Skip to content

Commit

Permalink
updated enemy code with new abilities
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielFitzwilliam committed Dec 9, 2023
1 parent 30906ab commit 148f298
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions assets/js/platformer/Enemy.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export class Enemy extends Character {
this.speed = -this.speed;
}

//Randomly change when the Goomba changes position
if (Math.random() < 0.006) {
this.speed = Math.random() < 0.5 ? -this.speed : this.speed;
}

//Randomly turn Goomba into God Mode
if (Math.random() < 0.01) {
this.performGoombaSpecial();
}

//Initially get the enemy moving
this.x += this.speed;

Expand All @@ -39,6 +49,33 @@ export class Enemy extends Character {
console.log("destroyed");
};
};

performGoombaSpecial() {
if (!this.specialActionActive) {
// Temporary increase in speed
const originalSpeed = this.speed;
this.speed *= 4; // You can adjust the multiplier based on your game's design

//Change the styling and scale of the enemy
this.canvas.style.transform = 'scaleX(-1)';
this.canvas.style.filter = 'invert(1)';
this.canvas.style.transform = 'scale(1.5)';


// Set a timeout to revert the speed to the original value after a certain duration
setTimeout(() => {
this.speed = originalSpeed;
this.canvas.style.transform = 'scaleX(1)';
this.canvas.style.filter = 'invert(0)';
this.canvas.style.transform = 'scale(1)';

this.specialActionActive = false; // Reset the flag after the timeout
}, 3000);

// Set the flag to indicate that the special action is active
this.specialActionActive = true;
}
}

/* murder() {
let i = 1;
Expand Down

0 comments on commit 148f298

Please sign in to comment.