From c39e7ad54f7e369e62ba0e917c3b92e076699239 Mon Sep 17 00:00:00 2001 From: kts of kettek Date: Sun, 30 Jan 2022 15:49:05 -0800 Subject: [PATCH] Add proper difficulty progression --- Engine/src/states/Game.ts | 103 +++++++++++++++++++++----------------- 1 file changed, 56 insertions(+), 47 deletions(-) diff --git a/Engine/src/states/Game.ts b/Engine/src/states/Game.ts index c2d53aa..2c659bf 100644 --- a/Engine/src/states/Game.ts +++ b/Engine/src/states/Game.ts @@ -40,7 +40,7 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment let modeTimer = 0 let nightTime = 30 * 1000 let dayTime = 30 * 1000 - let daysSurvived = 0 + let daysSurvived = -1 let lastTime: number = performance.now() let player: AnimalEntity @@ -309,23 +309,7 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment player.turn() } - // Add fake others - // MOVE ME - for (let animal of ['turkey','nutria','deer','salamander','rabbit']) { - let count = 2 + Math.floor(Math.random() * 8) - for (let i = 0; i < count; i++) { - let spawn = getSpawnZone(animal) - if (!spawn) break - let bounds = spawn.bounds - let x = bounds[0] + Math.floor(Math.random() * bounds[2]) - let y = bounds[1] + Math.floor(Math.random() * bounds[3]) - - let entity = new AnimalEntity(animals[animal]) - - - addEntity(entity, 'objects', x, y) - } - } + progress() // Add clock @@ -365,32 +349,32 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment } else if (gameOverShown) { updateGameOver() } - } - - // Update clock - { - //clockContainer.width = ctx.app.renderer.width - let w = ctx.app.renderer.width - let h = ctx.app.renderer.height - clockContainer.x = w / 2 - clockCoverSprite.container.width - clockContainer.y = h - clockCoverSprite.container.height * 2 - 8 - if (isNight) { - clockMoonSprite.container.angle = 180 + modeTimer / nightTime * 180 - clockSunSprite.container.angle = modeTimer / nightTime * 180 - } else { - clockMoonSprite.container.angle = modeTimer / dayTime * 180 - clockSunSprite.container.angle = 180 + modeTimer / dayTime * 180 + } else { + // Update clock + { + //clockContainer.width = ctx.app.renderer.width + let w = ctx.app.renderer.width + let h = ctx.app.renderer.height + clockContainer.x = w / 2 - clockCoverSprite.container.width + clockContainer.y = h - clockCoverSprite.container.height * 2 - 8 + if (isNight) { + clockMoonSprite.container.angle = 180 + modeTimer / nightTime * 180 + clockSunSprite.container.angle = modeTimer / nightTime * 180 + } else { + clockMoonSprite.container.angle = modeTimer / dayTime * 180 + clockSunSprite.container.angle = 180 + modeTimer / dayTime * 180 + } + clockMoonSprite.container.angle -= 230 + clockSunSprite.container.angle -= 230 } - clockMoonSprite.container.angle -= 230 - clockSunSprite.container.angle -= 230 - } - if (isNight && modeTimer >= nightTime) { - modeTimer = 0 - nightfall(false) - } else if (!isNight && modeTimer >= dayTime) { - modeTimer = 0 - nightfall(true) + if (isNight && modeTimer >= nightTime) { + modeTimer = 0 + nightfall(false) + } else if (!isNight && modeTimer >= dayTime) { + modeTimer = 0 + nightfall(true) + } } // Run world sim. while (elapsed >= 1/6) { @@ -666,22 +650,47 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment l.colorMatrix.saturate(-0.75, true) //l.colorMatrix.hue(160, true) } + for (let e of entities) { + if (e instanceof AnimalEntity) { + e.turn() + } + } } else { playSong('GGJ-HappyMusic') for (let l of layers) { l.colorMatrix.reset() } - daysSurvived++ - } - for (let e of entities) { - if (e instanceof AnimalEntity) { - e.turn() + for (let e of entities) { + if (e instanceof AnimalEntity) { + e.turn() + } } + progress() } isNight = b } + let progress = () => { + daysSurvived++ + + for (let animal of ['turkey','nutria','deer','salamander','rabbit']) { + let count = 1 + Math.floor(Math.random() * daysSurvived) + for (let i = 0; i < count; i++) { + let spawn = getSpawnZone(animal) + if (!spawn) break + let bounds = spawn.bounds + let x = bounds[0] + Math.floor(Math.random() * bounds[2]) + let y = bounds[1] + Math.floor(Math.random() * bounds[3]) + + let entity = new AnimalEntity(animals[animal]) + + addEntity(entity, 'objects', x, y) + } + } + + } + nightfall(false) return {