Compare commits

..

No commits in common. "059d455b249b72e2cef55d06698e16bf0c67c9b2" and "4ffe8a162b21a4119ca890f448d368821bcb746f" have entirely different histories.

11 changed files with 18 additions and 142 deletions

View file

@ -3,10 +3,6 @@
- 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
@ -36,11 +32,3 @@ mash le clavier pour écrire des message aux participants
- moins de temps - moins de temps
- ajout de plusieurs zone de text correspondant aux different participants - ajout de plusieurs zone de text correspondant aux different participants
- ajout d'un boutton "rappel" pour chaque participant avec un cool down à clique jusque à ce que tous les participants soit ok - ajout d'un boutton "rappel" pour chaque participant avec un cool down à clique jusque à ce que tous les participants soit ok
#### jsp
jeu de rythme
#### livraison
les caisses de club mate tombent du ciel et il faut les attraper

View file

@ -26,9 +26,3 @@ 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,6 +1,5 @@
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
@ -11,8 +10,6 @@ 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);
@ -31,15 +28,6 @@ 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() {
@ -71,18 +59,7 @@ 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._resultScreen.setStatus(status); this.nextGame();
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);
} }
} }

View file

@ -83,6 +83,10 @@ export class CleanupHS extends TimedGame {
} }
} }
end() {
super.end();
}
_onItemDrop(item) { _onItemDrop(item) {
console.log("dropped", item.type); console.log("dropped", item.type);

View file

@ -1,47 +0,0 @@
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

@ -20,7 +20,7 @@ export class TimedGame extends Game {
super.start(); super.start();
this.timerDisplay.start(); this.timerDisplay.start();
this._timeoutStartTime = Date.now(); this._timeoutStartTime = Date.now();
this._timeoutId = setTimeout(() => { this._timeoutId = setInterval(() => {
this._onTimeout(); this._onTimeout();
}, this.baseTimeout); }, this.baseTimeout);
} }
@ -34,7 +34,7 @@ export class TimedGame extends Game {
this._onTimeout(); this._onTimeout();
} else { } else {
this._timeoutStartTime = Date.now(); this._timeoutStartTime = Date.now();
this._timeoutId = setTimeout(() => { this._timeoutId = setInterval(() => {
this._onTimeout(); this._onTimeout();
}, this.currentTimeout); }, this.currentTimeout);
} }
@ -46,22 +46,17 @@ export class TimedGame extends Game {
clearTimeout(this._timeoutId); clearTimeout(this._timeoutId);
this._timeoutId = undefined; this._timeoutId = undefined;
this._timeoutStartTime = undefined; this._timeoutStartTime = undefined;
this.currentTimeout = this.baseTimeout;
} }
end(status) { end(status) {
clearTimeout(this._timeoutId); super.end(status);
super.end(this.getRemainingTime() > 0 ? status : false); // even if for some reason sub class tries to end after timeout, the game is still lost
this.timerDisplay.stop(); this.timerDisplay.stop();
clearTimeout(this._timeoutId);
this._timeoutId = undefined; this._timeoutId = undefined;
} }
getRemainingTime() { getRemainingTime() {
if (this._timeoutStartTime && this.currentTimeout) { return this.currentTimeout - (Date.now() - this._timeoutStartTime);
return this.currentTimeout - (Date.now() - this._timeoutStartTime);
} else {
return -1;
}
} }
_onTimeout() { _onTimeout() {

View file

@ -102,12 +102,14 @@ function switchToGame(gameContainer, newGame) {
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

@ -1,15 +0,0 @@
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

@ -1,23 +0,0 @@
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,3 +1 @@
export { TimerDisplay } from "./timerDisplay"; export { TimerDisplay } from "./timerDisplay";
export { AnnounceNextGameDisplay } from "./announceNextGameDisplay";
export { GameResultDisplay } from "./gameResultDisplay";

View file

@ -1 +1,4 @@
- game cycle -> launch a game handle end and launch next
- diplay info - diplay info
- game result