diff options
Diffstat (limited to 'src/drawables')
| -rw-r--r-- | src/drawables/Startscreen.ts | 74 | ||||
| -rw-r--r-- | src/drawables/TopBar.ts | 7 |
2 files changed, 67 insertions, 14 deletions
diff --git a/src/drawables/Startscreen.ts b/src/drawables/Startscreen.ts index ea8dc40..91f7405 100644 --- a/src/drawables/Startscreen.ts +++ b/src/drawables/Startscreen.ts @@ -1,38 +1,88 @@ -import { TOPBAR_HEIGHT } from "../consts" +import { ctx, TOPBAR_HEIGHT } from "../consts" import Drawable from "../Drawable" import { IMGS } from "../Images" +import { getStorage, Storage } from "../Storage" export default class Startscreen extends Drawable { sprite = IMGS.startScreen0 si = 0 - i = 0 + i = 0 j = 0 color = "white" colors = ["white", "yellow", "blue", "purple", "red"] ci = 0 + cdx = 16; + cdy = 26; + storage: Storage | null = null + show0 = true constructor() { super(0, TOPBAR_HEIGHT) } + draw() { + //@ts-expect-error + if (this.sprite.width == null) this.sprite = IMGS["startScreen" + this.si] + if (this.storage == null) this.storage = getStorage() + ctx.drawImage(this.sprite, this.x, this.y) + const chars = [] as string[][] + for (const [i, score] of this.storage.entries()) { + let place = "" + if (i === 0) place = "top"; + else if (i === 1) place = "2nd"; + else if (i === 2) place = "3rd"; + else place = i + "th"; + + chars.push([...place.split(''), ' ', ...score.score.padStart(7, '0').split(''), ' ', ...score.name, ' ', ...score.world.split('')]) + } + if (this.si !== 0 && this.show0 !== true) { + let x = 17, y = 40; + for (const char of chars) { + x = 17 + for (const c of char) { + try { + //@ts-expect-error + ctx.drawImage(IMGS.font[this.color][c], x, y) + } catch (e) { debugger } + + x += this.cdx + } + y += this.cdy + } + } + } move() { - if(this.si === 0) { - if(this.i++ === 199) { this.sprite = IMGS.startScreen1; this.i = 0; this.si++ } - // if(this.i++ === 19) { this.sprite = IMGS.startScreen1; this.i = 0; this.si++ } + if (this.si === 0 || this.show0) { + this.sprite = IMGS.startScreen0; + // if (this.i++ === 19) { + if (this.i++ === 199) { + this.i = 0; + // debugger + if (!this.show0) { + this.si++ + } else { + this.show0 = !this.show0 + } + } } else { - // if(this.i++ === 2) { - if(this.i++ === 9) { + //@ts-expect-error + this.sprite = IMGS["startScreen" + this.si]; + console.log("startScreen" + this.si); + + // if (this.i++ === 2) { + if (this.i++ === 9) { this.ci++; - if(this.ci >= this.colors.length) { - if(this.j++ === 9) { - // if(this.j++ === 2) { + if (this.ci >= this.colors.length) { + if (this.j++ === 9) { + // if (this.j++ === 2) { this.si++; - if(this.si > 4) this.si = 0 + this.show0 = true + if (this.si > 4) { this.si = 0; this.show0 = false; } //@ts-expect-error this.sprite = IMGS["startScreen" + this.si] this.j = 0 } - this.ci = 0; + this.ci = 0; } this.color = this.colors[this.ci] this.i = 0 diff --git a/src/drawables/TopBar.ts b/src/drawables/TopBar.ts index 8772050..d92db07 100644 --- a/src/drawables/TopBar.ts +++ b/src/drawables/TopBar.ts @@ -13,11 +13,14 @@ export class TopBar extends Drawable { constructor() { super(0, 0) } - setData(score: number, lives: number, rolls: number, highscore?: number) { + setData(score: number, lives: number, rolls: number, highscore?: number | string) { this.score = score this.lives = lives this.rolls = rolls - this.highscore = highscore ?? this.highscore + if (highscore) { + if (typeof highscore === "string") highscore = parseInt(highscore) + this.highscore = highscore + } } draw() { if (this.sprite.src == null) this.sprite = IMGS.topbar; |
