changed ball and bar for a sprite
This commit is contained in:
27
assets/js/Lives.js
Normal file
27
assets/js/Lives.js
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user