ReOrganizing the code

This commit is contained in:
2021-11-14 14:56:31 +01:00
parent b682ad199c
commit 0f4a403edb
7 changed files with 121 additions and 72 deletions

42
GamePlay.js Normal file
View File

@ -0,0 +1,42 @@
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();
}
}