Skip to content

Commit

Permalink
sequence kind of works and runs smoothly but implementation has a bun…
Browse files Browse the repository at this point in the history
…ch of flags because some tasks arent working. will probs rewrite code
  • Loading branch information
gregchan550 committed Sep 18, 2023
1 parent dee424f commit 6a619a5
Showing 1 changed file with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Double> 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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -131,7 +149,6 @@ public int getPriority() {
}

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

jumpTask = new MovementTask(finalPos);
Expand Down Expand Up @@ -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));

Expand All @@ -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);
}
}
}

0 comments on commit 6a619a5

Please sign in to comment.