26 lines
591 B
JavaScript
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);
|
|
}
|
|
}
|
|
}
|