diff options
author | mafaldo <mafaldo@heavyhammer.home> | 2018-02-10 15:12:05 +0100 |
---|---|---|
committer | mafaldo <mafaldo@heavyhammer.home> | 2018-02-10 15:12:05 +0100 |
commit | 0e8ebd8803718b37e9141649c6d8eb7036ec85ed (patch) | |
tree | 5b952c80b9d0616cf0bc7ba4243561352482e957 /src/main/java/Actor.java | |
parent | Switch to gradle, update gitignore (diff) | |
download | Subconscious-old-0e8ebd8803718b37e9141649c6d8eb7036ec85ed.tar.gz Subconscious-old-0e8ebd8803718b37e9141649c6d8eb7036ec85ed.zip |
Implement actor, create player
Diffstat (limited to 'src/main/java/Actor.java')
-rw-r--r-- | src/main/java/Actor.java | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/main/java/Actor.java b/src/main/java/Actor.java index 207d6e6..3d81d7c 100644 --- a/src/main/java/Actor.java +++ b/src/main/java/Actor.java @@ -1,3 +1,61 @@ +import java.awt.Dimension; +import java.awt.Point; + public class Actor { + public enum Type { + PLAYER, ENEMY + } + + + public final String name; + public final Type type; + protected final int MAXHP; + protected int hp; + protected int x, y; + protected Dimension gridSize; + + public Actor(String name, int MAXHP, Type type) { + this.name = name; + this.type = type; + this.MAXHP = MAXHP; + this.hp = this.MAXHP; + } + + public void damage(int dmg) { + this.hp = this.hp - dmg; + if (this.hp < 0) { + this.hp = 0; + } + } + + public void heal(int life) { + this.hp = this.hp + life; + if (this.hp > this.MAXHP) { + this.hp = this.MAXHP; + } + } + + public boolean move(int x, int y) { + if (x < this.gridSize.width && y < this.gridSize.height && x > 0 && y > 0) { + this.x = x; + this.y = y; + return true; + } else { + return false; + } + } + + public int getHp() { + return this.hp; + } + + public int getX() { + return this.x; + } + + public int getY() { + return this.y; + } + } |