ReOrganizing the code
This commit is contained in:
42
GamePlay.js
Normal file
42
GamePlay.js
Normal 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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user