Skip to content

Commit

Permalink
fix: combat bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rayallll committed Mar 3, 2024
1 parent 4fa939c commit 2212e4d
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ function ChallengeArea() {
const transitionImage = direction === 'right' ? imagesRight[0] : imagesLeft[0];
setCurrentImage(transitionImage);
}
if (isMagicAttack) {
const magicImage = direction === 'right' ? 'rightMagic.png' : 'leftMagic.png';
setCurrentImage(magicImage);
}
if (attackAnimationInterval) {
clearInterval(attackAnimationInterval);
attackAnimationInterval = null;
Expand Down Expand Up @@ -281,18 +285,20 @@ function ChallengeArea() {
bossImageIndex.current = (bossImageIndex.current + 1) % bossImagesLeft.length;
// set boss attack interval
if (!bossAttackCooldown && BossAttackCollision(distance)) {
setHealth(prevHealth => Math.max(prevHealth - 5, 0));
setBossAttackCooldown(true);
setTimeout(() => {
if (bossHealth > 0){
setHealth(prevHealth => Math.max(prevHealth - 5, 0));
setBossAttackCooldown(true);
setTimeout(() => {
setBossAttackCooldown(false);
}, bossCooldownTime);
}, bossCooldownTime);
}
}
};

const intervalId = setInterval(moveBoss, 80);

return () => clearInterval(intervalId);
}, [position, bossPosition, bossAttackCooldown]);
}, [position, bossPosition, bossAttackCooldown, bossHealth]);
/* ------------- Boss Logic End ------------- */

// check victory
Expand Down

0 comments on commit 2212e4d

Please sign in to comment.