changed ball and bar for a sprite

This commit is contained in:
2021-11-16 22:01:43 +01:00
parent e0ebef2a27
commit bc3ef31728
17 changed files with 77 additions and 24 deletions

27
assets/js/Lives.js Normal file
View File

@ -0,0 +1,27 @@
class Lives {
constructor() {
this.reset();
}
reset() {
this.lives = 3;
this.y = 10;
}
lost() {
this.lives--;
return this.lives==0;
}
get() {
return this.lives;
}
update(ctx) {
if (this.y != 48) this.y++;
if (this.y > 0) {
let txt = (String.fromCharCode(parseInt('26A1', 16))+" ").repeat(this.lives);
ctx.font = "18px Consolas";
ctx.fillStyle = 'Green';
this.x = ctx.canvas.width - ctx.measureText(txt).width;
ctx.fillText(txt, this.x, this.y);
}
}
}