Moved the balls behind the bar

This commit is contained in:
José David Guillén 2021-11-13 00:44:20 +01:00
parent ae92c56957
commit b682ad199c
2 changed files with 2 additions and 1 deletions

View File

@ -55,6 +55,7 @@ class Ball {
this.moving = false; this.moving = false;
return false; return false;
} }
if (this.y > this.bar.y ) return true; // Ball is lost, don't check anything else
if ( (this.y + this.size) > this.bar.y && this.x > this.bar.x && this.x < (this.bar.x + this.bar.w) ) { if ( (this.y + this.size) > this.bar.y && this.x > this.bar.x && this.x < (this.bar.x + this.bar.w) ) {
// Down (Bar) // Down (Bar)

View File

@ -62,12 +62,12 @@ function init() {
if(gstate==2) { if(gstate==2) {
gameOver.update(); gameOver.update();
} else { } else {
bar.update();
balls = balls.filter(ball => ball.update()); balls = balls.filter(ball => ball.update());
if (balls.length==0) { if (balls.length==0) {
if ( lives.lost() ) gstate=2; if ( lives.lost() ) gstate=2;
else balls.push(new Ball(ctx, bar)); else balls.push(new Ball(ctx, bar));
} }
bar.update();
} }
score.update(); score.update();
lives.update(); lives.update();