dimanche 4 juin 2017

Breakout Clone Lives Bug

I am currently making a Breakout clone and it's almost fully playable, but I'm running into an issue with the ball. I implemented lives into the game, and when the ball hits the bottom of the canvas, it just keeps bouncing towards the canvas. Here's some of the collision code. You can see all of the code on Codepen.

else if(y + dy > canvas.height - ballRadius) {
    if(x > paddleX && x < paddleX + paddleWidth) {
        dy = -dy;
    }
    else {
        lives--;
        if(!lives) {
            alert("GAME OVER!");
            window.location.reload(true);
        }
        else {
            x = canvas.width / 2;
            y = canvas.height - 30;
            dx = 2;
            dx = -2;
        }
   }

}

Aucun commentaire:

Enregistrer un commentaire