Skip to content

Commit

Permalink
Added required econ tower sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasakev committed Sep 6, 2023
1 parent f7ceec2 commit 53d7484
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 46 deletions.
12 changes: 6 additions & 6 deletions source/core/assets/images/economy/econ-tower.atlas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
/**
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public void setUp() {
resourceService.loadAll();
scrap = DropFactory.createScrapDrop();
}

@Test
void shouldCreateCurrency() {
Currency currency = mock(Currency.class, CALLS_REAL_METHODS);
Expand Down

0 comments on commit 53d7484

Please sign in to comment.