I am using the collide2D library in p5.js to detect if my player hits an obstacle. If it does, i wantthe player to have 1 less lives. The problem i’ve run in to is that when i hit an obstacle it keeps removing lives for the whole time i hover over it so i end up with -100 lives when i hover over the whole obstacle.
Code in class Rock(my obstacle):
isColliding(obj) {
let hit = collideRectCircle(obj.x - 55, obj.y - 60, 105, 109, this.x, this.y, 130);
return hit;
}
code in draw:
for (let i = 0; i < rocks.length; i++) {
if (rocks[i].isColliding(unicorn)) {
lives -= 1
// if (lives <= 0) {
// gameOver();
// }
}