diff --git a/Engine/src/states/Game.ts b/Engine/src/states/Game.ts index 7f5824d..bf77fe4 100644 --- a/Engine/src/states/Game.ts +++ b/Engine/src/states/Game.ts @@ -15,6 +15,7 @@ import { Action, adjustAction } from "../live/Action" import { WorldContext } from "../live/World" import { animals } from "../data/animals" import { GibletEntity } from "../live/GibletEntity" +import { bodyTextStyle, buttonBlurStyle, buttonHoverStyle } from "../styles" export interface PIXIMissingColorMatrix extends PIXI.Filter { night(intensity: number, multiply: boolean): void @@ -39,9 +40,76 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment let modeTimer = 0 let nightTime = 30 * 1000 let dayTime = 30 * 1000 + let daysSurvived = 0 let lastTime: number = performance.now() let player: AnimalEntity + // Game Over screenie + let gameOverShown = false + let gameOverPending = false + let gameOverScreen = new PIXI.Container() + let gameOverBackground = PIXI.Sprite.from(PIXI.Texture.WHITE) + gameOverBackground.tint = 0x111111 + gameOverBackground.alpha = 0.75 + + let gameOverTitle = new PIXI.Text('You have succumbed...', bodyTextStyle()) + let gameOverKills = new PIXI.Text('Hunted: ', bodyTextStyle()) + let gameOverKiller = new PIXI.Text('Slain By: ', bodyTextStyle()) + let gameOverDays = new PIXI.Text('You survived', bodyTextStyle()) + let returnToMain = new PIXI.Text('Return home...', buttonBlurStyle()) + returnToMain.interactive = true + returnToMain.on('pointerup', () => { + ctx.pop() + }) + returnToMain.on('pointerover', () => { + returnToMain.style = buttonHoverStyle() + }) + returnToMain.on('pointerout', () => { + returnToMain.style = buttonBlurStyle() + }) + + gameOverScreen.addChild(gameOverBackground) + gameOverScreen.addChild(gameOverTitle) + gameOverScreen.addChild(gameOverKills) + gameOverScreen.addChild(gameOverKiller) + gameOverScreen.addChild(gameOverDays) + gameOverScreen.addChild(returnToMain) + + let updateGameOver = () => { + gameOverScreen.width = ctx.app.view.width - ctx.app.view.width / 4 + gameOverScreen.height = ctx.app.view.height - ctx.app.view.height / 4 + gameOverScreen.x = ctx.app.view.width / 2 - gameOverScreen.width / 2 + gameOverScreen.y = ctx.app.view.height / 2 - gameOverScreen.height / 2 + let xPos = 0 + let yPos = 32 + + gameOverBackground.width = gameOverScreen.width + gameOverBackground.height = gameOverScreen.height + + gameOverTitle.x = gameOverScreen.width / 2 - gameOverTitle.width / 2 + gameOverTitle.y = yPos + yPos += gameOverTitle.height + 32 + + gameOverKiller.text = 'Slain By: ' + player.killer?.def.name + gameOverKiller.x = gameOverScreen.width / 2 - gameOverKiller.width / 2 + gameOverKiller.y = yPos + yPos += gameOverKiller.height + 32 + + gameOverKills.text = 'Hunted: ' + player.kills + gameOverKills.x = gameOverScreen.width / 2 - gameOverKills.width / 2 + gameOverKills.y = yPos + yPos += gameOverKills.height + 32 + + gameOverDays.text = 'You survived ' + daysSurvived + ' days.' + gameOverDays.x = gameOverScreen.width / 2 - gameOverDays.width /2 + gameOverDays.y = yPos + yPos += gameOverDays.height + 32 + + returnToMain.x = gameOverScreen.width / 2 - returnToMain.width / 2 + returnToMain.y = yPos + yPos += returnToMain.height + 32 + } + // let clockCoverSprite = new SpriteInstance('ui.clock.cover.default.0') let clockMoonSprite = new SpriteInstance('ui.clock.moon.default.0') @@ -239,6 +307,7 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment player.isPlayer = true addEntity(player, 'objects', x, y) player.turn() + player.dead = true } // Add fake others @@ -285,6 +354,20 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment elapsed += delta modeTimer += realDelta + if (player.dead) { + if (!gameOverPending && !gameOverShown) { + gameOverPending = true + setTimeout(() => { + gameOverPending = false + gameOverShown = true + realRootContainer.addChild(gameOverScreen) + updateGameOver() + }, 3000) + } else if (gameOverShown) { + updateGameOver() + } + } + // Update clock { //clockContainer.width = ctx.app.renderer.width @@ -589,6 +672,7 @@ export function GameState(ctx: ContextI, selectedAnimal: string, selectedSegment for (let l of layers) { l.colorMatrix.reset() } + daysSurvived++ } for (let e of entities) { if (e instanceof AnimalEntity) {