Skip to content

Commit

Permalink
Added more suitable animation as well as implementing activator
Browse files Browse the repository at this point in the history
  • Loading branch information
cindyle1 committed Sep 7, 2023
1 parent ffde6f4 commit 8919913
Show file tree
Hide file tree
Showing 13 changed files with 100 additions and 83 deletions.
48 changes: 16 additions & 32 deletions source/core/assets/images/projectiles/basic_projectile.atlas
Original file line number Diff line number Diff line change
@@ -1,50 +1,34 @@

basic_projectile.png
size: 128, 32
size: 256, 32
format: RGBA8888
filter: Nearest, Nearest
repeat: none
projectileFinal5
rotate: false
xy: 2, 17
size: 24, 13
orig: 24, 13
offset: 0, 0
index: 5
projectile4
projectile
rotate: false
xy: 2, 2
size: 23, 13
orig: 23, 13
size: 36, 19
orig: 36, 19
offset: 0, 0
index: 4
projectile3
projectileFinal
rotate: false
xy: 27, 2
size: 23, 13
orig: 23, 13
xy: 103, 3
size: 30, 18
orig: 30, 18
offset: 0, 0
index: 3
projectile2
projectile
rotate: false
xy: 28, 17
size: 23, 13
orig: 23, 13
xy: 40, 2
size: 30, 19
orig: 30, 19
offset: 0, 0
index: 2
projectileStart1
projectile
rotate: false
xy: 53, 16
size: 22, 14
orig: 22, 14
xy: 72, 2
size: 29, 19
orig: 29, 19
offset: 0, 0
index: 1
default
rotate: false
xy: 53, 16
size: 22, 14
orig: 22, 14
offset: 0, 0
index: 1


Binary file modified source/core/assets/images/projectiles/basic_projectile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions source/core/assets/images/projectiles/basic_projectile_old.atlas
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

basic_projectile_old.png
size: 256, 32
format: RGBA8888
filter: Nearest, Nearest
repeat: none
projectileFinal
rotate: false
xy: 34, 2
size: 30, 19
orig: 30, 19
offset: 0, 0
index: 5
projectile
rotate: false
xy: 66, 2
size: 30, 19
orig: 30, 19
offset: 0, 0
index: 2
projectile
rotate: false
xy: 98, 2
size: 29, 19
orig: 29, 19
offset: 0, 0
index: 1
projectile
rotate: false
xy: 129, 2
size: 29, 19
orig: 29, 19
offset: 0, 0
index: 3
default
rotate: false
xy: 129, 2
size: 29, 19
orig: 29, 19
offset: 0, 0
index: 3
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/towers/mine_tower.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/towers/turret.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/towers/turret_deployed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified source/core/assets/images/towers/wallTower.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
Expand Up @@ -48,7 +48,7 @@ public class ForestGameArea extends GameArea {

// Required to load assets before using them
private static final String[] forestTextures = {
"images/projectiles/projectile.png",
// "images/projectiles/projectile.png",
"images/box_boy_leaf.png",
"images/background/building1.png",
"images/ghost_1.png",
Expand Down Expand Up @@ -85,7 +85,7 @@ public class ForestGameArea extends GameArea {
"images/iso_grass_3.png",
"images/economy/scrap.png",
"images/towers/mine_tower.png",
"images/projectiles/basic_projectiles.png"
"images/projectiles/basic_projectile.png"
};
private static final String[] forestTextureAtlases = {
"images/terrain_iso_grass.atlas",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,16 @@

import com.csse3200.game.components.Component;
import com.csse3200.game.rendering.AnimationRenderComponent;
import com.csse3200.game.services.ServiceLocator;
import com.csse3200.game.services.ServiceLocator; //used for sound

public class ProjectileAnimationController extends Component{
/** Event name constants */
private static final String START = "startProjectileStart1";
private static final String PHASE1 = "startProjectile2";
private static final String PHASE2 = "startProjectile3";
private static final String PHASE3 = "startProjectile4";
private static final String FINAL = "startProjectileFinish5";
private static final String START = "startProjectile";
private static final String FINAL = "startProjectileFinal";

/** Animation name constants */
private static final String START_ANIM = "projectileStart1";
private static final String PHASE1_ANIM = "projectile2";
private static final String PHASE2_ANIM = "projectile3";
private static final String PHASE3_ANIM = "projectile4";
private static final String FINAL_ANIM = "projectileFinish5";
private static final String START_ANIM = "projectile";
private static final String FINAL_ANIM = "projectileFinal";

AnimationRenderComponent animator;

Expand All @@ -26,29 +20,14 @@ public void create() {
super.create();
animator = this.entity.getComponent(AnimationRenderComponent.class);
entity.getEvents().addListener(START, this::animateStart);
entity.getEvents().addListener(START, this::animatePhase1);
entity.getEvents().addListener(START, this::animatePhase2);
entity.getEvents().addListener(START, this::animatePhase3);
entity.getEvents().addListener(START, this::animateFinal);
entity.getEvents().addListener(FINAL, this::animateFinal);

}

void animateStart() {
animator.startAnimation(START_ANIM);
}

void animatePhase1() {
animator.startAnimation(PHASE1_ANIM);
}

void animatePhase2() {
animator.startAnimation(PHASE2_ANIM);
}

void animatePhase3() {
animator.startAnimation(PHASE3_ANIM);
}

void animateFinal() {
animator.startAnimation(FINAL_ANIM);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void updateTowerState() {
owner.getEntity().getEvents().trigger(FIRING);
// this might be changed to an event which gets triggered everytime the tower enters the firing state
Entity newProjectile = ProjectileFactory.createFireBall(owner.getEntity(), new Vector2(100, owner.getEntity().getPosition().y), new Vector2(2f,2f));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x + 0.75), (float) (owner.getEntity().getPosition().y + 0.75));
newProjectile.setPosition((float) (owner.getEntity().getPosition().x + 0.75), (float) (owner.getEntity().getPosition().y + 0.4));
ServiceLocator.getEntityService().register(newProjectile);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
import com.badlogic.gdx.math.Vector2;
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.services.GameTime;

/** Trajects a projectile from an entity towards the enemy entities */
public class TrajectTask extends DefaultTask implements PriorityTask {
private final int priority = 10;
private MovementTask movementTask;
private Vector2 destination;
private static final String START = "startProjectile";
private static final String FINAL = "startProjectileFinal";

private enum STATE {
START, FINAL
}
private STATE projectileState = STATE.START;

private GameTime projectSpawn;

/**
* @param destination The destination that the projectile will move towards.
Expand All @@ -26,8 +36,15 @@ public void start() {
movementTask = new MovementTask(destination);
movementTask.create(owner);
movementTask.start();

this.owner.getEntity().getEvents().trigger("trajectStart");
this.owner.getEntity().getEvents().trigger(START);
}

public void switchProjectileState() {
switch (projectileState) {
case START:
this.owner.getEntity().getEvents().trigger(FINAL);
projectileState = STATE.FINAL;
}
}

@Override
Expand All @@ -36,13 +53,15 @@ public void update() {
movementTask.update();
if (movementTask.getStatus() != Status.ACTIVE) {
movementTask.start();
switchProjectileState();
}
}

@Override
public void stop() {
super.stop();
movementTask.stop();
this.owner.getEntity().getEvents().trigger(FINAL);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@
public class ProjectileFactory {
/** Animation constants */
private static final String BASE_PROJECTILE_ATLAS = "images/projectiles/basic_projectile.atlas";
private static final String START_ANIM = "projectileStart1";
private static final String PHASE1_ANIM = "projectile2";
private static final String PHASE2_ANIM = "projectile3";
private static final String PHASE3_ANIM = "projectile4";
private static final String FINAL_ANIM = "projectileFinish5";
private static final float START_SPEED = 0.3f;
private static final float PHASE1_SPEED = 0.3f;
private static final float PHASE2_SPEED = 0.3f;
private static final float PHASE3_SPEED = 0.3f;
private static final float FINAL_SPEED = 0.3f;
private static final String START_ANIM = "projectile";
private static final String FINAL_ANIM = "projectileFinal";
private static final float START_SPEED = 0.1f;
private static final float FINAL_SPEED = 0.1f;

private static final NPCConfigs configs =
FileLoader.readClass(NPCConfigs.class, "configs/NPCs.json");
Expand All @@ -56,9 +50,17 @@ public static Entity createFireBall(Entity target, Vector2 destination, Vector2

Entity projectile = createBaseProjectile(target, destination);

AnimationRenderComponent animator =
new AnimationRenderComponent(
ServiceLocator.getResourceService()
.getAsset(BASE_PROJECTILE_ATLAS, TextureAtlas.class));
animator.addAnimation(START_ANIM, START_SPEED, Animation.PlayMode.NORMAL);
animator.addAnimation(FINAL_ANIM, FINAL_SPEED, Animation.PlayMode.NORMAL);

projectile
// .addComponent(new TextureRenderComponent("images/projectiles/projectile.png"))
.addComponent(new ProjectileAnimationController())
.addComponent(new ColliderComponent().setSensor(true))
.addComponent(animator)

// This is the component that allows the projectile to damage a specified target.
.addComponent(new TouchAttackComponent(PhysicsLayer.PLAYER, 1.5f, true))
Expand All @@ -70,14 +72,6 @@ public static Entity createFireBall(Entity target, Vector2 destination, Vector2
projectile
.getComponent(PhysicsMovementComponent.class).setSpeed(speed);

AnimationRenderComponent animator = new AnimationRenderComponent(
ServiceLocator.getResourceService()
.getAsset(BASE_PROJECTILE_ATLAS, TextureAtlas.class));
animator.addAnimation(START_ANIM, START_SPEED, Animation.PlayMode.NORMAL);
animator.addAnimation(PHASE1_ANIM, PHASE1_SPEED, Animation.PlayMode.NORMAL);
animator.addAnimation(PHASE2_ANIM, PHASE2_SPEED, Animation.PlayMode.NORMAL);
animator.addAnimation(PHASE3_ANIM, PHASE3_SPEED, Animation.PlayMode.NORMAL);
animator.addAnimation(FINAL_ANIM, FINAL_SPEED, Animation.PlayMode.NORMAL);

return projectile;
}
Expand Down

0 comments on commit 8919913

Please sign in to comment.