diff options
Diffstat (limited to 'src/main/java')
-rw-r--r-- | src/main/java/Actor.java | 20 | ||||
-rw-r--r-- | src/main/java/Enemy.java | 0 | ||||
-rw-r--r-- | src/main/java/Player.java | 8 | ||||
-rw-r--r-- | src/main/java/Tile.java | 13 | ||||
-rw-r--r-- | src/main/java/WorldScene.java | 31 |
5 files changed, 51 insertions, 21 deletions
diff --git a/src/main/java/Actor.java b/src/main/java/Actor.java index 9f6f5e6..1e0ba80 100644 --- a/src/main/java/Actor.java +++ b/src/main/java/Actor.java @@ -1,5 +1,4 @@ import java.awt.Dimension; -import java.awt.Point; public class Actor { @@ -10,21 +9,24 @@ public class Actor { public final String name; public final Type type; - protected final int MAXHP; - protected int hp; - protected int x, y; - protected Dimension gridSize; + private boolean alive; + private final int MAXHP; + private int hp; + private int x, y; + private Dimension gridSize; - public Actor(String name, int MAXHP, Type type) { + public Actor(String name, int MAXHP, Type type, Dimension gridSize) { this.name = name; this.type = type; this.MAXHP = MAXHP; this.hp = this.MAXHP; + this.alive = true; } public void damage(int dmg) { this.hp = this.hp - dmg; - if (this.hp < 0) { + if (this.hp <= 0) { + this.alive = false; this.hp = 0; } } @@ -46,6 +48,10 @@ public class Actor { } } + public boolean isAlive() { + return alive; + } + public int getHp() { return this.hp; } diff --git a/src/main/java/Enemy.java b/src/main/java/Enemy.java deleted file mode 100644 index e69de29..0000000 --- a/src/main/java/Enemy.java +++ /dev/null diff --git a/src/main/java/Player.java b/src/main/java/Player.java deleted file mode 100644 index e64b765..0000000 --- a/src/main/java/Player.java +++ /dev/null @@ -1,8 +0,0 @@ -import java.awt.Dimension; - -public class Player extends Actor { - - public Player(String name, Dimension gridSize) { - super(name, 100, Actor.Type.PLAYER); - } -} diff --git a/src/main/java/Tile.java b/src/main/java/Tile.java index a5e0daa..4ced8c8 100644 --- a/src/main/java/Tile.java +++ b/src/main/java/Tile.java @@ -8,10 +8,23 @@ public class Tile { public final Type type; public boolean selected = false; + private Actor actor = null; public Tile(Type type, int x, int y) { this.type = type; this.x = x; this.y = y; } + + public void setActor(Actor actor) { + this.actor = actor; + } + + public Actor getActor() { + return actor; + } + + public void clearActor() { + this.actor = null; + } } diff --git a/src/main/java/WorldScene.java b/src/main/java/WorldScene.java index 829afbb..7d08077 100644 --- a/src/main/java/WorldScene.java +++ b/src/main/java/WorldScene.java @@ -21,7 +21,7 @@ public class WorldScene extends Scene { // TODO remove hardcoded stuff - Player player = new Player("pipo", gridSize); + Actor player = new Actor("pipo", 100, Actor.Type.PLAYER, gridSize); this.actors.add(player); } @@ -79,7 +79,11 @@ public class WorldScene extends Scene { for (Actor actor : this.actors) { switch (actor.type) { case PLAYER: - g2d.setColor(Palette.ORANGE); + if (actor.isAlive()) { + g2d.setColor(Palette.ORANGE); + } else { + g2d.setColor(Palette.BLUE); + } break; case ENEMY: g2d.setColor(Palette.RED); @@ -87,8 +91,8 @@ public class WorldScene extends Scene { } int gap = this.tileSize / 10; g2d.fillRect( - (this.tileSize * actor.x) + gap, - (this.tileSize * actor.y) + gap, + (this.tileSize * actor.getX()) + gap, + (this.tileSize * actor.getY()) + gap, this.tileSize - gap * 2, this.tileSize - gap * 2 ); } @@ -96,12 +100,27 @@ public class WorldScene extends Scene { @Override public void mouseClicked(int x, int y) { + this.updateTiles(); + Tile tile = map.getTile( (int) (x/(double)this.tileSize) + sceneXOffset, (int) (y/(double)this.tileSize) + sceneYOffset ); - // TODO find clicked actor - tile.selected = !tile.selected; + //TODO remove test stuff + if (tile.getActor() != null) { + Actor actor = tile.getActor(); + actor.damage(1000); + } + } + + public void updateTiles() { + for (Tile tile : this.map.grid) { + tile.clearActor(); + } + for (Actor actor : this.actors) { + Tile tile = map.getTile(actor.getX(), actor.getY()); + tile.setActor(actor); + } } } |