From 7200c3e5e4d66581d193d4f88db93ab39ee45482 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Tue, 25 Feb 2020 10:54:40 +0100 Subject: [PATCH] Add tower sprites --- .../game/{SuperTower.java => AutoTower.java} | 9 +++++++-- .../fr/ynerant/leveleditor/game/BasicTower.java | 5 +++++ .../fr/ynerant/leveleditor/game/GameFrame.java | 4 ++-- .../fr/ynerant/leveleditor/game/NullTower.java | 5 +++++ .../java/fr/ynerant/leveleditor/game/Tower.java | 11 +++++++++++ .../leveleditor/textures/sprites/autotower.png | Bin 0 -> 696 bytes .../leveleditor/textures/sprites/nulltower.png | Bin 0 -> 697 bytes .../leveleditor/textures/sprites/simpletower.png | Bin 0 -> 697 bytes .../leveleditor/textures/sprites/sprites.json | 9 +++++++++ 9 files changed, 39 insertions(+), 4 deletions(-) rename src/main/java/fr/ynerant/leveleditor/game/{SuperTower.java => AutoTower.java} (72%) create mode 100644 src/main/resources/assets/leveleditor/textures/sprites/autotower.png create mode 100644 src/main/resources/assets/leveleditor/textures/sprites/nulltower.png create mode 100644 src/main/resources/assets/leveleditor/textures/sprites/simpletower.png diff --git a/src/main/java/fr/ynerant/leveleditor/game/SuperTower.java b/src/main/java/fr/ynerant/leveleditor/game/AutoTower.java similarity index 72% rename from src/main/java/fr/ynerant/leveleditor/game/SuperTower.java rename to src/main/java/fr/ynerant/leveleditor/game/AutoTower.java index bd48827..6eb3e1f 100644 --- a/src/main/java/fr/ynerant/leveleditor/game/SuperTower.java +++ b/src/main/java/fr/ynerant/leveleditor/game/AutoTower.java @@ -2,11 +2,16 @@ package fr.ynerant.leveleditor.game; import java.util.Collection; -public class SuperTower extends Tower { - public SuperTower(int x, int y) { +public class AutoTower extends Tower { + public AutoTower(int x, int y) { super(x, y); } + @Override + public String getName() { + return "autotower"; + } + @Override public int getDamagePerShot() { return 20; diff --git a/src/main/java/fr/ynerant/leveleditor/game/BasicTower.java b/src/main/java/fr/ynerant/leveleditor/game/BasicTower.java index 3ce72bc..0f377f9 100644 --- a/src/main/java/fr/ynerant/leveleditor/game/BasicTower.java +++ b/src/main/java/fr/ynerant/leveleditor/game/BasicTower.java @@ -9,6 +9,11 @@ public class BasicTower extends Tower { super(x, y); } + @Override + public String getName() { + return "basictower"; + } + @Override public int getDamagePerShot() { return 1; diff --git a/src/main/java/fr/ynerant/leveleditor/game/GameFrame.java b/src/main/java/fr/ynerant/leveleditor/game/GameFrame.java index 8d49fb1..c4e853e 100644 --- a/src/main/java/fr/ynerant/leveleditor/game/GameFrame.java +++ b/src/main/java/fr/ynerant/leveleditor/game/GameFrame.java @@ -168,8 +168,8 @@ public class GameFrame extends JFrame { } for (Tower tower : towers) { - g.setColor(Color.blue); - g.fillRect(SPRITE_SIZE * tower.getX(), SPRITE_SIZE * tower.getY(), SPRITE_SIZE, SPRITE_SIZE); + Sprite s = tower.getSprite(); + g.drawImage(s.getImage(), SPRITE_SIZE * tower.getX(), SPRITE_SIZE * tower.getY(), SPRITE_SIZE, SPRITE_SIZE, null, null); } repaint(); diff --git a/src/main/java/fr/ynerant/leveleditor/game/NullTower.java b/src/main/java/fr/ynerant/leveleditor/game/NullTower.java index 3ea628e..798b924 100644 --- a/src/main/java/fr/ynerant/leveleditor/game/NullTower.java +++ b/src/main/java/fr/ynerant/leveleditor/game/NullTower.java @@ -8,6 +8,11 @@ public class NullTower extends Tower { super(x, y); } + @Override + public String getName() { + return "nulltower"; + } + @Override public int getDamagePerShot() { return Integer.MAX_VALUE; diff --git a/src/main/java/fr/ynerant/leveleditor/game/Tower.java b/src/main/java/fr/ynerant/leveleditor/game/Tower.java index 305949c..59ebfd1 100644 --- a/src/main/java/fr/ynerant/leveleditor/game/Tower.java +++ b/src/main/java/fr/ynerant/leveleditor/game/Tower.java @@ -1,21 +1,32 @@ package fr.ynerant.leveleditor.game; +import fr.ynerant.leveleditor.api.editor.sprites.Sprite; +import fr.ynerant.leveleditor.api.editor.sprites.SpriteRegister; + import java.util.ArrayList; import java.util.Collection; import java.util.Random; public abstract class Tower { + private Sprite sprite; private final int x; private final int y; private long remainingTicks; public Tower(int x, int y) { + this.sprite = SpriteRegister.getCategory(getName()).getSprites().get(0); this.x = x; this.y = y; } private static final Random RANDOM = new Random(); + public Sprite getSprite() { + return sprite; + } + + public abstract String getName(); + public abstract int getDamagePerShot(); public abstract long getPeriod(); diff --git a/src/main/resources/assets/leveleditor/textures/sprites/autotower.png b/src/main/resources/assets/leveleditor/textures/sprites/autotower.png new file mode 100644 index 0000000000000000000000000000000000000000..3177412873312820763c8dff8acd5efa5ed33e5a GIT binary patch literal 696 zcmV;p0!RIcP)EX>4Tx04R}tkv&MmKpe$iQ>7{u2Ro=Z1gzp;lcSTOibnM}+Rhls^o3o9+m@}@>SMI2T&o$`fL zomI|ToV8+^HSWn@7|iG^%Uq{9h!_^J1PLM(luN1;QA$UDdZ}E zkz)ZRXpmh$_#gc4*2+#!)RTfyp#8;hK8At7E>NpD&iAq7)J_2ZGjOFh{iP}}^GSN8 zsfCY#o^9abx~VC9z~v6m_hiVX>`H!`LN*J$pV2p^f!y{D4^000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2jl`72`e!^uYR2X000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}0001wNklGNmy{5Z1tW`QK!Q=L`%Cp{U~j|1<4lkYix@ z|CezagB$|`EX>4Tx04R}tkv&MmKpe$iQ>7{u2Ro=Z1gzp;lcSTOibnM}+Rhls^o3o9+m@}@>SMI2T&o$`fL zomI|ToV8+^HSWn@7|iG^%Uq{9h!_^J1PLM(luN1;QA$UDdZ}E zkz)ZRXpmh$_#gc4*2+#!)RTfyp#8;hK8At7E>NpD&iAq7)J_2ZGjOFh{iP}}^GSN8 zsfCY#o^9abx~VC9z~v6m_hiVX>`H!`LN*J$pV2p^f!y{D4^000SaNLh0L z04^f{04^f|c%?sf00007bV*G`2jl`72`@9W&Dym9000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}0001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