From b682ad199cbdacc1b5b69444d0c378254c764a24 Mon Sep 17 00:00:00 2001 From: JDG Date: Sat, 13 Nov 2021 00:44:20 +0100 Subject: [PATCH] Moved the balls behind the bar --- Ball.js | 1 + index.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Ball.js b/Ball.js index 4574385..0b9b7f8 100644 --- a/Ball.js +++ b/Ball.js @@ -55,6 +55,7 @@ class Ball { this.moving = 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) ) { // Down (Bar) diff --git a/index.js b/index.js index b15b640..7c76180 100644 --- a/index.js +++ b/index.js @@ -62,12 +62,12 @@ function init() { if(gstate==2) { gameOver.update(); } else { - bar.update(); balls = balls.filter(ball => ball.update()); if (balls.length==0) { if ( lives.lost() ) gstate=2; else balls.push(new Ball(ctx, bar)); } + bar.update(); } score.update(); lives.update();