add game smart monday
This commit is contained in:
parent
0a95900c55
commit
8f08f96096
7 changed files with 42 additions and 15 deletions
|
|
@ -91,7 +91,7 @@ export class Fridge extends Game {
|
||||||
makeDragable(newBottle, (node) => {
|
makeDragable(newBottle, (node) => {
|
||||||
this._onBottleDrop(node);
|
this._onBottleDrop(node);
|
||||||
if (this._bottlePlaced >= this._bottleCount) {
|
if (this._bottlePlaced >= this._bottleCount) {
|
||||||
console.log("fridge game won");
|
this._win();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.gameContainer.addChild(newBottle);
|
this.gameContainer.addChild(newBottle);
|
||||||
|
|
|
||||||
|
|
@ -10,4 +10,10 @@ export class Game {
|
||||||
|
|
||||||
/* should reset the game to its initial position*/
|
/* should reset the game to its initial position*/
|
||||||
reset() {}
|
reset() {}
|
||||||
|
|
||||||
|
_win() {
|
||||||
|
this.win = true;
|
||||||
|
console.log("game won");
|
||||||
|
// we probably want to call a callback here
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export { Fridge } from "./fridge.js";
|
export { Fridge } from "./fridge.js";
|
||||||
export { Opinator } from "./opinator.js";
|
export { Opinator } from "./opinator.js";
|
||||||
|
export { SmartMonday } from "./smartMonday.js";
|
||||||
|
|
|
||||||
|
|
@ -51,13 +51,13 @@ export class Opinator extends Game {
|
||||||
this._pixelGoalScore,
|
this._pixelGoalScore,
|
||||||
);
|
);
|
||||||
if (this._pixelGoalScore < this._currentScore) {
|
if (this._pixelGoalScore < this._currentScore) {
|
||||||
console.log("game won");
|
this._win();
|
||||||
this.won = true;
|
|
||||||
}
|
}
|
||||||
} //else ignore, not enough move to get some distance
|
} //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);
|
this.gameContainer.addChild(backgroundSprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
22
src/games/smartMonday.js
Normal file
22
src/games/smartMonday.js
Normal file
|
|
@ -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() {}
|
||||||
|
}
|
||||||
13
src/main.js
13
src/main.js
|
|
@ -1,7 +1,7 @@
|
||||||
import "@pixi/layout";
|
import "@pixi/layout";
|
||||||
import { Application, Assets, Container, Sprite } from "pixi.js";
|
import { Application, Assets, Container, Sprite } from "pixi.js";
|
||||||
import { Fridge, Opinator } from "./games";
|
import { Fridge, Opinator, SmartMonday } from "./games";
|
||||||
import { backgroundLayout } from "./common";
|
import { backgroundLayout, KeyBoardListener } from "./common";
|
||||||
|
|
||||||
const app = new Application();
|
const app = new Application();
|
||||||
let root = new Container();
|
let root = new Container();
|
||||||
|
|
@ -53,6 +53,8 @@ async function preload() {
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
await Assets.load(assets);
|
await Assets.load(assets);
|
||||||
|
|
||||||
|
KeyBoardListener.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchToGame(gameContainer, newGame) {
|
function switchToGame(gameContainer, newGame) {
|
||||||
|
|
@ -80,7 +82,10 @@ function switchToGame(gameContainer, newGame) {
|
||||||
};
|
};
|
||||||
const opinator = new Opinator();
|
const opinator = new Opinator();
|
||||||
const fridge = new Fridge();
|
const fridge = new Fridge();
|
||||||
gameContainter.addChild(fridge.gameContainer);
|
const smartMonday = new SmartMonday();
|
||||||
//gameContainter.addChild(opinator.gameContainer);
|
//gameContainter.addChild(fridge.gameContainer);
|
||||||
|
gameContainter.addChild(opinator.gameContainer);
|
||||||
|
gameContainter.addChild(smartMonday.gameContainer);
|
||||||
|
|
||||||
root.addChild(gameContainter);
|
root.addChild(gameContainter);
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
7
src/package-lock.json
generated
7
src/package-lock.json
generated
|
|
@ -9,7 +9,6 @@
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pixi/layout": "^3.2.0",
|
"@pixi/layout": "^3.2.0",
|
||||||
"@pixi/math": "^7.4.3",
|
|
||||||
"pixi.js": "^8.0.0"
|
"pixi.js": "^8.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
@ -102,12 +101,6 @@
|
||||||
"yoga-layout": "^3"
|
"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": {
|
"node_modules/@pixi/react": {
|
||||||
"version": "8.0.5",
|
"version": "8.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/@pixi/react/-/react-8.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/@pixi/react/-/react-8.0.5.tgz",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue