Question: Please correct my code so that the following project is satisfied: Create a bug squish game in p5 javascript that will progressively speed up as
Please correct my code so that the following project is satisfied:
Create a bug squish game in p5 javascript that will progressively speed up as you "kill" bugs. Please fix my code so that the speed of the bugs ONLY speeds up when a bug is pressed, NOT when the time goes on.
This is the code I have so far and I have the sprites linked in my code for bugs and deadBugs:
class Bug {
constructor() {
this.x = random(width);
this.y = random(height);
this.size = 50;
this.speed = 2;
this.dead = false;
}
display() {
if (!this.dead) {
image(bug, this.x, this.y, this.size, this.size);
} else {
image(deadBug, this.x, this.y, this.size, this.size);
}
}
move() {
this.x += random(-this.speed, this.speed);
this.y += random(-this.speed, this.speed);
this.speed += 0.05;
}
isClicked(mx, my) {
let d = dist(mx, my, this.x, this.y);
if (d < this.size / 2) {
this.dead = true;
return true;
}
return false;
}
}
PLEASE FIX MY CODE SO THAT THE SPEED OF THE BUGS ONLY GET FASTER AFTER YOU CLICK ON THE BUG!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
