Skip to content

Commit

Permalink
Added required animations and sprite for income tower
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasakev committed Sep 6, 2023
1 parent ea7a783 commit f7ceec2
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 0 deletions.
55 changes: 55 additions & 0 deletions source/core/assets/images/economy/econ-tower.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@

econ-tower.png
size: 256, 64
format: RGBA8888
filter: Nearest, Nearest
repeat: none
move1
rotate: false
xy: 122, 2
size: 28, 31
orig: 28, 31
offset: 0, 0
index: -1
move2
rotate: false
xy: 32, 2
size: 28, 31
orig: 28, 31
offset: 0, 0
index: -1
move3
rotate: false
xy: 182, 2
size: 28, 31
orig: 28, 31
offset: 0, 0
index: -1
move4
rotate: false
xy: 92, 2
size: 28, 31
orig: 28, 31
offset: 0, 0
index: -1
move5
rotate: false
xy: 2, 2
size: 28, 31
orig: 28, 31
offset: 0, 0
index: -1
move6
rotate: false
xy: 152, 2
size: 28, 31
orig: 28, 31
offset: 0, 0
index: -1
move7
rotate: false
xy: 62, 2
size: 28, 31
orig: 28, 31
offset: 0, 0
index: -1
Binary file added source/core/assets/images/economy/econ-tower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.csse3200.game.components.tower;

import com.badlogic.gdx.audio.Sound;
import com.csse3200.game.components.Component;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;

/**
* Listens for events relevant to a weapon tower state.
* Each event will trigger a certain animation
*/
public class TowerAnimationController 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";

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
* be attached to and registers all the event listeners required to trigger the animations and sounds.
*/
@Override
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);
}

/**
* Starts the
*/
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();
}
}

0 comments on commit f7ceec2

Please sign in to comment.