From 53d7484a180d7f77388e8bd9c9f42d000ae127d7 Mon Sep 17 00:00:00 2001 From: Kevin Date: Wed, 6 Sep 2023 14:20:46 +1000 Subject: [PATCH] Added required econ tower sprites --- .../assets/images/economy/econ-tower.atlas | 12 +++--- .../csse3200/game/areas/ForestGameArea.java | 6 ++- .../game/components/tasks/CurrencyTask.java | 2 + .../tower/EconTowerAnimationController.java | 37 +------------------ .../game/entities/factories/TowerFactory.java | 21 ++++++++++- .../csse3200/game/currency/CurrencyTest.java | 1 - 6 files changed, 33 insertions(+), 46 deletions(-) diff --git a/source/core/assets/images/economy/econ-tower.atlas b/source/core/assets/images/economy/econ-tower.atlas index 2f9387548..9193bdf19 100644 --- a/source/core/assets/images/economy/econ-tower.atlas +++ b/source/core/assets/images/economy/econ-tower.atlas @@ -11,42 +11,42 @@ move1 orig: 28, 31 offset: 0, 0 index: -1 -move2 +move1 rotate: false xy: 32, 2 size: 28, 31 orig: 28, 31 offset: 0, 0 index: -1 -move3 +move1 rotate: false xy: 182, 2 size: 28, 31 orig: 28, 31 offset: 0, 0 index: -1 -move4 +move1 rotate: false xy: 92, 2 size: 28, 31 orig: 28, 31 offset: 0, 0 index: -1 -move5 +move1 rotate: false xy: 2, 2 size: 28, 31 orig: 28, 31 offset: 0, 0 index: -1 -move6 +move1 rotate: false xy: 152, 2 size: 28, 31 orig: 28, 31 offset: 0, 0 index: -1 -move7 +move1 rotate: false xy: 62, 2 size: 28, 31 diff --git a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java index 2e2f7a0a6..8644f7261 100644 --- a/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java +++ b/source/core/src/main/com/csse3200/game/areas/ForestGameArea.java @@ -95,10 +95,12 @@ public class ForestGameArea extends GameArea { "images/Dusty_MoonBG.png", "images/economy/scrap.png", - "images/towers/mine_tower.png" + "images/economy/econ-tower.png" + }; private static final String[] forestTextureAtlases = { + "images/economy/econ-tower.atlas", "images/terrain_iso_grass.atlas", "images/ghost.atlas", "images/ghostKing.atlas", @@ -460,7 +462,7 @@ private void spawnIncome() { GridPoint2 minPos = new GridPoint2(0, 0); GridPoint2 maxPos = terrain.getMapBounds(0).sub(2, 2); - for (int i = 0; i < 5; i++) { + for (int i = 0; i < 50; i++) { GridPoint2 randomPos = RandomUtils.random(minPos, maxPos); Entity towerfactory = TowerFactory.createIncomeTower(); spawnEntityAt(towerfactory, randomPos, true, true); diff --git a/source/core/src/main/com/csse3200/game/components/tasks/CurrencyTask.java b/source/core/src/main/com/csse3200/game/components/tasks/CurrencyTask.java index f38d02f51..4ed84c265 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/CurrencyTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/CurrencyTask.java @@ -20,6 +20,7 @@ public class CurrencyTask extends DefaultTask implements PriorityTask { private int interval; private final Scrap scrap = new Scrap(); // currency to update private final int currencyAmount = scrap.getAmount(); // amount of currency to update + private static final String IDLE = "idleStart"; /** * @param priority Task priority for currency updates. Must be a positive integer. @@ -38,6 +39,7 @@ public CurrencyTask(int priority, int interval) { public void start() { super.start(); endTime = timeSource.getTime() + (INTERVAL * 1000); + owner.getEntity().getEvents().trigger(IDLE); } /** diff --git a/source/core/src/main/com/csse3200/game/components/tower/EconTowerAnimationController.java b/source/core/src/main/com/csse3200/game/components/tower/EconTowerAnimationController.java index a53084434..9f36641c3 100644 --- a/source/core/src/main/com/csse3200/game/components/tower/EconTowerAnimationController.java +++ b/source/core/src/main/com/csse3200/game/components/tower/EconTowerAnimationController.java @@ -9,29 +9,13 @@ * Listens for events relevant to a weapon tower state. * Each event will trigger a certain animation */ -public class TowerAnimationController extends Component { +public class EconTowerAnimationController extends Component { // Event name constants private static final String IDLE = "idleStart"; - private static final String DEPLOY = "deployStart"; - private static final String FIRING = "firingStart"; - private static final String STOW = "stowStart"; // Animation name constants - private static final String IDLE_ANIM = "idle"; - private static final String DEPLOY_ANIM = "deploy"; - private static final String FIRE_ANIM = "firing"; - private static final String STOW_ANIM = "stow"; - // Sound effects constants - private static final String DEPLOY_SFX = "sounds/towers/deploy.mp3"; - private static final String FIRE_SFX = "sounds/towers/gun_shot_trimmed.mp3"; - private static final String STOW_SFX = "sounds/towers/stow.mp3"; + private static final String IDLE_ANIM = "move1"; AnimationRenderComponent animator; - Sound deploySound = ServiceLocator.getResourceService().getAsset( - DEPLOY_SFX, Sound.class); - Sound attackSound = ServiceLocator.getResourceService().getAsset( - FIRE_SFX, Sound.class); - Sound stowSound = ServiceLocator.getResourceService().getAsset( - STOW_SFX, Sound.class); /** * Creation call for a TowerAnimationController, fetches the animationRenderComponent that this controller will @@ -42,9 +26,6 @@ public void create() { super.create(); animator = this.entity.getComponent(AnimationRenderComponent.class); entity.getEvents().addListener(IDLE, this::animateIdle); - entity.getEvents().addListener(STOW, this::animateStow); - entity.getEvents().addListener(DEPLOY, this::animateDeploy); - entity.getEvents().addListener(FIRING, this::animateFiring); } /** @@ -54,18 +35,4 @@ void animateIdle() { animator.startAnimation(IDLE_ANIM); } - void animateStow() { - animator.startAnimation(STOW_ANIM); - stowSound.play(); - } - - void animateDeploy() { - animator.startAnimation(DEPLOY_ANIM); - deploySound.play(); - } - - void animateFiring() { - animator.startAnimation(FIRE_ANIM); - attackSound.play(); - } } \ No newline at end of file diff --git a/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java b/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java index 04dab2a54..918c6857a 100644 --- a/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java +++ b/source/core/src/main/com/csse3200/game/entities/factories/TowerFactory.java @@ -10,6 +10,7 @@ import com.csse3200.game.components.CombatStatsComponent; import com.csse3200.game.components.CostComponent; import com.csse3200.game.components.tasks.TowerCombatTask; +import com.csse3200.game.components.tower.EconTowerAnimationController; import com.csse3200.game.components.tower.TowerAnimationController; import com.csse3200.game.components.tasks.CurrencyTask; import com.csse3200.game.entities.Entity; @@ -49,6 +50,11 @@ public class TowerFactory { private static final int INCOME_INTERVAL = 300; private static final int INCOME_TASK_PRIORITY = 1; + + private static final String ECO_ATLAS = "images/economy/econ-tower.atlas"; + private static final String ECO_IDLE = "move1"; + private static final float ECO_IDLE_SPEED = 0.3f; + private static final baseTowerConfigs configs = FileLoader.readClass(baseTowerConfigs.class, "configs/tower.json"); /** @@ -66,11 +72,22 @@ public static Entity createIncomeTower() { currencyTask.setInterval(updatedInterval); AITaskComponent aiTaskComponent = new AITaskComponent().addTask(currencyTask); + + // Contains all the animations that the tower will have + AnimationRenderComponent animator = + new AnimationRenderComponent( + ServiceLocator.getResourceService() + .getAsset(ECO_ATLAS, TextureAtlas.class)); + animator.addAnimation(ECO_IDLE, ECO_IDLE_SPEED, Animation.PlayMode.LOOP); + income .addComponent(new CombatStatsComponent(config.health, config.baseAttack)) .addComponent(new CostComponent(config.cost)) - .addComponent(new TextureRenderComponent("images/towers/mine_tower.png")) - .addComponent(aiTaskComponent); + .addComponent(aiTaskComponent) + .addComponent(animator) + .addComponent(new EconTowerAnimationController()); + + return income; diff --git a/source/core/src/test/com/csse3200/game/currency/CurrencyTest.java b/source/core/src/test/com/csse3200/game/currency/CurrencyTest.java index fff7d0c0a..7ed8a22de 100644 --- a/source/core/src/test/com/csse3200/game/currency/CurrencyTest.java +++ b/source/core/src/test/com/csse3200/game/currency/CurrencyTest.java @@ -38,7 +38,6 @@ public void setUp() { resourceService.loadAll(); scrap = DropFactory.createScrapDrop(); } - @Test void shouldCreateCurrency() { Currency currency = mock(Currency.class, CALLS_REAL_METHODS);