From 6a619a57120f8c3f54df0b0194fbaf005c059adc Mon Sep 17 00:00:00 2001 From: gregchan550 <86044792+gregchan550@users.noreply.github.com> Date: Mon, 18 Sep 2023 22:35:02 +1000 Subject: [PATCH] sequence kind of works and runs smoothly but implementation has a bunch of flags because some tasks arent working. will probs rewrite code --- .../tasks/bosstask/DemonBossTask.java | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java index c36536aa6..3537a5c0c 100644 --- a/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java +++ b/source/core/src/main/com/csse3200/game/components/tasks/bosstask/DemonBossTask.java @@ -45,9 +45,9 @@ public class DemonBossTask extends DefaultTask implements PriorityTask { private AnimationRenderComponent animation; private Entity demon; private float elapsedTime = 0f; - private boolean sequenceFlag = false; Array yArray = new Array<>(); - WaitTask waitTask; + private boolean isBreath; + private boolean waitFlag = false; private enum DEMON_STATE { TRANSFORM, IDLE, CAST, CLEAVE, DEATH, BREATH, SMASH, TAKE_HIT, WALK @@ -81,23 +81,41 @@ public void run() { @Override public void update() { animate(); + System.out.println(state); + currentPos = demon.getPosition(); switch (state) { case IDLE -> {jump(getJumpPos());} case SMASH -> { if (jumpComplete()) { fireBreath(); + isBreath = true; } } - case BREATH -> Timer.schedule(new Timer.Task() { - @Override - public void run() { + case BREATH -> { + if (!isBreath) { changeState(DEMON_STATE.IDLE); + waitFlag = false; + } else { + if (waitFlag) { + return; + } + waitTask(); } - }, 4.2f); // Delay in seconds + } } } + private void waitTask() { + waitFlag = true; + // to be replaced by wait task + Timer.schedule(new Timer.Task() { + @Override + public void run() { + isBreath = false; + } + }, 4.2f); // Delay in seconds + } private void changeState(DEMON_STATE state) { prevState = this.state; this.state = state; @@ -131,7 +149,6 @@ public int getPriority() { } private void jump(Vector2 finalPos) { - sequenceFlag = false; changeState(DEMON_STATE.SMASH); jumpTask = new MovementTask(finalPos); @@ -188,7 +205,7 @@ private void fireBreath() { // add constant y changes to burn projectile yArray.add(Math.sqrt(3)); yArray.add(1/Math.sqrt(3)); - yArray.add(1d); + yArray.add(0d); yArray.add(-1/Math.sqrt(3)); yArray.add(-Math.sqrt(3)); @@ -204,6 +221,7 @@ private void fireBreath() { Entity projectile = ProjectileFactory.createEffectProjectile(PhysicsLayer.HUMANS, destination, new Vector2(2,2), ProjectileEffects.BURN, false); projectile.setPosition(demon.getPosition().x, demon.getPosition().y); + ServiceLocator.getEntityService().register(projectile); } } }