Skip to content

Commit

Permalink
changing functionality so that a sequence flag is being used to trigg…
Browse files Browse the repository at this point in the history
…er the Demon boss action sequence
  • Loading branch information
gregchan550 committed Sep 18, 2023
1 parent d6f331a commit c3067a5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.csse3200.game.ai.tasks.DefaultTask;
import com.csse3200.game.ai.tasks.PriorityTask;
import com.csse3200.game.components.tasks.MovementTask;
import com.csse3200.game.components.tasks.WaitTask;
import com.csse3200.game.entities.Entity;
import com.csse3200.game.physics.PhysicsEngine;
import com.csse3200.game.physics.components.PhysicsMovementComponent;
Expand All @@ -19,7 +20,7 @@ public class DemonBossTask extends DefaultTask implements PriorityTask {

// Constants
private static final int PRIORITY = 3;
private static final Vector2 DEMON_JUMP_SPEED = new Vector2(1f, 1f);
private static final Vector2 DEMON_JUMP_SPEED = new Vector2(2f, 2f);
private static final float STOP_DISTANCE = 0.1f;
private static final float TIME_INTERVAL = 10f; // 10 seconds

Expand All @@ -36,6 +37,7 @@ public class DemonBossTask extends DefaultTask implements PriorityTask {
private AnimationRenderComponent animation;
private Entity demon;
private float elapsedTime = 0f;
private boolean sequenceFlag = false;

private enum DEMON_STATE {
TRANSFORM, IDLE, CAST, CLEAVE, DEATH, BREATH, SMASH, TAKE_HIT, WALK
Expand All @@ -60,21 +62,30 @@ public void update() {
currentPos = owner.getEntity().getPosition();
animate();

// Check if transform is complete
if (state.equals(DEMON_STATE.TRANSFORM)) {
if (!animation.isFinished()) {
return;
}
}
state = DEMON_STATE.IDLE;
// // Check if transform is complete
// if (state.equals(DEMON_STATE.TRANSFORM)) {
// WaitTask wait = new WaitTask(2);
// wait.create(owner);
// }
// changeState(DEMON_STATE.IDLE);

// Every 10 seconds perform sequence
// Change sequence flag to true every 10 seconds
elapsedTime += gameTime.getDeltaTime();
if (elapsedTime >= TIME_INTERVAL) {
jump(getJumpPos());

sequenceFlag = true;
elapsedTime = 0f; // Reset the elapsed time
}

// Do nothing if sequence flag is false
if (!sequenceFlag) {return;}

// Run sequence otherwise

}

private void changeState(DEMON_STATE state) {
prevState = this.state;
this.state = state;
}

private void animate() {
Expand All @@ -93,11 +104,8 @@ private void animate() {
case CLEAVE -> demon.getEvents().trigger("demon_cleave");
case TAKE_HIT -> demon.getEvents().trigger("demon_take_hit");
case TRANSFORM -> demon.getEvents().trigger("transform");
default -> {
logger.debug("Demon animation {state} not found");
}
default -> logger.debug("Demon animation {state} not found");
}
prevState = state;
}

@Override
Expand All @@ -106,7 +114,7 @@ public int getPriority() {
}

private void jump(Vector2 finalPos) {
state = DEMON_STATE.SMASH;
changeState(DEMON_STATE.SMASH);

jumpTask = new MovementTask(finalPos);
jumpTask.create(owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ public static Entity createDemonBoss() {
// Animation addition
AnimationRenderComponent animator = new AnimationRenderComponent(
ServiceLocator.getResourceService().getAsset("images/mobboss/demon.atlas", TextureAtlas.class));
animator.addAnimation("demon_cast_spell", 0.2f, Animation.PlayMode.NORMAL);
animator.addAnimation("demon_cleave", 0.2f, Animation.PlayMode.NORMAL);
animator.addAnimation("demon_death", 0.2f, Animation.PlayMode.NORMAL);
animator.addAnimation("demon_fire_breath", 0.2f, Animation.PlayMode.NORMAL);
animator.addAnimation("demon_cast_spell", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("demon_cleave", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("demon_death", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("demon_fire_breath", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("demon_idle", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("demon_smash", 0.2f, Animation.PlayMode.NORMAL);
animator.addAnimation("demon_take_hit", 0.2f, Animation.PlayMode.NORMAL);
animator.addAnimation("demon_smash", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("demon_take_hit", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("demon_walk", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("idle", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("move", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("projectile_explosion", 0.2f, Animation.PlayMode.NORMAL);
animator.addAnimation("projectile_explosion", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("projectile_idle", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("take_hit", 0.2f, Animation.PlayMode.NORMAL);
animator.addAnimation("transform", 0.2f, Animation.PlayMode.NORMAL);
animator.addAnimation("take_hit", 0.2f, Animation.PlayMode.LOOP);
animator.addAnimation("transform", 0.2f, Animation.PlayMode.LOOP);


// AI task addition
Expand Down

0 comments on commit c3067a5

Please sign in to comment.