From 059d455b249b72e2cef55d06698e16bf0c67c9b2 Mon Sep 17 00:00:00 2001 From: lagaffe <> Date: Tue, 30 Jun 2026 17:46:15 +0200 Subject: [PATCH] add infos between games --- notes.md | 6 +++- src/common/helpers.js | 6 ++++ src/gameManager.js | 27 ++++++++++++++++-- src/games/delivery.js | 47 +++++++++++++++++++++++++++++++ src/main.js | 6 ++-- src/ui/announceNextGameDisplay.js | 15 ++++++++++ src/ui/gameResultDisplay.js | 23 +++++++++++++++ src/ui/index.js | 2 ++ todo.md | 1 - 9 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 src/games/delivery.js create mode 100644 src/ui/announceNextGameDisplay.js create mode 100644 src/ui/gameResultDisplay.js diff --git a/notes.md b/notes.md index 8ec80b1..3dfa46a 100644 --- a/notes.md +++ b/notes.md @@ -3,6 +3,10 @@ - fade out au bout d'un certain temps - fade out dès que le score du jeu bouge +### about timed game and timer display + +timed game uses setInterval for timeout, so it is possible that the timeout fires a little bit after it should so the timer display goes in the negatives, the alternative would be to use a ticker and check each frame that the timer has not reached timeout -> performance impact (maybe) + ### mini game ideas #### fridge @@ -39,4 +43,4 @@ jeu de rythme #### livraison -les caisses de club mate tombent du ciel et il faut le attraper +les caisses de club mate tombent du ciel et il faut les attraper diff --git a/src/common/helpers.js b/src/common/helpers.js index 6dc9732..08c040a 100644 --- a/src/common/helpers.js +++ b/src/common/helpers.js @@ -26,3 +26,9 @@ export function getIntersection(a, b, out = new Rectangle()) { export function getRandomInt(max) { return Math.floor(Math.random() * max); } + +export function scaleSpriteKeepRatio(sprite, newWidth) { + const ratio = newWidth / sprite.width; + sprite.height = sprite.height * ratio; + sprite.width = newWidth; +} diff --git a/src/gameManager.js b/src/gameManager.js index 7487416..469b6aa 100644 --- a/src/gameManager.js +++ b/src/gameManager.js @@ -1,5 +1,6 @@ import { getRandomInt } from "./common"; import { Fridge, Opinator, SmartMonday, CleanupHS } from "./games"; +import { GameResultDisplay, AnnounceNextGameDisplay } from "./ui"; /** * manages the game lifecyle, starting a game, handeling game end and starting a new one @@ -10,6 +11,8 @@ export class GameManager { this._app = app; this._gameContainer = gameContainter; this._difficulty = 1; + this.gameResultTime = 2500; // milliseconds + this.nextGameAnnounceTime = 2000; // ... const opinator = new Opinator(app.ticker); const fridge = new Fridge(app.ticker); @@ -28,6 +31,15 @@ export class GameManager { this._unPlayedGamesIds.push(i); } this._currentGame = undefined; + + // in between game display + this._resultScreen = new GameResultDisplay(); + this._nextGameAnnounceScreen = new AnnounceNextGameDisplay(); + + this._gameContainer.addChild(this._resultScreen.node); + this._gameContainer.addChild(this._nextGameAnnounceScreen.node); + this._resultScreen.node.visible = false; + this._nextGameAnnounceScreen.node.visible = false; } start() { @@ -59,7 +71,18 @@ export class GameManager { _onGameEnd(status) { console.log("game end", status); this._gameContainer.removeChild(this._currentGame.gameContainer); - console.log("next !"); - this.nextGame(); + + this._resultScreen.setStatus(status); + this._resultScreen.node.visible = true; + setTimeout(() => { + this._resultScreen.node.visible = false; + this._nextGameAnnounceScreen.node.visible = true; + }, this.gameResultTime); + + setTimeout(() => { + this._nextGameAnnounceScreen.node.visible = false; + console.log("starting next game"); + this.nextGame(); + }, this.gameResultTime + this.nextGameAnnounceTime); } } diff --git a/src/games/delivery.js b/src/games/delivery.js new file mode 100644 index 0000000..7c070e2 --- /dev/null +++ b/src/games/delivery.js @@ -0,0 +1,47 @@ +import { Application, Assets, Container, Sprite, Rectangle } from "pixi.js"; +import { Game } from "./game"; +import { KeyBoardListener } from "../common"; + +export class Delivery extends Game { + constructor() { + super(); + + this._gameDesc.text = "Récupère la livraison de club maté !!"; + this._instruction.text = "Utilise les flèches pour te déplacer"; + + this._spawnRate = 0.5 * this._difficulty * 0.5; // how many crates spawn each second + this._fallSpeed = 1 * this._difficulty * 0.3; + + this._crates = []; + + this._spawnHandle = undefined; + + this.gameContainer.layout = { width: "100%", height: "100%" }; + } + + reset() { + super.reset(); + + this._crates = []; + } + + start() { + this._spawnHandle = setTimeout(() => { + this._addCrate(); + }, 1000 / this._spawnRate); + } + + end(status) { + super.end(status); + clearTimeout(this._spawnHandle); + KeyBoardListener.offKeyDown(this._keyEventHandle); + } + + _addCrate() { + const newCrate = Sprite.from("mate_caisse"); + this.newCrate.width = 20; + this.newCrate.height = 20; + } + + _animateCrates() {} +} diff --git a/src/main.js b/src/main.js index b8a7596..cc94da2 100644 --- a/src/main.js +++ b/src/main.js @@ -100,14 +100,14 @@ function switchToGame(gameContainer, newGame) { root.addChild(gameContainter); const manager = new GameManager(app, gameContainter); - //manager.start(); + manager.start(); const opinator = new Opinator(app.ticker); const fridge = new Fridge(app.ticker); const smartMonday = new SmartMonday(app.ticker); const cleanupHS = new CleanupHS(root.width, root.height, app.ticker); let currentGame = cleanupHS; - gameContainter.addChild(currentGame.gameContainer); + //gameContainter.addChild(currentGame.gameContainer); - currentGame.start(); + //currentGame.start(); })(); diff --git a/src/ui/announceNextGameDisplay.js b/src/ui/announceNextGameDisplay.js new file mode 100644 index 0000000..8bee9cb --- /dev/null +++ b/src/ui/announceNextGameDisplay.js @@ -0,0 +1,15 @@ +import { Text } from "pixi.js"; + +export class AnnounceNextGameDisplay { + constructor() { + this.node = new Text({ + text: "Next !", + style: { + fontFamily: "Arial", + fontSize: 24, + fill: 0xff1010, + align: "center", + }, + }); + } +} diff --git a/src/ui/gameResultDisplay.js b/src/ui/gameResultDisplay.js new file mode 100644 index 0000000..d130506 --- /dev/null +++ b/src/ui/gameResultDisplay.js @@ -0,0 +1,23 @@ +import { Text } from "pixi.js"; + +export class GameResultDisplay { + constructor() { + this.status = false; + + this.node = new Text({ + text: "default text", + style: { + fontFamily: "Arial", + fontSize: 24, + fill: 0xff1010, + align: "center", + }, + }); + } + + // gameStatus: bool indicating if the game was won or not + setStatus(gameStatus) { + // potentially here select among end game animations and shit + this.node.text = gameStatus ? "You won !" : "You lost !"; + } +} diff --git a/src/ui/index.js b/src/ui/index.js index 3245e3c..803e2cd 100644 --- a/src/ui/index.js +++ b/src/ui/index.js @@ -1 +1,3 @@ export { TimerDisplay } from "./timerDisplay"; +export { AnnounceNextGameDisplay } from "./announceNextGameDisplay"; +export { GameResultDisplay } from "./gameResultDisplay"; diff --git a/todo.md b/todo.md index 474af3a..c6c6644 100644 --- a/todo.md +++ b/todo.md @@ -1,2 +1 @@ - diplay info - - game result