diff --git a/src/AniMove.java b/src/AniMove.java new file mode 100644 index 0000000..75badff --- /dev/null +++ b/src/AniMove.java @@ -0,0 +1,38 @@ +import processing.core.PVector; + +public class AniMove extends Animation { + public AniMove(Fenster window, Character player) { + super(window, player); + this.window = window; + this.player = player; + } + + public boolean animate(float from_x, float from_y, float to_x, float to_y) { + if (frame_count < numPoints) { + animating = true; + PVector point = move(from_x,from_y, to_x, to_y); + player.real_x = point.x; + player.real_y = point.y; + System.out.println(player.real_x); + } else { + player.real_x = from_x; + player.real_y = from_y; + animating = false; + } + return animating; + } + + public PVector move(float from_x, float from_y, float to_x, float to_y) { + PVector point = new PVector(from_x, from_y); + + float interpolationAmount = window.map(frame_count, 0, numPoints - 1, 0, 1); + + float interpolatedX = window.lerp(from_x, to_x, interpolationAmount); + float interpolatedY = window.lerp(from_y, to_y, interpolationAmount); + + point = new PVector(interpolatedX, interpolatedY); + frame_count++; + + return point; + } +} diff --git a/src/AniShrink.java b/src/AniShrink.java new file mode 100644 index 0000000..f53d2f4 --- /dev/null +++ b/src/AniShrink.java @@ -0,0 +1,26 @@ +public class AniShrink extends Animation { + int numPoints = 100; + public AniShrink(Fenster window, Character player) { + super(window, player); + } + + public boolean animate(int from_size, int to_size){ + if (frame_count < numPoints) { + animating = true; + player.textsize = shrink(from_size, to_size); + System.out.println(player.real_x); + } else { + player.textsize = to_size; + animating = false; + } + return animating; + } + + private int shrink(int from_size, int to_size){ + float interpolationAmount = window.map(frame_count, 0, numPoints - 1, 0, 1); + + int interpolated = (int) window.lerp(from_size, to_size, interpolationAmount); + frame_count++; + return interpolated; + } +} diff --git a/src/Bubble.java b/src/Bubble.java index b9cd306..be473e5 100644 --- a/src/Bubble.java +++ b/src/Bubble.java @@ -6,11 +6,12 @@ import java.util.List; /** * The speech bubble that can be shown by all Talkable characters */ -public class Bubble implements Drawable { +public class Bubble { Fenster window; List text; boolean opened; int index = 0; + float real_x, real_y; Bubble(Fenster window, List text) { this.window = window; @@ -45,12 +46,21 @@ public class Bubble implements Drawable { this.text = text; } - public void draw(float x, float y) { + public void draw(float x, float y, int textsize) { + if (window.inGame) { + this.real_x = x * window.tilewidth / 2; + this.real_y = y * window.tilewidth / 2; + } else { + this.real_x = x; + this.real_y = y; + } if (opened) { window.fill(255); window.rect(x * window.tilewidth/2, y * window.tilewidth/2, 300, 50); window.fill(0); - window.text(text.get(index), x * window.tilewidth/2, y * window.tilewidth/2, 300, 50); + window.textSize(textsize); + window.textAlign(window.CENTER); + window.text(text.get(index), real_x, real_y, window.textWidth(text.get(index)), 50); } } } diff --git a/src/Character.java b/src/Character.java index 93b0438..7ace486 100644 --- a/src/Character.java +++ b/src/Character.java @@ -10,6 +10,7 @@ public class Character implements Drawable { boolean collidable; float x, y; float real_x, real_y; + int textsize = 20; Character (Fenster window, String type) { this.window = window; @@ -44,10 +45,12 @@ public class Character implements Drawable { } public void draw(float x, float y) { - this.real_x = x * window.tilewidth/2; - this.real_y = y * window.tilewidth/2; + if (window.inGame) { + this.real_x = x * window.tilewidth / 2; + this.real_y = y * window.tilewidth / 2; + } window.fill(color); - window.textSize(20); + window.textSize(textsize); window.text(type, real_x, real_y); } } diff --git a/src/Fenster.java b/src/Fenster.java index 8102ad6..d7b63b8 100644 --- a/src/Fenster.java +++ b/src/Fenster.java @@ -3,6 +3,7 @@ import processing.core.PFont; import java.awt.event.KeyEvent; import java.util.ArrayList; +import java.util.Arrays; public class Fenster extends PApplet { @@ -16,11 +17,14 @@ public class Fenster extends PApplet { // STATES boolean inFight = false; - boolean inGame = true; + boolean inGame = false; boolean inMenu = false; boolean inDialog = false; + boolean starting = true; Fight myfight; + AniShrink startingAnimation = new AniShrink(this, player); + Bubble startingDialog = new Bubble(this, Arrays.asList("Das bist du...", "In einer gefährlichen Welt", "Wirst du überleben?")); UI ui = new UI(this); @Override @@ -30,7 +34,7 @@ public class Fenster extends PApplet { tiles.settings(); - myfight = new Fight(this, player, (Enemy) tiles.get(10, 10)); + //this.text("lol", 0, 0); @@ -44,33 +48,65 @@ public class Fenster extends PApplet { this.textSize(20); this.textAlign(CENTER, CENTER); + myfight = new Fight(this, player, (Enemy) tiles.get(10, 10)); + // start the first dialog + startingDialog.open(); } @Override public void draw() { background(255); - tiles.draw(); - // Handle the Cell which the player was on last round - if (tiles.get(player.x, player.y) != player) { - old_player_cell = tiles.get(player.x, player.y); - old_player_x = player.x; - old_player_y = player.y; + if (starting) { + if (startingDialog.opened) { + startingDialog.draw(200, 200, 40); + System.out.println(startingDialog.opened); + player.real_x = 400; + player.real_y = 400; + player.textsize = 200; + player.draw(0, 0); + } else { + if (!startingAnimation.animate(200, 20)) { + starting = false; + inGame = true; + } else { + tiles.draw(); + System.out.println("startscreen"); + player.draw(0, 0); + } + } } + if (inGame) { + player.textsize = 20; - tiles.set(player.x, player.y, player); + tiles.draw(); + // Handle the Cell which the player was on last round + if (tiles.get(player.x, player.y) != player) { + old_player_cell = tiles.get(player.x, player.y); + old_player_x = player.x; + old_player_y = player.y; + } + + tiles.set(player.x, player.y, player); - ui.draw(); - + ui.draw(); + } if (inFight) { + tiles.draw(); myfight.draw(); } + //println(player.x + " " + player.y); } public void keyPressed(processing.event.KeyEvent event) { + if (starting) { + if (keyCode == 32) { + startingDialog.toggle(); + } + } if (inGame) { if (keyCode == this.UP) { Cell newTile = tiles.get_cell(player.x, player.y - 1); diff --git a/src/Fight.java b/src/Fight.java index 8bce916..76b0bf5 100644 --- a/src/Fight.java +++ b/src/Fight.java @@ -1,3 +1,5 @@ +import processing.core.PApplet; + import java.util.List; public class Fight extends Bubble { @@ -10,20 +12,26 @@ public class Fight extends Bubble { float enemy_x = 600; float enemy_y = 300; + boolean pos_set = false; + Skill running_move; Fight(Fenster window, Player player, Enemy enemy) { super(window); - + System.out.println(player); 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); + if (!pos_set) { + player.real_x = player_x; + player.real_y = player_y; + pos_set = true; + } + player.textsize = 150; + player.draw(0, 0); window.ui.healthBar(player_x, player_y-60, player.health, player.maxHealth); } @@ -37,8 +45,9 @@ public class Fight extends Bubble { } public void attack() { - running_move = player.skills.get(0); - player.skills.get(0).use(enemy); + + running_move = player.skill; + running_move.use(enemy); } @@ -54,6 +63,7 @@ public class Fight extends Bubble { window.fill(0); } if (running_move != null) { + //System.out.println("move is running"); running_move.draw(); } if (enemy.health <= 0) { diff --git a/src/Player.java b/src/Player.java index c2236fc..2b9e63f 100644 --- a/src/Player.java +++ b/src/Player.java @@ -11,15 +11,16 @@ public class Player extends Fightable implements Health { int health; int maxHealth = 20; List skills = new ArrayList(); + Skill skill = new Tritt(window, this); Player(Fenster window) { super(window); this.type = "@"; - this.x = 4; - this.y = 4; + this.x = 20; + this.y = 20; this.health = maxHealth; - this.skills.add(new Tritt(window, this)); + this.skills.add(new Tritt(window, (Fightable) window.player)); } public void damage(int damage) { diff --git a/src/Save.java b/src/Save.java new file mode 100644 index 0000000..051327d --- /dev/null +++ b/src/Save.java @@ -0,0 +1,25 @@ +import java.io.*; + +public class Save { + + private static Save INSTANCE; + private String file = "./save"; + + private Save() {} + + public static Save getInstance() { + if(INSTANCE == null) { + INSTANCE = new Save(); + } + return INSTANCE; + } + + public void save() { + try (Writer writer = new BufferedWriter(new OutputStreamWriter( + new FileOutputStream(file), "utf-8"))) { + writer.write("something"); + } catch (IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/Skill.java b/src/Skill.java index c227ba0..7981d0d 100644 --- a/src/Skill.java +++ b/src/Skill.java @@ -1,7 +1,7 @@ public class Skill { Fenster window; - Fightable user; - Fightable target; + Character user; + Character target; static int power = 5; int numPoints = 10; diff --git a/src/Talkable.java b/src/Talkable.java index f9080d8..820465d 100644 --- a/src/Talkable.java +++ b/src/Talkable.java @@ -27,7 +27,7 @@ public class Talkable extends Character implements Interactable{ window.fill(color); window.text(type, x * window.tilewidth/2, y * window.tilewidth/2); - this.bubble.draw(x, y); + this.bubble.draw(x, y, 20); if (Math.abs(window.player.x - x) > 1 || Math.abs(window.player.y - y) > 1) { this.bubble.close(); diff --git a/src/Tritt.java b/src/Tritt.java index 8169cec..b870155 100644 --- a/src/Tritt.java +++ b/src/Tritt.java @@ -1,69 +1,33 @@ public class Tritt extends Skill { - Fenster window; - Fightable user; - Fightable target; + boolean animating = false; + Animation animation; Tritt(Fenster window, Fightable user) { super(window, user); System.out.println(user); } public void use(Fightable target){ + System.out.println("using tritt"); target.damage(power); this.target = target; + animate(); }; public void animate(){ + animating = true; + // it should be user, but that doesnt work, so pick the player from window + animation = new AniMove(window, window.player); }; - 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(); + System.out.println("before drawing"); + if (animating) { + System.out.println("animating tritt"); + if (!animation.animate(200, 500, 600, 300)) { + animating = false; + } + } return true; } }