diff options
| -rw-r--r-- | src/Images.ts | 8 | ||||
| -rw-r--r-- | src/Storage.ts | 6 | ||||
| -rw-r--r-- | src/audios/1942-enemy-die.mp3 | bin | 0 -> 7447 bytes | |||
| -rw-r--r-- | src/audios/1942-fire.mp3 | bin | 0 -> 13015 bytes | |||
| -rw-r--r-- | src/audios/1942-main-theme.mp3 | bin | 0 -> 4267824 bytes | |||
| -rw-r--r-- | src/audios/1942-name.mp3 | bin | 0 -> 4619832 bytes | |||
| -rw-r--r-- | src/audios/1942-player-death.mp3 | bin | 0 -> 11335 bytes | |||
| -rw-r--r-- | src/audios/1942-start-level.mp3 | bin | 0 -> 117991 bytes | |||
| -rw-r--r-- | src/audios/1942-win.mp3 | bin | 0 -> 692352 bytes | |||
| -rw-r--r-- | src/drawables/Startscreen.ts | 74 | ||||
| -rw-r--r-- | src/drawables/TopBar.ts | 7 | ||||
| -rw-r--r-- | src/game.ts | 81 | ||||
| -rw-r--r-- | src/imgs/font/blue/..png | bin | 0 -> 1337 bytes | |||
| -rw-r--r-- | src/imgs/font/green/..png | bin | 0 -> 1337 bytes | |||
| -rw-r--r-- | src/imgs/font/purple/..png | bin | 0 -> 1337 bytes | |||
| -rw-r--r-- | src/imgs/font/red/..png | bin | 0 -> 1337 bytes | |||
| -rw-r--r-- | src/main.ts | 2 |
17 files changed, 131 insertions, 47 deletions
diff --git a/src/Images.ts b/src/Images.ts index bf91bb3..eeda006 100644 --- a/src/Images.ts +++ b/src/Images.ts @@ -89,15 +89,19 @@ export default async function loadAllImages() { if (["empty", "font"].includes(key)) continue; IMGS[key as keyof typeof IMGS] = await asyncImageLoader("/src/imgs/" + toKebabCase(key) + ".png") as any } - for (const color of ['yellow', 'white']) { + for (const color of ['yellow', 'white', 'blue', 'red', 'green', 'purple']) { // for (const color of ['white']) { for (const char of allChars) { (((IMGS.font as any)[color] as any)[char]) = await asyncImageLoader("/src/imgs/font/" + color + "/" + encodeURIComponent(char) + ".png") as any } } IMGS.font[' '] = await asyncImageLoader("/src/imgs/font/ .png") - IMGS.font.yellow[' '] = await asyncImageLoader("/src/imgs/font/ .png") IMGS.font.white[' '] = await asyncImageLoader("/src/imgs/font/ .png") + IMGS.font.yellow[' '] = await asyncImageLoader("/src/imgs/font/ .png") + IMGS.font.blue[' '] = await asyncImageLoader("/src/imgs/font/ .png") + IMGS.font.red[' '] = await asyncImageLoader("/src/imgs/font/ .png") + IMGS.font.green[' '] = await asyncImageLoader("/src/imgs/font/ .png") + IMGS.font.purple[' '] = await asyncImageLoader("/src/imgs/font/ .png") // Only numbers for (const c of allChars.filter(ch => !alphabet.includes(ch))) { IMGS.font.small.white[c] = await asyncImageLoader("/src/imgs/font/small/white/" + c + ".png"); diff --git a/src/Storage.ts b/src/Storage.ts index 632ce50..2307846 100644 --- a/src/Storage.ts +++ b/src/Storage.ts @@ -4,7 +4,7 @@ export interface Score { score: string; world: string; } -export type Storage = Score[] +export type Storage = Score[]; export function getStorage(): Storage { const s = JSON.parse(localStorage.getItem("storage") ?? "{}"); const storage = [ @@ -23,6 +23,10 @@ export function setStorage(s: Storage) { localStorage.setItem("storage", JSON.stringify(s)) } +export function getHighscore() { + return getStorage()[0].score; +} + export function getPlace(s: number): string { const storage = getStorage(); let place = 7 diff --git a/src/audios/1942-enemy-die.mp3 b/src/audios/1942-enemy-die.mp3 Binary files differnew file mode 100644 index 0000000..cfd1afd --- /dev/null +++ b/src/audios/1942-enemy-die.mp3 diff --git a/src/audios/1942-fire.mp3 b/src/audios/1942-fire.mp3 Binary files differnew file mode 100644 index 0000000..a010815 --- /dev/null +++ b/src/audios/1942-fire.mp3 diff --git a/src/audios/1942-main-theme.mp3 b/src/audios/1942-main-theme.mp3 Binary files differnew file mode 100644 index 0000000..fcef295 --- /dev/null +++ b/src/audios/1942-main-theme.mp3 diff --git a/src/audios/1942-name.mp3 b/src/audios/1942-name.mp3 Binary files differnew file mode 100644 index 0000000..197f2f6 --- /dev/null +++ b/src/audios/1942-name.mp3 diff --git a/src/audios/1942-player-death.mp3 b/src/audios/1942-player-death.mp3 Binary files differnew file mode 100644 index 0000000..30052df --- /dev/null +++ b/src/audios/1942-player-death.mp3 diff --git a/src/audios/1942-start-level.mp3 b/src/audios/1942-start-level.mp3 Binary files differnew file mode 100644 index 0000000..15b85ac --- /dev/null +++ b/src/audios/1942-start-level.mp3 diff --git a/src/audios/1942-win.mp3 b/src/audios/1942-win.mp3 Binary files differnew file mode 100644 index 0000000..b381ad9 --- /dev/null +++ b/src/audios/1942-win.mp3 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; diff --git a/src/game.ts b/src/game.ts index 3fdfa8c..7991d94 100644 --- a/src/game.ts +++ b/src/game.ts @@ -16,12 +16,13 @@ import Green1 from "./enemies/Green1"; import Green2 from "./enemies/Green2"; import Strange from "./enemies/Strange"; import White from "./enemies/White"; -// import Startscreen from "./drawables/Startscreen"; +import Startscreen from "./drawables/Startscreen"; +import { getHighscore } from "./Storage"; let p = new Player() -let pLifes = 1; +let pLifes = 3; let score = 25004; -let highscore = 0; +let highscore = getHighscore(); let rolls = 3; let bullets = [] as Bullet[] const playerBullets = () => bullets.filter(b => b.players) @@ -31,6 +32,7 @@ let enemies = [] as Enemy[] let animations = [] as Anime[] let intervalId = 0; let rafId = 0; +let menu = true const bg = new Background() const tb = new TopBar() const hg = new Highscore() @@ -56,6 +58,11 @@ export function cpuLoop() { // ss.move() // newTimeout() // return + if (menu) { + cpuMenu() + newTimeout() + return + } if (hg.show) { hg.move(); tb.setData(score, pLifes, rolls, highscore) @@ -120,6 +127,10 @@ export function gpuLoop() { clearCtx() + if (menu) { + gpuMenu() + return + } if (hg.show) { hg.drawHg(bg, score) tb.draw() @@ -165,35 +176,45 @@ export async function drawRestartScreen() { await sleep(2000) } +const startscreen = new Startscreen() +tb.setData(score, pLifes, rolls, highscore) +function cpuMenu() { + startscreen.move() +} +function gpuMenu() { + tb.draw() + startscreen.draw() +} + const newTimeout = (f = cpuLoop) => { clearTimeout(intervalId); intervalId = setTimeout(f, 1000 / keys.fps) } function spawnEnemies() { - if(bg.delta === 180) enemies.push(new Straight(80, 0)); - if(bg.delta === 180 + 20) enemies.push(new Straight(110, 0)); - if(bg.delta === 180 + 20 + 30) enemies.push(new Straight(160, 0)); - if(bg.delta === 180 + 20 + 30 + 25) enemies.push(new Straight(210, 0)); - if(bg.delta === 180 + 20 + 30 + 25 + 80) enemies.push(new Straight(130, 0)); - if(bg.delta === 180 + 20 + 30 + 25 + 80 + 50) enemies.push(new Straight(90, 0)); - if(bg.delta === 180 + 20 + 30 + 25 + 80 + 50 + 32) enemies.push(new Straight(220, 0)); - if(bg.delta === 630) enemies.push(new BigCircle(16, TOPBAR_HEIGHT - 40)) - if(bg.delta === 630 + 38) enemies.push(new Straight(90, 0), new Straight(266, 0)) - if(bg.delta === 630 + 38 + 38) enemies.push(new Straight(140, 0)) - if(bg.delta === 630 + 38 + 38 + 70) enemies.push(new Straight(30, 0)) - if(bg.delta === 630 + 38 + 38 + 70 + 30) enemies.push(new Straight(266, 0)) - if(bg.delta === 1016 + 21 * 0) enemies.push(new Red1(-20, 52)) - if(bg.delta === 1016 + 21 * 1) enemies.push(new Red1(-20, 52)) - if(bg.delta === 1016 + 21 * 2) enemies.push(new Red1(-20, 52)) - if(bg.delta === 1016 + 21 * 3) enemies.push(new Red1(-20, 52)) - if(bg.delta === 1016 + 21 * 4) enemies.push(new Red1(-20, 52)) - if(bg.delta === 1120) enemies.push(new Green1(110, canvas.height, true), new Green1(170, canvas.height, false)) - if(bg.delta === 1498) enemies.push(new Strange(160, canvas.height)) - if(bg.delta === 1498 + 45) enemies.push(new Red2(100, 0, true), new Red2(180, 0, false)) - if(bg.delta === 1498 + 45 + 90) enemies.push(new Green2(100, 0, true), new Green2(180, 0, false)) - if(bg.delta === 2000 + 85 * 0) enemies.push(new White(60, 0, true), new White(230, 0, false)) - if(bg.delta === 2000 + 85 * 1) enemies.push(new White(60, 0, true), new White(230, 0, false)) - if(bg.delta === 2000 + 85 * 2) enemies.push(new White(60, 0, true), new White(230, 0, false)) - if(bg.delta === 2000 + 85 * 3) enemies.push(new White(60, 0, true)) + if (bg.delta === 180) enemies.push(new Straight(80, 0)); + if (bg.delta === 180 + 20) enemies.push(new Straight(110, 0)); + if (bg.delta === 180 + 20 + 30) enemies.push(new Straight(160, 0)); + if (bg.delta === 180 + 20 + 30 + 25) enemies.push(new Straight(210, 0)); + if (bg.delta === 180 + 20 + 30 + 25 + 80) enemies.push(new Straight(130, 0)); + if (bg.delta === 180 + 20 + 30 + 25 + 80 + 50) enemies.push(new Straight(90, 0)); + if (bg.delta === 180 + 20 + 30 + 25 + 80 + 50 + 32) enemies.push(new Straight(220, 0)); + if (bg.delta === 630) enemies.push(new BigCircle(16, TOPBAR_HEIGHT - 40)) + if (bg.delta === 630 + 38) enemies.push(new Straight(90, 0), new Straight(266, 0)) + if (bg.delta === 630 + 38 + 38) enemies.push(new Straight(140, 0)) + if (bg.delta === 630 + 38 + 38 + 70) enemies.push(new Straight(30, 0)) + if (bg.delta === 630 + 38 + 38 + 70 + 30) enemies.push(new Straight(266, 0)) + if (bg.delta === 1016 + 21 * 0) enemies.push(new Red1(-20, 52)) + if (bg.delta === 1016 + 21 * 1) enemies.push(new Red1(-20, 52)) + if (bg.delta === 1016 + 21 * 2) enemies.push(new Red1(-20, 52)) + if (bg.delta === 1016 + 21 * 3) enemies.push(new Red1(-20, 52)) + if (bg.delta === 1016 + 21 * 4) enemies.push(new Red1(-20, 52)) + if (bg.delta === 1120) enemies.push(new Green1(110, canvas.height, true), new Green1(170, canvas.height, false)) + if (bg.delta === 1498) enemies.push(new Strange(160, canvas.height)) + if (bg.delta === 1498 + 45) enemies.push(new Red2(100, 0, true), new Red2(180, 0, false)) + if (bg.delta === 1498 + 45 + 90) enemies.push(new Green2(100, 0, true), new Green2(180, 0, false)) + if (bg.delta === 2000 + 85 * 0) enemies.push(new White(60, 0, true), new White(230, 0, false)) + if (bg.delta === 2000 + 85 * 1) enemies.push(new White(60, 0, true), new White(230, 0, false)) + if (bg.delta === 2000 + 85 * 2) enemies.push(new White(60, 0, true), new White(230, 0, false)) + if (bg.delta === 2000 + 85 * 3) enemies.push(new White(60, 0, true)) - if(bg.delta > 2200) - console.log(bg.delta); + if (bg.delta > 2200) + console.log(bg.delta); } diff --git a/src/imgs/font/blue/..png b/src/imgs/font/blue/..png Binary files differnew file mode 100644 index 0000000..46fea24 --- /dev/null +++ b/src/imgs/font/blue/..png diff --git a/src/imgs/font/green/..png b/src/imgs/font/green/..png Binary files differnew file mode 100644 index 0000000..71a3ebd --- /dev/null +++ b/src/imgs/font/green/..png diff --git a/src/imgs/font/purple/..png b/src/imgs/font/purple/..png Binary files differnew file mode 100644 index 0000000..c3eb74e --- /dev/null +++ b/src/imgs/font/purple/..png diff --git a/src/imgs/font/red/..png b/src/imgs/font/red/..png Binary files differnew file mode 100644 index 0000000..41f4335 --- /dev/null +++ b/src/imgs/font/red/..png diff --git a/src/main.ts b/src/main.ts index 9f462e5..91e23ec 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,9 +2,11 @@ import "./style.css"; import "./Events"; import loadAllImages from "./Images"; import { start } from "./game"; +import { IMGS } from "./Images" async function init() { await loadAllImages(); + console.log(IMGS.startScreen0); start(); } document.body.onload = init; |
