Added the bricks (and improve the bouncing)

This commit is contained in:
2021-11-14 23:49:49 +01:00
parent 0f4a403edb
commit 7493713529
12 changed files with 303 additions and 111 deletions

View File

@ -1,25 +1,21 @@
class Score {
constructor(ctx) {
this.ctx = ctx;
constructor() {
this.reset();
this.ctx.font = "30px Consolas";
let m = ctx.measureText('Score: 00000');
this.x = ctx.canvas.width - m.width;
this.y = -10;
}
reset() {
this.points = 0;
this.x = 235;
this.y = -10;
}
add(x) {
this.points += x;
}
update() {
if (this.y != 30) this.y++;
update(ctx) {
if (this.y != 20) this.y++;
if (this.y > 0) {
this.ctx.font = "30px Consolas";
this.ctx.fillStyle = 'Black';
this.ctx.fillText('Score: ' + this.points, this.x, this.y);
ctx.font = "20px Consolas";
ctx.fillStyle = 'Black';
ctx.fillText('Score: ' + this.points, this.x, this.y);
}
}
}