diff --git a/src/games/fridge.js b/src/games/fridge.js index 1aa3b19..78fe3de 100644 --- a/src/games/fridge.js +++ b/src/games/fridge.js @@ -91,7 +91,7 @@ export class Fridge extends Game { makeDragable(newBottle, (node) => { this._onBottleDrop(node); if (this._bottlePlaced >= this._bottleCount) { - console.log("fridge game won"); + this._win(); } }); this.gameContainer.addChild(newBottle); diff --git a/src/games/game.js b/src/games/game.js index bd3d981..6f4fb2b 100644 --- a/src/games/game.js +++ b/src/games/game.js @@ -10,4 +10,10 @@ 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 + } } diff --git a/src/games/index.js b/src/games/index.js index a0355bf..51d25bb 100644 --- a/src/games/index.js +++ b/src/games/index.js @@ -1,2 +1,3 @@ export { Fridge } from "./fridge.js"; export { Opinator } from "./opinator.js"; +export { SmartMonday } from "./smartMonday.js"; diff --git a/src/games/opinator.js b/src/games/opinator.js index e31a70a..50ba2cd 100644 --- a/src/games/opinator.js +++ b/src/games/opinator.js @@ -51,13 +51,13 @@ export class Opinator extends Game { this._pixelGoalScore, ); if (this._pixelGoalScore < this._currentScore) { - console.log("game won"); - this.won = true; + this._win(); } } //else ignore, not enough move to get some distance } }); - backgroundSprite.layout = backgroundLayout; + backgroundSprite.layout = { objectFit: "contain" }; + this.gameContainer.layout = { width: "100%", height: "100%" }; this.gameContainer.addChild(backgroundSprite); } diff --git a/src/games/smartMonday.js b/src/games/smartMonday.js new file mode 100644 index 0000000..c271029 --- /dev/null +++ b/src/games/smartMonday.js @@ -0,0 +1,22 @@ +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() {} +} diff --git a/src/main.js b/src/main.js index 0afaca0..3a0718f 100644 --- a/src/main.js +++ b/src/main.js @@ -1,7 +1,7 @@ import "@pixi/layout"; import { Application, Assets, Container, Sprite } from "pixi.js"; -import { Fridge, Opinator } from "./games"; -import { backgroundLayout } from "./common"; +import { Fridge, Opinator, SmartMonday } from "./games"; +import { backgroundLayout, KeyBoardListener } from "./common"; const app = new Application(); let root = new Container(); @@ -53,6 +53,8 @@ async function preload() { }, ]; await Assets.load(assets); + + KeyBoardListener.init(); } function switchToGame(gameContainer, newGame) { @@ -80,7 +82,10 @@ function switchToGame(gameContainer, newGame) { }; const opinator = new Opinator(); const fridge = new Fridge(); - gameContainter.addChild(fridge.gameContainer); - //gameContainter.addChild(opinator.gameContainer); + const smartMonday = new SmartMonday(); + //gameContainter.addChild(fridge.gameContainer); + gameContainter.addChild(opinator.gameContainer); + gameContainter.addChild(smartMonday.gameContainer); + root.addChild(gameContainter); })(); diff --git a/src/package-lock.json b/src/package-lock.json index d379b69..82b1cd2 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -9,7 +9,6 @@ "version": "0.0.0", "dependencies": { "@pixi/layout": "^3.2.0", - "@pixi/math": "^7.4.3", "pixi.js": "^8.0.0" }, "devDependencies": { @@ -102,12 +101,6 @@ "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",