Compare commits
No commits in common. "8f08f96096dd314fa33c4c06808ca1641188350f" and "5057de55720ab27286a8386aeefc8bc483a8aab3" have entirely different histories.
8f08f96096
...
5057de5572
9 changed files with 15 additions and 89 deletions
|
|
@ -1,4 +1,3 @@
|
|||
export { backgroundLayout } from "./layouts";
|
||||
export { makeDragable, makeUnDragable } from "./dragAndDrop";
|
||||
export { getIntersection } from "./helpers";
|
||||
export { KeyBoardListener } from "./keyBoardEvents";
|
||||
|
|
|
|||
|
|
@ -1,46 +0,0 @@
|
|||
export class KeyBoardListener {
|
||||
static _listenersKeyUp = {};
|
||||
static _listenersKeyDown = {};
|
||||
static ready = false;
|
||||
static _listenCount = 0;
|
||||
static init() {
|
||||
document.addEventListener("keydown", (event) => {
|
||||
for (const listener of Object.values(
|
||||
KeyBoardListener._listenersKeyDown,
|
||||
)) {
|
||||
listener(event);
|
||||
}
|
||||
});
|
||||
document.addEventListener("keyup", (event) => {
|
||||
for (const listener of Object.values(
|
||||
KeyBoardListener._listenersKeyUp,
|
||||
)) {
|
||||
listener(event);
|
||||
}
|
||||
});
|
||||
|
||||
KeyBoardListener.ready = true;
|
||||
}
|
||||
|
||||
/* return id used to remove the listener */
|
||||
static onKeyDown(callback) {
|
||||
const id = KeyBoardListener._listenCount++;
|
||||
KeyBoardListener._listenersKeyDown[id] = callback;
|
||||
return id;
|
||||
}
|
||||
|
||||
static offKeyDown(id) {
|
||||
delete KeyBoardListener._listenersKeyDown[id];
|
||||
}
|
||||
|
||||
/* return id used to remove the listener */
|
||||
static onKeyUp(callback) {
|
||||
const id = KeyBoardListener._listenCount++;
|
||||
KeyBoardListener._listenersKeyUp[id] = callback;
|
||||
return id;
|
||||
}
|
||||
|
||||
static offKeyUp(id) {
|
||||
delete KeyBoardListener._listenersKeyUp[id];
|
||||
}
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ export class Fridge extends Game {
|
|||
makeDragable(newBottle, (node) => {
|
||||
this._onBottleDrop(node);
|
||||
if (this._bottlePlaced >= this._bottleCount) {
|
||||
this._win();
|
||||
console.log("fridge game won");
|
||||
}
|
||||
});
|
||||
this.gameContainer.addChild(newBottle);
|
||||
|
|
|
|||
|
|
@ -10,10 +10,4 @@ export class Game {
|
|||
|
||||
/* should reset the game to its initial position*/
|
||||
reset() {}
|
||||
|
||||
_win() {
|
||||
this.win = true;
|
||||
console.log("game won");
|
||||
// we probably want to call a callback here
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,2 @@
|
|||
export { Fridge } from "./fridge.js";
|
||||
export { Opinator } from "./opinator.js";
|
||||
export { SmartMonday } from "./smartMonday.js";
|
||||
|
|
|
|||
|
|
@ -51,13 +51,13 @@ export class Opinator extends Game {
|
|||
this._pixelGoalScore,
|
||||
);
|
||||
if (this._pixelGoalScore < this._currentScore) {
|
||||
this._win();
|
||||
console.log("game won");
|
||||
this.won = true;
|
||||
}
|
||||
} //else ignore, not enough move to get some distance
|
||||
}
|
||||
});
|
||||
backgroundSprite.layout = { objectFit: "contain" };
|
||||
this.gameContainer.layout = { width: "100%", height: "100%" };
|
||||
backgroundSprite.layout = backgroundLayout;
|
||||
this.gameContainer.addChild(backgroundSprite);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
import { Application, Assets, Container, Sprite, Rectangle } from "pixi.js";
|
||||
import { Game } from "./game";
|
||||
import { KeyBoardListener } from "../common";
|
||||
|
||||
export class SmartMonday extends Game {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this._goal = 100 * this._difficulty; // number of characters
|
||||
this._currentString = "";
|
||||
|
||||
const handle = KeyBoardListener.onKeyDown((event) => {
|
||||
this._currentString += event.key;
|
||||
console.log("current text", this._currentString);
|
||||
if (this._currentString.length >= this._goal) {
|
||||
this._win();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
reset() {}
|
||||
}
|
||||
13
src/main.js
13
src/main.js
|
|
@ -1,7 +1,7 @@
|
|||
import "@pixi/layout";
|
||||
import { Application, Assets, Container, Sprite } from "pixi.js";
|
||||
import { Fridge, Opinator, SmartMonday } from "./games";
|
||||
import { backgroundLayout, KeyBoardListener } from "./common";
|
||||
import { Fridge, Opinator } from "./games";
|
||||
import { backgroundLayout } from "./common";
|
||||
|
||||
const app = new Application();
|
||||
let root = new Container();
|
||||
|
|
@ -53,8 +53,6 @@ async function preload() {
|
|||
},
|
||||
];
|
||||
await Assets.load(assets);
|
||||
|
||||
KeyBoardListener.init();
|
||||
}
|
||||
|
||||
function switchToGame(gameContainer, newGame) {
|
||||
|
|
@ -82,10 +80,7 @@ function switchToGame(gameContainer, newGame) {
|
|||
};
|
||||
const opinator = new Opinator();
|
||||
const fridge = new Fridge();
|
||||
const smartMonday = new SmartMonday();
|
||||
//gameContainter.addChild(fridge.gameContainer);
|
||||
gameContainter.addChild(opinator.gameContainer);
|
||||
gameContainter.addChild(smartMonday.gameContainer);
|
||||
|
||||
gameContainter.addChild(fridge.gameContainer);
|
||||
//gameContainter.addChild(opinator.gameContainer);
|
||||
root.addChild(gameContainter);
|
||||
})();
|
||||
|
|
|
|||
7
src/package-lock.json
generated
7
src/package-lock.json
generated
|
|
@ -9,6 +9,7 @@
|
|||
"version": "0.0.0",
|
||||
"dependencies": {
|
||||
"@pixi/layout": "^3.2.0",
|
||||
"@pixi/math": "^7.4.3",
|
||||
"pixi.js": "^8.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
@ -101,6 +102,12 @@
|
|||
"yoga-layout": "^3"
|
||||
}
|
||||
},
|
||||
"node_modules/@pixi/math": {
|
||||
"version": "7.4.3",
|
||||
"resolved": "https://registry.npmjs.org/@pixi/math/-/math-7.4.3.tgz",
|
||||
"integrity": "sha512-/uJOVhR2DOZ+zgdI6Bs/CwcXT4bNRKsS+TqX3ekRIxPCwaLra+Qdm7aDxT5cTToDzdxbKL5+rwiLu3Y1egILDw==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@pixi/react": {
|
||||
"version": "8.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@pixi/react/-/react-8.0.5.tgz",
|
||||
|
|
|
|||
Loading…
Reference in a new issue