diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2022-05-31 18:11:09 +0200 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2022-05-31 18:11:09 +0200 |
| commit | 0010f2de57cfa97106432ea1849c1bb75d3d99a1 (patch) | |
| tree | 41e89ff13aacfc4dc1324a365302a0867e316dc9 /src/drawables/TopBar.ts | |
| parent | 344737031e5bbad5f24469aabf45be6535c893f3 (diff) | |
| download | 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.gz 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.zst 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.zip | |
All enemies movement
Diffstat (limited to 'src/drawables/TopBar.ts')
| -rw-r--r-- | src/drawables/TopBar.ts | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/drawables/TopBar.ts b/src/drawables/TopBar.ts index f021f77..8772050 100644 --- a/src/drawables/TopBar.ts +++ b/src/drawables/TopBar.ts @@ -6,12 +6,36 @@ export class TopBar extends Drawable { sprite = IMGS.topbar; width = canvas.width height = 24 + score = 0; + lives = 0; + rolls = 0; + highscore = 0; constructor() { super(0, 0) } + setData(score: number, lives: number, rolls: number, highscore?: number) { + this.score = score + this.lives = lives + this.rolls = rolls + this.highscore = highscore ?? this.highscore + } draw() { if (this.sprite.src == null) this.sprite = IMGS.topbar; - ctx.drawImage(this.sprite, 0, 0) + ctx.drawImage(this.sprite, 0, 0); + [...this.score.toString().padStart(7, '0')].forEach((char, i) => { + ctx.imageSmoothingEnabled = false + ctx.drawImage(IMGS.font.small.white[char], 24 + i * 8, 8) + }); + for (let i = 0; i < this.lives; i++) { + ctx.drawImage(IMGS.planeIcon, 112 + i * 8, 9) + } + for (let i = 0; i < this.rolls; i++) { + ctx.drawImage(IMGS.rollIcon, 177 + i * 8, 9) + } + [...this.highscore.toString().padStart(7, '0')].forEach((char, i) => { + ctx.imageSmoothingEnabled = false + ctx.drawImage(IMGS.font.small.white[char], 240 + i * 8, 8) + }); } } |
