class GamePlay extends Board { constructor(ctx, key) { super(ctx, key); this.controls = { 'KeyX': ()=>{ this.balls.push(new Ball(this.ctx, this.bar)); this.balls[this.balls.length - 1].start(); }, 'Space': ()=>{ this.balls[0].moving = true; } } this.score = new Score(ctx); this.lives = new Lives(ctx); this.bar = new Bar(ctx, key); this.newGame(); } newGame() { this.lives.reset(); this.score.reset(); this.bar.reset(); this.balls = []; this.balls.push(new Ball(this.ctx, this.bar)); } update() { if(this.lives.get()==0) { gameOver.update(); } else { this.balls = this.balls.filter(ball => ball.update()); if (this.balls.length==0) { if ( !this.lives.lost() ) this.balls.push(new Ball(this.ctx, this.bar)); } this.bar.update(); } this.score.update(); this.lives.update(); } }