diff --git a/src/Character.java b/src/Character.java index b40a0ee..93b0438 100644 --- a/src/Character.java +++ b/src/Character.java @@ -9,6 +9,7 @@ public class Character implements Drawable { int color; boolean collidable; float x, y; + float real_x, real_y; Character (Fenster window, String type) { this.window = window; @@ -43,10 +44,10 @@ public class Character implements Drawable { } public void draw(float x, float y) { - this.x = x; - this.y = y; + this.real_x = x * window.tilewidth/2; + this.real_y = y * window.tilewidth/2; window.fill(color); window.textSize(20); - window.text(type, x * window.tilewidth/2, y * window.tilewidth/2); + window.text(type, real_x, real_y); } } diff --git a/src/Enemy.java b/src/Enemy.java index eec2dbd..e8ba890 100644 --- a/src/Enemy.java +++ b/src/Enemy.java @@ -3,7 +3,7 @@ import processing.core.PApplet; /** * Enemy which is Interactable in the way, that we can damage him. He also has health so he is also healable. */ -public class Enemy extends Character implements Health, Interactable { +public class Enemy extends Fightable implements Health, Interactable { int health; int maxHealth = 20; @@ -44,6 +44,5 @@ public class Enemy extends Character implements Health, Interactable { public void interact() { window.inGame = false; window.inFight = true; - window.player.damageEnemy(5, this); } } diff --git a/src/Fight.java b/src/Fight.java index 9f01a6e..8bce916 100644 --- a/src/Fight.java +++ b/src/Fight.java @@ -10,7 +10,7 @@ public class Fight extends Bubble { float enemy_x = 600; float enemy_y = 300; - boolean animating = false; + Skill running_move; Fight(Fenster window, Player player, Enemy enemy) { super(window); @@ -37,53 +37,11 @@ public class Fight extends Bubble { } public void attack() { - animating = true; + running_move = player.skills.get(0); + player.skills.get(0).use(enemy); } - 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() { @@ -95,8 +53,8 @@ public class Fight extends Bubble { drawEnemy(); window.fill(0); } - if (animating) { - animating_attack(); + if (running_move != null) { + running_move.draw(); } if (enemy.health <= 0) { window.inFight = false; diff --git a/src/Fightable.java b/src/Fightable.java new file mode 100644 index 0000000..fb6ea8e --- /dev/null +++ b/src/Fightable.java @@ -0,0 +1,11 @@ +public abstract class Fightable extends Character { + + public Fightable(Fenster window) { + super(window); + } + + public abstract void damage(int damage); + + public abstract void heal(int healing); + +} diff --git a/src/Player.java b/src/Player.java index fd0665a..c2236fc 100644 --- a/src/Player.java +++ b/src/Player.java @@ -1,12 +1,16 @@ import processing.core.PApplet; +import java.util.ArrayList; +import java.util.List; + /** * This is the main player of the game we can move around with and interact. */ -public class Player extends Character implements Health { +public class Player extends Fightable implements Health { int x, y; int health; int maxHealth = 20; + List skills = new ArrayList(); Player(Fenster window) { super(window); @@ -14,10 +18,8 @@ public class Player extends Character implements Health { this.x = 4; this.y = 4; this.health = maxHealth; - } - public void damageEnemy(int damage, Enemy enemy) { - enemy.damage(damage); + this.skills.add(new Tritt(window, this)); } public void damage(int damage) { diff --git a/src/Skill.java b/src/Skill.java new file mode 100644 index 0000000..c227ba0 --- /dev/null +++ b/src/Skill.java @@ -0,0 +1,22 @@ +public class Skill { + Fenster window; + Fightable user; + Fightable target; + static int power = 5; + int numPoints = 10; + + boolean animating = false; + + Skill(Fenster window, Fightable user) { + this.window = window; + this.user = user; + } + public void use(Fightable target){ + target.damage(power); + }; + public void animate() {}; + + public boolean draw() { + return true; + } +} diff --git a/src/Tritt.java b/src/Tritt.java new file mode 100644 index 0000000..8169cec --- /dev/null +++ b/src/Tritt.java @@ -0,0 +1,69 @@ +public class Tritt extends Skill { + Fenster window; + Fightable user; + Fightable target; + boolean animating = false; + + Tritt(Fenster window, Fightable user) { + super(window, user); + System.out.println(user); + } + public void use(Fightable target){ + target.damage(power); + this.target = target; + }; + public void animate(){ + }; + + int i = 0; + boolean ani_hit = false; + void animating_attack() { + float startanimate_x; + float startanimate_y; + float stopanimate_x; + float stopanimate_y; + if (i == 10 && ani_hit == false) { + ani_hit = true; + i = 0; + } + 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); + + user.real_x = interpolatedX; + user.real_y = interpolatedY; + i++; + } + + } + + void animation_cleanup() { + if (!ani_hit && user.real_x == 600 && user.real_y == 300) { + animating = false; + i = 0; + ani_hit = false; + + user.real_x = 600; + user.real_y = 300; + } + } + + public boolean draw() { + System.out.println(2); + animating_attack(); + return true; + } +}