Hello… And alrighty, so the issue I’ve been having is that I can’t seem to figure out how to reset my code but with a certain variable changed after a specific event. For more clarification, I’m trying to reset the code after my character collides with an enemy, but with one less life
Player: function (img, x, y, w, h) {
//bunch of functional code regarding animation, location and other properties goes here and whatnot
this.lives = 3;
}
^^^Character variable stated in a separate file
if (entity.type === "enemy") {
if (player.x < entity.x && player.y >= entity.y) {
player.x = entity.x - player.w;
player.lives -=1;
}
if (player.x > entity.x && player.y >= entity.y) {
player.x = entity.x + entity.w;
player.lives -=1;
}
if (player.y < entity.y && (player.x + player.w) > entity.x + 10 &&
player.x < (entity.x + entity.w) - 10 && player.velY >= 0) {
player.y = entity.y - player.h;
player.velY = 0;
jack.lives -=1;
}
}
^^^This is the already functional collision code/the event which I need to restart my code with…
I’ve tried the window.reload, but that resets everything, and renders the lives useless.
So yeah, any help regarding the above would greatly be appreciated!