Compare commits
3 commits
4ffe8a162b
...
059d455b24
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
059d455b24 | ||
|
|
dd8131e55a | ||
|
|
cedafd5e10 |
11 changed files with 142 additions and 18 deletions
12
notes.md
12
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
|
||||
|
|
@ -32,3 +36,11 @@ mash le clavier pour écrire des message aux participants
|
|||
- moins de temps
|
||||
- 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
|
||||
|
||||
|
||||
#### jsp
|
||||
jeu de rythme
|
||||
|
||||
|
||||
#### livraison
|
||||
les caisses de club mate tombent du ciel et il faut les attraper
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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._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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,10 +83,6 @@ export class CleanupHS extends TimedGame {
|
|||
}
|
||||
}
|
||||
|
||||
end() {
|
||||
super.end();
|
||||
}
|
||||
|
||||
_onItemDrop(item) {
|
||||
console.log("dropped", item.type);
|
||||
|
||||
|
|
|
|||
47
src/games/delivery.js
Normal file
47
src/games/delivery.js
Normal 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() {}
|
||||
}
|
||||
|
|
@ -20,7 +20,7 @@ export class TimedGame extends Game {
|
|||
super.start();
|
||||
this.timerDisplay.start();
|
||||
this._timeoutStartTime = Date.now();
|
||||
this._timeoutId = setInterval(() => {
|
||||
this._timeoutId = setTimeout(() => {
|
||||
this._onTimeout();
|
||||
}, this.baseTimeout);
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ export class TimedGame extends Game {
|
|||
this._onTimeout();
|
||||
} else {
|
||||
this._timeoutStartTime = Date.now();
|
||||
this._timeoutId = setInterval(() => {
|
||||
this._timeoutId = setTimeout(() => {
|
||||
this._onTimeout();
|
||||
}, this.currentTimeout);
|
||||
}
|
||||
|
|
@ -46,17 +46,22 @@ export class TimedGame extends Game {
|
|||
clearTimeout(this._timeoutId);
|
||||
this._timeoutId = undefined;
|
||||
this._timeoutStartTime = undefined;
|
||||
this.currentTimeout = this.baseTimeout;
|
||||
}
|
||||
|
||||
end(status) {
|
||||
super.end(status);
|
||||
this.timerDisplay.stop();
|
||||
clearTimeout(this._timeoutId);
|
||||
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._timeoutId = undefined;
|
||||
}
|
||||
|
||||
getRemainingTime() {
|
||||
if (this._timeoutStartTime && this.currentTimeout) {
|
||||
return this.currentTimeout - (Date.now() - this._timeoutStartTime);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
_onTimeout() {
|
||||
|
|
|
|||
|
|
@ -102,14 +102,12 @@ function switchToGame(gameContainer, newGame) {
|
|||
const manager = new GameManager(app, gameContainter);
|
||||
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();
|
||||
})();
|
||||
|
|
|
|||
15
src/ui/announceNextGameDisplay.js
Normal file
15
src/ui/announceNextGameDisplay.js
Normal 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",
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
23
src/ui/gameResultDisplay.js
Normal file
23
src/ui/gameResultDisplay.js
Normal 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 !";
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1,3 @@
|
|||
export { TimerDisplay } from "./timerDisplay";
|
||||
export { AnnounceNextGameDisplay } from "./announceNextGameDisplay";
|
||||
export { GameResultDisplay } from "./gameResultDisplay";
|
||||
|
|
|
|||
3
todo.md
3
todo.md
|
|
@ -1,4 +1 @@
|
|||
- game cycle -> launch a game handle end and launch next
|
||||
|
||||
- diplay info
|
||||
- game result
|
||||
|
|
|
|||
Loading…
Reference in a new issue