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 | |
| parent | 344737031e5bbad5f24469aabf45be6535c893f3 (diff) | |
| download | 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.gz 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.zst 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.zip | |
All enemies movement
Diffstat (limited to 'src/drawables')
| -rw-r--r-- | src/drawables/Bullet.ts | 10 | ||||
| -rw-r--r-- | src/drawables/TopBar.ts | 26 |
2 files changed, 31 insertions, 5 deletions
diff --git a/src/drawables/Bullet.ts b/src/drawables/Bullet.ts index 68f55e8..a745a06 100644 --- a/src/drawables/Bullet.ts +++ b/src/drawables/Bullet.ts @@ -1,19 +1,21 @@ import { canvas } from "../consts"; -import Drawable from "../Drawable"; +import Drawable, { Rectangle } from "../Drawable"; export default class Bullet extends Drawable { static width = 2; static height = 5; static color = "black"; + width = 2; + height = 5; color = "black"; sprite = "black"; - squares = [this] + squares: Rectangle[] = [new Rectangle(this)] constructor(x: number, y: number, public xvel: number, public yvel: number, public players: boolean) { super(x, y); - this.width = Bullet.width; - this.height = Bullet.height; + // this.width = Bullet.width; + // this.height = Bullet.height; } move(): boolean { 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) + }); } } |
