Added the bricks (and improve the bouncing)

This commit is contained in:
2021-11-14 23:49:49 +01:00
parent 0f4a403edb
commit 7493713529
12 changed files with 303 additions and 111 deletions

View File

@ -1,16 +1,25 @@
class GameOver {
constructor(ctx) {
this.ctx = ctx;
this.x = ctx.canvas.width;
this.y = ctx.canvas.height / 2 - 48;
constructor() {
this.w = 240;
this.h = 120;
this.cx = 360 / 2;
this.cy = 640 / 2;
this.x = this.cx - this.w/2;
this.y = this.cy - this.h/2;
}
update() {
this.centerText('GAME OVER', this.y, '48px', 'Consolas', 'Black');
update(ctx) {
ctx.fillStyle = "rgba(0, 0, 0, 0.5)";
ctx.fillRect(this.x, this.y, this.w, this.h);
this.centerText(ctx, 'GAME OVER', this.cy, '48px', 'Consolas', 'Black');
this.centerText(ctx, '(Press "N" to start)', this.cy + 48, '24px', 'Consolas', 'Black');
}
centerText(txt, y, s, f, c) {
this.ctx.font = s + ' ' + f;
this.ctx.fillStyle = 'Black';
let x = (this.ctx.canvas.width - this.ctx.measureText(txt).width) / 2;
this.ctx.fillText(txt, x, y);
centerText(ctx, txt, y, s, f, c) {
ctx.font = s + ' ' + f;
ctx.fillStyle = 'Black';
let x = (ctx.canvas.width - ctx.measureText(txt).width) / 2;
ctx.fillText(txt, x, y);
}
}