breakout/Score.js
2021-11-12 18:44:25 +01:00

26 lines
591 B
JavaScript

class Score {
constructor(ctx) {
this.ctx = ctx;
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;
}
add(x) {
this.points += x;
}
update() {
if (this.y != 30) 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);
}
}
}