Added the bricks (and improve the bouncing)
This commit is contained in:
20
Lives.js
20
Lives.js
@ -1,15 +1,10 @@
|
||||
class Lives {
|
||||
constructor(ctx) {
|
||||
this.ctx = ctx;
|
||||
constructor() {
|
||||
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;
|
||||
this.y = 10;
|
||||
}
|
||||
lost() {
|
||||
this.lives--;
|
||||
@ -18,14 +13,15 @@ class Lives {
|
||||
get() {
|
||||
return this.lives;
|
||||
}
|
||||
update() {
|
||||
if (this.y != 60) this.y++;
|
||||
update(ctx) {
|
||||
if (this.y != 48) 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);
|
||||
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