Fight window
This commit is contained in:
parent
d3283cd0f6
commit
5a51e43a4f
@ -6,7 +6,7 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* The speech bubble that can be shown by all Talkable characters
|
* The speech bubble that can be shown by all Talkable characters
|
||||||
*/
|
*/
|
||||||
public class Bubble {
|
public class Bubble implements Drawable {
|
||||||
Fenster window;
|
Fenster window;
|
||||||
List<String> text;
|
List<String> text;
|
||||||
boolean opened;
|
boolean opened;
|
||||||
@ -17,6 +17,11 @@ public class Bubble {
|
|||||||
this.text = text;
|
this.text = text;
|
||||||
this.opened = false;
|
this.opened = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Bubble(Fenster window) {
|
||||||
|
this.window = window;
|
||||||
|
}
|
||||||
|
|
||||||
public void open() {
|
public void open() {
|
||||||
this.opened = true;
|
this.opened = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,7 +3,7 @@ import processing.core.PApplet;
|
|||||||
/**
|
/**
|
||||||
* Class from which we define all other Entities which are seen in the game.
|
* Class from which we define all other Entities which are seen in the game.
|
||||||
*/
|
*/
|
||||||
public class Character {
|
public class Character implements Drawable {
|
||||||
Fenster window;
|
Fenster window;
|
||||||
String type;
|
String type;
|
||||||
int color;
|
int color;
|
||||||
@ -46,6 +46,7 @@ public class Character {
|
|||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
window.fill(color);
|
window.fill(color);
|
||||||
|
window.textSize(20);
|
||||||
window.text(type, x * window.tilewidth/2, y * window.tilewidth/2);
|
window.text(type, x * window.tilewidth/2, y * window.tilewidth/2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
3
src/Drawable.java
Normal file
3
src/Drawable.java
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
public interface Drawable {
|
||||||
|
public void draw(float x, float y);
|
||||||
|
}
|
||||||
@ -18,6 +18,7 @@ public class Enemy extends Character implements Health, Interactable {
|
|||||||
public void damage(int damage) {
|
public void damage(int damage) {
|
||||||
health = health - damage;
|
health = health - damage;
|
||||||
if (health <= 0) {
|
if (health <= 0) {
|
||||||
|
health = 0;
|
||||||
window.println("dead");
|
window.println("dead");
|
||||||
this.color = window.color(100);
|
this.color = window.color(100);
|
||||||
}
|
}
|
||||||
@ -30,7 +31,19 @@ public class Enemy extends Character implements Health, Interactable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void draw(float x, float y) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
window.fill(color);
|
||||||
|
window.text(type, x * window.tilewidth/2, y * window.tilewidth/2);
|
||||||
|
if (window.inFight) {
|
||||||
|
window.ui.healthBar(x * window.tilewidth/2, y * window.tilewidth/2 - 15, health, maxHealth);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void interact() {
|
public void interact() {
|
||||||
|
window.inGame = false;
|
||||||
|
window.inFight = true;
|
||||||
window.player.damageEnemy(5, this);
|
window.player.damageEnemy(5, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,8 @@ public class Fenster extends PApplet {
|
|||||||
boolean inMenu = false;
|
boolean inMenu = false;
|
||||||
boolean inDialog = false;
|
boolean inDialog = false;
|
||||||
|
|
||||||
|
Fight myfight;
|
||||||
|
|
||||||
UI ui = new UI(this);
|
UI ui = new UI(this);
|
||||||
@Override
|
@Override
|
||||||
public void settings() {
|
public void settings() {
|
||||||
@ -28,7 +30,7 @@ public class Fenster extends PApplet {
|
|||||||
|
|
||||||
tiles.settings();
|
tiles.settings();
|
||||||
|
|
||||||
|
myfight = new Fight(this, player, (Enemy) tiles.get(10, 10));
|
||||||
|
|
||||||
|
|
||||||
//this.text("lol", 0, 0);
|
//this.text("lol", 0, 0);
|
||||||
@ -41,6 +43,8 @@ public class Fenster extends PApplet {
|
|||||||
this.textFont(font);
|
this.textFont(font);
|
||||||
this.textSize(20);
|
this.textSize(20);
|
||||||
this.textAlign(CENTER, CENTER);
|
this.textAlign(CENTER, CENTER);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -59,6 +63,10 @@ public class Fenster extends PApplet {
|
|||||||
|
|
||||||
|
|
||||||
ui.draw();
|
ui.draw();
|
||||||
|
|
||||||
|
if (inFight) {
|
||||||
|
myfight.draw();
|
||||||
|
}
|
||||||
//println(player.x + " " + player.y);
|
//println(player.x + " " + player.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +78,11 @@ public class Fenster extends PApplet {
|
|||||||
player.y = player.y - 1;
|
player.y = player.y - 1;
|
||||||
tiles.set(old_player_x, old_player_y, old_player_cell);
|
tiles.set(old_player_x, old_player_y, old_player_cell);
|
||||||
} else if (newTile.character instanceof Interactable) {
|
} else if (newTile.character instanceof Interactable) {
|
||||||
((Interactable) newTile.character).interact();
|
if (newTile.character instanceof Enemy) {
|
||||||
|
myfight = new Fight(this, player, (Enemy) newTile.character);
|
||||||
|
} else {
|
||||||
|
((Interactable) newTile.character).interact();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (keyCode == this.LEFT) {
|
if (keyCode == this.LEFT) {
|
||||||
@ -100,7 +112,18 @@ public class Fenster extends PApplet {
|
|||||||
((Interactable) newTile.character).interact();
|
((Interactable) newTile.character).interact();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (inFight) {
|
||||||
|
if (keyCode == 32) {
|
||||||
|
myfight.attack();
|
||||||
|
}
|
||||||
|
if (keyCode == this.ESC) {
|
||||||
|
if (key == ESC) {
|
||||||
|
key = 0;
|
||||||
|
}
|
||||||
|
inFight = false;
|
||||||
|
inGame = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
102
src/Fight.java
102
src/Fight.java
@ -1,10 +1,106 @@
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Fight extends Bubble {
|
public class Fight extends Bubble {
|
||||||
|
Player player;
|
||||||
|
Enemy enemy;
|
||||||
|
|
||||||
Fight(Fenster window, List<String> text) {
|
float player_x = 200;
|
||||||
super(window, text);
|
float player_y = 500;
|
||||||
|
|
||||||
this.opened = false;
|
float enemy_x = 600;
|
||||||
|
float enemy_y = 300;
|
||||||
|
|
||||||
|
boolean animating = false;
|
||||||
|
|
||||||
|
Fight(Fenster window, Player player, Enemy enemy) {
|
||||||
|
super(window);
|
||||||
|
|
||||||
|
this.player = player;
|
||||||
|
this.enemy = enemy;
|
||||||
|
this.opened = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawPlayer() {
|
||||||
|
window.textSize(150);
|
||||||
|
window.fill(0);
|
||||||
|
window.text(player.type, player_x, player_y);
|
||||||
|
|
||||||
|
window.ui.healthBar(player_x, player_y-60, player.health, player.maxHealth);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawEnemy() {
|
||||||
|
window.textSize(150);
|
||||||
|
window.fill(enemy.color);
|
||||||
|
window.text(enemy.type, enemy_x, enemy_y);
|
||||||
|
|
||||||
|
window.ui.healthBar(enemy_x, enemy_y-60, enemy.health, enemy.maxHealth);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void attack() {
|
||||||
|
animating = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
boolean ani_hit = false;
|
||||||
|
void animating_attack() {
|
||||||
|
int numPoints = 10;
|
||||||
|
float startanimate_x;
|
||||||
|
float startanimate_y;
|
||||||
|
float stopanimate_x;
|
||||||
|
float stopanimate_y;
|
||||||
|
if (i == 5 && ani_hit == false) {
|
||||||
|
ani_hit = true;
|
||||||
|
}
|
||||||
|
if (!ani_hit) {
|
||||||
|
startanimate_x = 600;
|
||||||
|
startanimate_y = 300;
|
||||||
|
stopanimate_x = 200;
|
||||||
|
stopanimate_y = 500;
|
||||||
|
} else {
|
||||||
|
startanimate_x = 200;
|
||||||
|
startanimate_y = 500;
|
||||||
|
stopanimate_x = 600;
|
||||||
|
stopanimate_y = 300;
|
||||||
|
}
|
||||||
|
if (i < 10) {
|
||||||
|
float interpolationAmount = window.map(i, 0, numPoints - 1, 0, 1);
|
||||||
|
|
||||||
|
float interpolatedX = window.lerp(startanimate_x, stopanimate_x, interpolationAmount);
|
||||||
|
float interpolatedY = window.lerp(startanimate_y, stopanimate_y, interpolationAmount);
|
||||||
|
|
||||||
|
player_x = interpolatedX;
|
||||||
|
player_y = interpolatedY;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
void animation_cleanup() {
|
||||||
|
if (!ani_hit && player_x == 600 && player_y == 300) {
|
||||||
|
animating = false;
|
||||||
|
i = 0;
|
||||||
|
ani_hit = false;
|
||||||
|
|
||||||
|
player_x = 600;
|
||||||
|
player_y = 300;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw() {
|
||||||
|
|
||||||
|
if (opened) {
|
||||||
|
window.fill(255);
|
||||||
|
window.rectMode(window.CENTER);
|
||||||
|
window.rect(window.width/2, window.height/2, 700, 500);
|
||||||
|
drawPlayer();
|
||||||
|
drawEnemy();
|
||||||
|
window.fill(0);
|
||||||
|
}
|
||||||
|
if (animating) {
|
||||||
|
animating_attack();
|
||||||
|
}
|
||||||
|
if (enemy.health <= 0) {
|
||||||
|
window.inFight = false;
|
||||||
|
window.inGame = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/UI.java
13
src/UI.java
@ -1,4 +1,5 @@
|
|||||||
import processing.core.PApplet;
|
import processing.core.PApplet;
|
||||||
|
import processing.core.PShape;
|
||||||
|
|
||||||
public class UI {
|
public class UI {
|
||||||
PApplet window;
|
PApplet window;
|
||||||
@ -12,12 +13,18 @@ public class UI {
|
|||||||
window.rect(x, 775, 300, 50);
|
window.rect(x, 775, 300, 50);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void healthBar() {
|
public void healthBar(float x, float y, int health, int maxHealth) {
|
||||||
window.text("❤", 20, 20);
|
float barlength = 100;
|
||||||
|
float healthLength = barlength / maxHealth * health;
|
||||||
|
window.rectMode(window.CORNER);
|
||||||
|
window.fill(0);
|
||||||
|
window.rect(x -barlength/2, y, barlength, 5);
|
||||||
|
window.fill(window.color(255, 0, 0));
|
||||||
|
window.rect(x - barlength/2, y, healthLength, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void draw() {
|
public void draw() {
|
||||||
bottomBar(400, 700);
|
bottomBar(400, 700);
|
||||||
healthBar();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user