add infos between games

This commit is contained in:
lagaffe 2026-06-30 17:46:15 +02:00
parent dd8131e55a
commit 059d455b24
9 changed files with 126 additions and 7 deletions

View file

@ -3,6 +3,10 @@
- fade out au bout d'un certain temps - fade out au bout d'un certain temps
- fade out dès que le score du jeu bouge - 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 ### mini game ideas
#### fridge #### fridge
@ -39,4 +43,4 @@ jeu de rythme
#### livraison #### 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

View file

@ -26,3 +26,9 @@ export function getIntersection(a, b, out = new Rectangle()) {
export function getRandomInt(max) { export function getRandomInt(max) {
return Math.floor(Math.random() * 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;
}

View file

@ -1,5 +1,6 @@
import { getRandomInt } from "./common"; import { getRandomInt } from "./common";
import { Fridge, Opinator, SmartMonday, CleanupHS } from "./games"; 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 * 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._app = app;
this._gameContainer = gameContainter; this._gameContainer = gameContainter;
this._difficulty = 1; this._difficulty = 1;
this.gameResultTime = 2500; // milliseconds
this.nextGameAnnounceTime = 2000; // ...
const opinator = new Opinator(app.ticker); const opinator = new Opinator(app.ticker);
const fridge = new Fridge(app.ticker); const fridge = new Fridge(app.ticker);
@ -28,6 +31,15 @@ export class GameManager {
this._unPlayedGamesIds.push(i); this._unPlayedGamesIds.push(i);
} }
this._currentGame = undefined; 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() { start() {
@ -59,7 +71,18 @@ export class GameManager {
_onGameEnd(status) { _onGameEnd(status) {
console.log("game end", status); console.log("game end", status);
this._gameContainer.removeChild(this._currentGame.gameContainer); 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);
} }
} }

47
src/games/delivery.js Normal file
View file

@ -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() {}
}

View file

@ -100,14 +100,14 @@ function switchToGame(gameContainer, newGame) {
root.addChild(gameContainter); root.addChild(gameContainter);
const manager = new GameManager(app, gameContainter); const manager = new GameManager(app, gameContainter);
//manager.start(); manager.start();
const opinator = new Opinator(app.ticker); const opinator = new Opinator(app.ticker);
const fridge = new Fridge(app.ticker); const fridge = new Fridge(app.ticker);
const smartMonday = new SmartMonday(app.ticker); const smartMonday = new SmartMonday(app.ticker);
const cleanupHS = new CleanupHS(root.width, root.height, app.ticker); const cleanupHS = new CleanupHS(root.width, root.height, app.ticker);
let currentGame = cleanupHS; let currentGame = cleanupHS;
gameContainter.addChild(currentGame.gameContainer); //gameContainter.addChild(currentGame.gameContainer);
currentGame.start(); //currentGame.start();
})(); })();

View file

@ -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",
},
});
}
}

View file

@ -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 !";
}
}

View file

@ -1 +1,3 @@
export { TimerDisplay } from "./timerDisplay"; export { TimerDisplay } from "./timerDisplay";
export { AnnounceNextGameDisplay } from "./announceNextGameDisplay";
export { GameResultDisplay } from "./gameResultDisplay";

View file

@ -1,2 +1 @@
- diplay info - diplay info
- game result