breakout/Lives.js
2021-11-13 00:34:29 +01:00

29 lines
686 B
JavaScript

class Lives {
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 = 20;
}
reset() {
this.lives = 3;
}
lost() {
this.lives--;
return this.lives==0;
}
update() {
if (this.y != 60) this.y++;
if (this.y > 0) {
let txt = (String.fromCharCode(parseInt('26A1', 16))+" ").repeat(this.lives);
this.ctx.font = "30px Consolas";
this.ctx.fillStyle = 'Green';
this.ctx.fillText(txt, this.x, this.y);
}
}
}