Compare commits
No commits in common. "4ffe8a162b21a4119ca890f448d368821bcb746f" and "f5eee290fba311e2e16052d240ee4b9fc0b7cb57" have entirely different histories.
4ffe8a162b
...
f5eee290fb
12 changed files with 13 additions and 132 deletions
5
notes.md
5
notes.md
|
|
@ -1,8 +1,3 @@
|
|||
### divers
|
||||
- messages d'explication des jeux
|
||||
- fade out au bout d'un certain temps
|
||||
- fade out dès que le score du jeu bouge
|
||||
|
||||
### mini game ideas
|
||||
|
||||
#### fridge
|
||||
|
|
|
|||
|
|
@ -22,7 +22,3 @@ export function getIntersection(a, b, out = new Rectangle()) {
|
|||
|
||||
return out;
|
||||
}
|
||||
|
||||
export function getRandomInt(max) {
|
||||
return Math.floor(Math.random() * max);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
export { backgroundLayout } from "./layouts";
|
||||
export { makeDragable, makeUnDragable } from "./dragAndDrop";
|
||||
export { getIntersection } from "./helpers";
|
||||
export { getRandomInt } from "./helpers";
|
||||
export { KeyBoardListener } from "./keyBoardEvents";
|
||||
|
|
|
|||
|
|
@ -1,65 +0,0 @@
|
|||
import { getRandomInt } from "./common";
|
||||
import { Fridge, Opinator, SmartMonday, CleanupHS } from "./games";
|
||||
|
||||
/**
|
||||
* manages the game lifecyle, starting a game, handeling game end and starting a new one
|
||||
* lvl up etc.
|
||||
*/
|
||||
export class GameManager {
|
||||
constructor(app, gameContainter) {
|
||||
this._app = app;
|
||||
this._gameContainer = gameContainter;
|
||||
this._difficulty = 1;
|
||||
|
||||
const opinator = new Opinator(app.ticker);
|
||||
const fridge = new Fridge(app.ticker);
|
||||
const smartMonday = new SmartMonday(app.ticker);
|
||||
const cleanupHS = new CleanupHS(
|
||||
app.stage.width,
|
||||
app.stage.height,
|
||||
app.ticker,
|
||||
);
|
||||
|
||||
this._games = [opinator, fridge, smartMonday, cleanupHS];
|
||||
|
||||
this._playedGamesIds = [];
|
||||
this._unPlayedGamesIds = [];
|
||||
for (var i = 0; i < this._games.length; i++) {
|
||||
this._unPlayedGamesIds.push(i);
|
||||
}
|
||||
this._currentGame = undefined;
|
||||
}
|
||||
|
||||
start() {
|
||||
this.nextGame();
|
||||
}
|
||||
|
||||
nextGame() {
|
||||
const unplayedLength = this._unPlayedGamesIds.length;
|
||||
if (unplayedLength == 0) {
|
||||
console.log("level up");
|
||||
this._difficulty += 1;
|
||||
this._unPlayedGamesIds = this._playedGamesIds;
|
||||
this._playedGamesIds = [];
|
||||
}
|
||||
|
||||
const nextIndex = getRandomInt(unplayedLength);
|
||||
const nextId = this._unPlayedGamesIds[nextIndex];
|
||||
console.log(nextIndex, this._playedGamesIds, this._unPlayedGamesIds);
|
||||
this._playedGamesIds.push(this._unPlayedGamesIds[nextIndex]);
|
||||
this._unPlayedGamesIds.splice(nextIndex, 1);
|
||||
this._currentGame = this._games[nextId];
|
||||
this._currentGame.onEnd = (status) => {
|
||||
this._onGameEnd(status);
|
||||
};
|
||||
this._gameContainer.addChild(this._currentGame.gameContainer);
|
||||
this._currentGame.start();
|
||||
}
|
||||
|
||||
_onGameEnd(status) {
|
||||
console.log("game end", status);
|
||||
this._gameContainer.removeChild(this._currentGame.gameContainer);
|
||||
console.log("next !");
|
||||
this.nextGame();
|
||||
}
|
||||
}
|
||||
|
|
@ -35,9 +35,6 @@ export class CleanupHS extends TimedGame {
|
|||
this.trashLandingZone.addChild(trashcan);
|
||||
this.shelfLandingZone.addChild(shelf);
|
||||
|
||||
this._gameDesc.text = "Range le HS !!";
|
||||
this._instruction.text = "drag & drop les objets dans le bon contenant";
|
||||
|
||||
this.trashLandingZone.layout = { width: "20%", height: "100%" };
|
||||
this.shelfLandingZone.layout = {
|
||||
width: "20%",
|
||||
|
|
|
|||
|
|
@ -31,9 +31,6 @@ export class Fridge extends TimedGame {
|
|||
|
||||
this.timeout = this._bottleCount * 1500; // 1.5s per bottle
|
||||
|
||||
this._gameDesc.text = "Remplis le frigo !!";
|
||||
this._instruction.text = "drag & drop les club mate dans le frigo";
|
||||
|
||||
const fridgeContainer = new Container();
|
||||
fridgeContainer.layout = { width: "50%" };
|
||||
const fridge = Sprite.from("frigo");
|
||||
|
|
|
|||
|
|
@ -1,46 +1,17 @@
|
|||
import { Container, RenderLayer, Text } from "pixi.js";
|
||||
import { Container, RenderLayer } from "pixi.js";
|
||||
|
||||
export class Game {
|
||||
constructor() {
|
||||
this._difficulty = 1;
|
||||
this.won = false;
|
||||
this.onEnd = () => {};
|
||||
|
||||
this.gameContainer = new Container(); // main container, to add the game to a node, add this container as a child
|
||||
this.gameContainer.layout = true;
|
||||
|
||||
/*
|
||||
this._uiLayer = new Container();
|
||||
this._gameObjectsLayer = new Container();*/
|
||||
this._uiLayer = new RenderLayer();
|
||||
this._gameObjectsLayer = new RenderLayer();
|
||||
this._gameObjectsLayer.sortableChildren = true;
|
||||
|
||||
this._gameDesc = new Text({
|
||||
text: "",
|
||||
style: {
|
||||
fontFamily: "Arial",
|
||||
fontSize: 30,
|
||||
fill: 0x000000,
|
||||
align: "center",
|
||||
},
|
||||
});
|
||||
this._instruction = new Text({
|
||||
text: "",
|
||||
style: {
|
||||
fontFamily: "Arial",
|
||||
fontSize: 30,
|
||||
fill: 0x000000,
|
||||
align: "center",
|
||||
},
|
||||
});
|
||||
this._gameDesc.layout = { position: "absolute", left: "40%" };
|
||||
this._instruction.layout = {
|
||||
position: "absolute",
|
||||
left: "40%",
|
||||
top: "40%",
|
||||
};
|
||||
|
||||
this._addUiChild(this._gameDesc);
|
||||
this._addUiChild(this._instruction);
|
||||
|
||||
this.gameContainer.addChild(this._gameObjectsLayer);
|
||||
this.gameContainer.addChild(this._uiLayer);
|
||||
}
|
||||
|
|
@ -57,9 +28,9 @@ export class Game {
|
|||
|
||||
/* status indicates if its a win or a loss */
|
||||
end(status) {
|
||||
this.won = status;
|
||||
this.win = status;
|
||||
console.log(status ? "game won" : "game lost");
|
||||
this.onEnd(status);
|
||||
// we probably want to call a callback here
|
||||
}
|
||||
|
||||
_addGameObjectChild(node) {
|
||||
|
|
|
|||
|
|
@ -12,8 +12,6 @@ export class Opinator extends TimedGame {
|
|||
this._lastMousePos = undefined; // use to compute the travelled distance
|
||||
|
||||
this.timeout = this._baseGoalScore * 1000; // 1s per sprite len
|
||||
this._gameDesc.text = "Répare opinator !!";
|
||||
this._instruction.text = "clique et agite la souris";
|
||||
|
||||
this._backgroundSprite = Sprite.from("opinator");
|
||||
|
||||
|
|
|
|||
|
|
@ -6,15 +6,11 @@ export class SmartMonday extends TimedGame {
|
|||
constructor(ticker) {
|
||||
super(10000, ticker);
|
||||
|
||||
this._gameDesc.text = "Organise le smart monday !!";
|
||||
this._instruction.text = "spam le clavier";
|
||||
|
||||
this._goal = 100 * this._difficulty; // number of characters
|
||||
this.timeout = 1000 * (this._goal / 10); // 10 chars per second
|
||||
|
||||
this._currentString = "";
|
||||
this._keyEventHandle = undefined;
|
||||
this.gameContainer.layout = { width: "100%", height: "100%" };
|
||||
}
|
||||
|
||||
reset() {
|
||||
|
|
|
|||
|
|
@ -61,6 +61,6 @@ export class TimedGame extends Game {
|
|||
|
||||
_onTimeout() {
|
||||
console.log("time end");
|
||||
this.end(this.won);
|
||||
this.end(this._win);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
12
src/main.js
12
src/main.js
|
|
@ -2,7 +2,6 @@ import "@pixi/layout";
|
|||
import { Application, Assets, Container, Sprite } from "pixi.js";
|
||||
import { Fridge, Opinator, SmartMonday, CleanupHS } from "./games";
|
||||
import { backgroundLayout, KeyBoardListener } from "./common";
|
||||
import { GameManager } from "./gameManager";
|
||||
|
||||
const app = new Application();
|
||||
let root = new Container();
|
||||
|
|
@ -97,19 +96,14 @@ function switchToGame(gameContainer, newGame) {
|
|||
maxHeight: "100%",
|
||||
margin: 0,
|
||||
};
|
||||
root.addChild(gameContainter);
|
||||
|
||||
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;
|
||||
let currentGame = opinator;
|
||||
gameContainter.addChild(currentGame.gameContainer);
|
||||
|
||||
root.addChild(gameContainter);
|
||||
|
||||
currentGame.start();
|
||||
*/
|
||||
})();
|
||||
|
|
|
|||
3
todo.md
3
todo.md
|
|
@ -2,3 +2,6 @@
|
|||
|
||||
- diplay info
|
||||
- game result
|
||||
- game
|
||||
- game name
|
||||
- play instruction
|
||||
|
|
|
|||
Loading…
Reference in a new issue