From 7a494b148dd03d6346a63641fc479015e7450a26 Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Wed, 1 Jun 2022 18:53:40 +0200 Subject: Startscreen adn sfx --- src/game.ts | 83 ++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 31 deletions(-) (limited to 'src/game.ts') 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 > 2200) - console.log(bg.delta); + 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); } -- cgit v1.3.1