diff --git a/src/AniMove.java b/src/AniMove.java index 75badff..f29596e 100644 --- a/src/AniMove.java +++ b/src/AniMove.java @@ -11,12 +11,9 @@ public class AniMove extends Animation { 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); + player.pos.set(point); } else { - player.real_x = from_x; - player.real_y = from_y; + player.pos.set(from_x, from_y); animating = false; } return animating; diff --git a/src/AniShrink.java b/src/AniShrink.java index f53d2f4..a860e67 100644 --- a/src/AniShrink.java +++ b/src/AniShrink.java @@ -8,7 +8,7 @@ public class AniShrink extends Animation { if (frame_count < numPoints) { animating = true; player.textsize = shrink(from_size, to_size); - System.out.println(player.real_x); + System.out.println(player.pos.x); } else { player.textsize = to_size; animating = false; diff --git a/src/AuraFight.java b/src/AuraFight.java index 6d3888a..493dd25 100644 --- a/src/AuraFight.java +++ b/src/AuraFight.java @@ -22,12 +22,11 @@ public class AuraFight extends Bubble{ void drawPlayer() { if (!pos_set) { - player.real_x = player_x; - player.real_y = player_y; + player.pos.set(player_x, player_y); pos_set = true; } player.textsize = 150; - player.draw(0, 0); + player.draw(); window.ui.healthBar(player_x, player_y-100, player.health, player.maxHealth); } diff --git a/src/Cell.java b/src/Cell.java index 63e9098..cbaa140 100644 --- a/src/Cell.java +++ b/src/Cell.java @@ -3,13 +3,13 @@ */ public class Cell { float width; - float x, y; + int x, y; Character character; - Cell(float x, float y, float width, Character character) { - this.width = width; + Cell(int x, int y, float width, Character character) { this.x = x; this.y = y; + this.width = width; this.character = character; } public boolean hasChar() { @@ -21,7 +21,8 @@ public class Cell { public void draw() { if (this.hasChar()) { - character.draw(x, y); + character.pos.set_on_grid(x, y); + character.draw(); } } } diff --git a/src/Character.java b/src/Character.java index c7f432b..09b57d2 100644 --- a/src/Character.java +++ b/src/Character.java @@ -8,8 +8,7 @@ public class Character implements Drawable { String type; int color; boolean collidable; - float x, y; - float real_x, real_y; + Position pos; int experience = 0; int level = 1; float damage_mult = (float) (1 + level * 0.4); @@ -20,6 +19,7 @@ public class Character implements Drawable { this.type = type; this.collidable = true; this.color = 0; + this.pos = new Position(window); } Character (Fenster window, String type, int color) { @@ -34,6 +34,7 @@ public class Character implements Drawable { this.type = type; this.color = color; this.collidable = collidable; + this.pos = new Position(window); } Character (Character another) { @@ -41,19 +42,20 @@ public class Character implements Drawable { this.type = another.type; this.collidable = another.collidable; this.color = another.color; + this.pos = new Position(window); } public Character(Fenster window) { this.window = window; + this.pos = new Position(window); } - public void draw(float x, float y) { + public void draw() { if (window.inGame) { - this.real_x = x * window.tilewidth / 2; - this.real_y = y * window.tilewidth / 2; + pos.sync_grid(); } window.fill(color); window.textSize(textsize); - window.text(type, real_x, real_y); + window.text(type, pos.get().x, pos.get().y); } } diff --git a/src/Drawable.java b/src/Drawable.java index 5792a21..86cceb9 100644 --- a/src/Drawable.java +++ b/src/Drawable.java @@ -1,3 +1,3 @@ public interface Drawable { - public void draw(float x, float y); + public void draw(); } diff --git a/src/Enemy.java b/src/Enemy.java index e8ba890..b240d0c 100644 --- a/src/Enemy.java +++ b/src/Enemy.java @@ -31,13 +31,11 @@ public class Enemy extends Fightable implements Health, Interactable { } } - public void draw(float x, float y) { - this.x = x; - this.y = y; + public void draw() { window.fill(color); - window.text(type, x * window.tilewidth/2, y * window.tilewidth/2); + window.text(type, pos.get().x, pos.get().y); if (window.inFight) { - window.ui.healthBar(x * window.tilewidth/2, y * window.tilewidth/2 - 15, health, maxHealth); + window.ui.healthBar(pos.get().x, pos.get().y - 15, health, maxHealth); } } diff --git a/src/Fenster.java b/src/Fenster.java index d7b63b8..4e857ba 100644 --- a/src/Fenster.java +++ b/src/Fenster.java @@ -21,10 +21,13 @@ public class Fenster extends PApplet { boolean inMenu = false; boolean inDialog = false; boolean starting = true; + boolean gametitel = 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?")); + int gametitel_gamma = 255; + boolean gametitel_fade = false; UI ui = new UI(this); @Override @@ -58,14 +61,13 @@ public class Fenster extends PApplet { public void draw() { background(255); + if (starting) { if (startingDialog.opened) { startingDialog.draw(200, 200, 40); - System.out.println(startingDialog.opened); - player.real_x = 400; - player.real_y = 400; + player.pos.set(400, 400); player.textsize = 200; - player.draw(0, 0); + player.draw(); } else { if (!startingAnimation.animate(200, 20)) { starting = false; @@ -73,22 +75,44 @@ public class Fenster extends PApplet { } else { tiles.draw(); System.out.println("startscreen"); - player.draw(0, 0); + player.draw(); } } } + if (gametitel) { + System.out.println(gametitel_gamma); + fill(255, gametitel_gamma); + rect(0, 0, 800, 800); + textSize(15); + fill(0, gametitel_gamma); + text(" ('-. _ .-') ('-. (`\\ .-') /` _ .-') _ .-') _ \n" + + " ( OO ).-. ( \\( -O ) ( OO ).-. `.( OO ),' ( \\( -O ) ( ( OO) ) \n" + + " / . --. / ,--. ,--. ,------. / . --. /,--./ .--. .-'),-----. ,------. ,--. \\ .'_ \n" + + " | \\-. \\ | | | | | /`. ' | \\-. \\ | | | ( OO' .-. '| /`. ' | |.-') ,`'--..._) \n" + + ".-'-' | | | | | .-') | / | |.-'-' | || | | |, / | | | || / | | | | OO )| | \\ ' \n" + + " \\| |_.' | | |_|( OO )| |_.' | \\| |_.' || |.'.| |_)\\_) | |\\| || |_.' | | |`-' || | ' | \n" + + " | .-. | | | | `-' /| . '.' | .-. || | \\ | | | || . '.'(| '---.'| | / : \n" + + " | | | |(' '-'(_.-' | |\\ \\ | | | || ,'. | `' '-' '| |\\ \\ | | | '--' / \n" + + " `--' `--' `-----' `--' '--' `--' `--''--' '--' `-----' `--' '--' `------' `-------'", 400, 200); + if (gametitel_fade) { + gametitel_gamma = gametitel_gamma - 5; + } + if (gametitel_gamma < 1) { + gametitel = false; + } + } if (inGame) { player.textsize = 20; 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 (tiles.get(player.pos.grid_x, player.pos.grid_y) != player) { + old_player_cell = tiles.get(player.pos.grid_x, player.pos.grid_y); + old_player_x = player.pos.grid_x; + old_player_y = player.pos.grid_y; } - tiles.set(player.x, player.y, player); + tiles.set(player.pos.grid_x, player.pos.grid_y, player); ui.draw(); @@ -102,16 +126,21 @@ public class Fenster extends PApplet { } public void keyPressed(processing.event.KeyEvent event) { - if (starting) { + if (gametitel) { + if (keyCode == 32) { + gametitel_fade = true; + } + } + if (starting && !gametitel) { if (keyCode == 32) { startingDialog.toggle(); } } if (inGame) { if (keyCode == this.UP) { - Cell newTile = tiles.get_cell(player.x, player.y - 1); + Cell newTile = tiles.get_cell(player.pos.grid_x, player.pos.grid_y - 1); if (!newTile.character.collidable) { - player.y = player.y - 1; + player.pos.grid_y_change(-1); tiles.set(old_player_x, old_player_y, old_player_cell); } else if (newTile.character instanceof Interactable) { if (newTile.character instanceof Enemy) { @@ -122,27 +151,27 @@ public class Fenster extends PApplet { } } if (keyCode == this.LEFT) { - Cell newTile = tiles.get_cell(player.x - 1, player.y); + Cell newTile = tiles.get_cell(player.pos.grid_x - 1, player.pos.grid_y); if (!newTile.character.collidable) { - player.x = player.x - 1; + player.pos.grid_x_change(-1); tiles.set(old_player_x, old_player_y, old_player_cell); } else if (newTile.character instanceof Interactable) { ((Interactable) newTile.character).interact(); } } if (keyCode == this.DOWN) { - Cell newTile = tiles.get_cell(player.x, player.y + 1); + Cell newTile = tiles.get_cell(player.pos.grid_x, player.pos.grid_y + 1); if (!newTile.character.collidable) { - player.y = player.y + 1; + player.pos.grid_y_change(1); tiles.set(old_player_x, old_player_y, old_player_cell); } else if (newTile.character instanceof Interactable) { ((Interactable) newTile.character).interact(); } } if (keyCode == this.RIGHT) { - Cell newTile = tiles.get_cell(player.x + 1, player.y); + Cell newTile = tiles.get_cell(player.pos.grid_x + 1, player.pos.grid_y); if (!newTile.character.collidable) { - player.x = player.x + 1; + player.pos.grid_x_change(1); tiles.set(old_player_x, old_player_y, old_player_cell); } else if (newTile.character instanceof Interactable) { ((Interactable) newTile.character).interact(); diff --git a/src/Fight.java b/src/Fight.java index 87d6174..f784271 100644 --- a/src/Fight.java +++ b/src/Fight.java @@ -26,12 +26,11 @@ public class Fight extends Bubble { void drawPlayer() { if (!pos_set) { - player.real_x = player_x; - player.real_y = player_y; + player.pos.set(player_x, player_y); pos_set = true; } player.textsize = 150; - player.draw(0, 0); + player.draw(); window.ui.healthBar(player_x, player_y-100, player.health, player.maxHealth); } diff --git a/src/Player.java b/src/Player.java index 57410fb..431a83f 100644 --- a/src/Player.java +++ b/src/Player.java @@ -7,7 +7,6 @@ import java.util.List; * This is the main player of the game we can move around with and interact. */ public class Player extends Fightable implements Health { - int x, y; int health; int maxHealth = 20; @@ -17,8 +16,7 @@ public class Player extends Fightable implements Health { Player(Fenster window) { super(window); this.type = "@"; - this.x = 20; - this.y = 20; + pos.set_on_grid(20, 20); this.health = maxHealth; this.skills.add(new Tritt(window, (Fightable) window.player)); diff --git a/src/Position.java b/src/Position.java new file mode 100644 index 0000000..5991acb --- /dev/null +++ b/src/Position.java @@ -0,0 +1,55 @@ +import processing.core.PVector; + +public class Position { + Fenster window; + float x, y; + int grid_x, grid_y; + + Position(Fenster window) { + this.window = window; + } + + public PVector get() { + return new PVector(x, y); + } + public PVector get_grid() { + return new PVector(grid_x, grid_y); + } + + public void set(float x, float y) { + this.x = x; + this.y = y; + } + + public void set(PVector point) { + this.x = point.x; + this.y = point.y; + } + + public void set_on_grid(int x, int y) { + this.grid_x = x; + this.grid_y = y; + sync_grid(); + } + + public void set_grid_x(int x) { + set_on_grid(x, grid_y); + } + + public void set_grid_y(int y) { + set_on_grid(grid_x, y); + } + + public void grid_x_change(int x) { + set_grid_x(grid_x + x); + } + + public void grid_y_change(int y) { + set_grid_y(grid_y + y); + } + + public void sync_grid() { + x = grid_x * window.tilewidth / 2; + y = grid_y * window.tilewidth / 2; + } +} diff --git a/src/Talkable.java b/src/Talkable.java index 820465d..30c2995 100644 --- a/src/Talkable.java +++ b/src/Talkable.java @@ -23,13 +23,14 @@ public class Talkable extends Character implements Interactable{ this.bubble.toggle(); } - public void draw(float x, float y) { + public void draw() { window.fill(color); - window.text(type, x * window.tilewidth/2, y * window.tilewidth/2); - this.bubble.draw(x, y, 20); + window.text(type, this.pos.get().x, this.pos.get().y); + this.bubble.draw(this.pos.get_grid().x, this.pos.get_grid().y, 20); - if (Math.abs(window.player.x - x) > 1 || Math.abs(window.player.y - y) > 1) { + System.out.println(window.player.pos.get_grid().x - this.pos.get_grid().x); + if (Math.abs(window.player.pos.get_grid().x - this.pos.get_grid().x) > 1 || Math.abs(window.player.pos.get_grid().y - this.pos.get_grid().y) > 1) { this.bubble.close(); } }