Bounce is now better
This commit is contained in:
28
Lives.js
Normal file
28
Lives.js
Normal file
@ -0,0 +1,28 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user