Skip to content

Commit

Permalink
Changed getJumpPos to jump a certain distance so itll fit better with…
Browse files Browse the repository at this point in the history
… the animation
  • Loading branch information
gregchan550 committed Sep 19, 2023
1 parent 6a619a5 commit 83a35ca
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class DemonBossTask extends DefaultTask implements PriorityTask {
private static final float TIME_INTERVAL = 10f; // 10 seconds
private static final int BURN_BALLS = 5;
private static final int X_LENGTH = 20; // for projectile destination calculations
private static final int JUMP_DISTANCE = 4;

// Private variables
private static final Logger logger = LoggerFactory.getLogger(DemonBossTask.class);
Expand Down Expand Up @@ -165,23 +166,28 @@ private Vector2 getJumpPos() {
// check where demon can jump
float jumpMinX = currentPos.x - 4;
float jumpMaxX = currentPos.x + 4;
float jumpMinY = currentPos.y - 4;
float jumpMaxY = currentPos.y + 4;

if (jumpMinX < 1) {
jumpMinX = 1;
} else if (jumpMaxX > 18) {
jumpMaxX = 18;
} else if (jumpMinY < 1) {
jumpMinX = 1;
} else if (jumpMinY > 7) {
jumpMaxY = 7;
}

// check x bounds
if (jumpMinX < 1) { jumpMinX = 1; }
else if (jumpMaxX > 18) { jumpMaxX = 18; }

// generate random jump pos
float randomX = MathUtils.random(jumpMinX, jumpMaxX);
float randomY = MathUtils.random(jumpMinY, jumpMaxY);
return jumpPos = new Vector2(randomX, randomY);
float yLen = (float) Math.sqrt(Math.pow(JUMP_DISTANCE, 2) - Math.pow(randomX, 2));
float yDown = demon.getPosition().y - yLen;
float yUp = demon.getPosition().y + yLen;
float yValue = 0;

// check y bounds
if (yUp > 7) { yValue = yDown; }
if (yDown < 1) { yValue = yUp; }

// randomise y value selection
if (yValue == 0) {
int randomNumber = (int) (Math.random() * 100);
if (randomNumber % 2 == 0) { yValue = yUp; } else { yValue = yDown; }
}
return jumpPos = new Vector2(randomX, yValue);
}

private boolean isAtTarget() {
Expand Down

0 comments on commit 83a35ca

Please sign in to comment.