Compare commits
No commits in common. "f5eee290fba311e2e16052d240ee4b9fc0b7cb57" and "5cb4c299a3031f97f655c20593e4810ead73a5f4" have entirely different histories.
f5eee290fb
...
5cb4c299a3
11 changed files with 45 additions and 159 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import { Container } from "pixi.js";
|
import { Container } from "pixi.js";
|
||||||
|
|
||||||
let maxZIndex = 100; // heretic method to bring dragged sprite to the front,
|
let maxZIndex = 0; // heretic method to bring dragged sprite to the front,
|
||||||
// will technically overflow if you play long enough,
|
// will technically overflow if you play long enough,
|
||||||
// it is also shitty because if you externally use zIndex on the sprites in the same container, it may not bring to front
|
// it is also shitty because if you externally use zIndex on the sprites in the same container, it may not bring to front
|
||||||
// clean solution would be to make a draggable container class
|
// clean solution would be to make a draggable container class
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,12 @@
|
||||||
import {
|
import { Application, Assets, Container, Sprite, Rectangle } from "pixi.js";
|
||||||
Application,
|
import { Game } from "./game";
|
||||||
Assets,
|
|
||||||
Container,
|
|
||||||
Sprite,
|
|
||||||
Rectangle,
|
|
||||||
Text,
|
|
||||||
} from "pixi.js";
|
|
||||||
import { TimedGame } from "./timedGame";
|
|
||||||
import { KeyBoardListener, makeDragable, getIntersection } from "../common";
|
import { KeyBoardListener, makeDragable, getIntersection } from "../common";
|
||||||
|
|
||||||
const itemTypes = { TRASH: "TRASH", HARDWARE: "HARDWARE" };
|
const itemTypes = { TRASH: "TRASH", HARDWARE: "HARDWARE" };
|
||||||
|
|
||||||
export class CleanupHS extends TimedGame {
|
export class CleanupHS extends Game {
|
||||||
constructor(width, height, ticker) {
|
constructor(width, height) {
|
||||||
super(10000, ticker);
|
super();
|
||||||
|
|
||||||
this._elementCount = this._difficulty * 6;
|
this._elementCount = this._difficulty * 6;
|
||||||
this._elementsPlaced = 0;
|
this._elementsPlaced = 0;
|
||||||
|
|
@ -21,8 +14,6 @@ export class CleanupHS extends TimedGame {
|
||||||
this._scree_w = width;
|
this._scree_w = width;
|
||||||
this._scree_h = height;
|
this._scree_h = height;
|
||||||
|
|
||||||
this.timeout = this._elementCount * 1000; // 1s per element
|
|
||||||
|
|
||||||
this.gameContainer.layout = {
|
this.gameContainer.layout = {
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "100%",
|
height: "100%",
|
||||||
|
|
@ -43,8 +34,8 @@ export class CleanupHS extends TimedGame {
|
||||||
trashcan.layout = { objectFit: "contain" };
|
trashcan.layout = { objectFit: "contain" };
|
||||||
shelf.layout = { objectFit: "contain" };
|
shelf.layout = { objectFit: "contain" };
|
||||||
|
|
||||||
this._addGameObjectChild(this.trashLandingZone);
|
this.gameContainer.addChild(this.trashLandingZone);
|
||||||
this._addGameObjectChild(this.shelfLandingZone);
|
this.gameContainer.addChild(this.shelfLandingZone);
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
|
|
@ -76,14 +67,10 @@ export class CleanupHS extends TimedGame {
|
||||||
makeDragable(item.sprite, (node) => {
|
makeDragable(item.sprite, (node) => {
|
||||||
this._onItemDrop(item);
|
this._onItemDrop(item);
|
||||||
});
|
});
|
||||||
this._addGameObjectChild(item.sprite);
|
this.gameContainer.addChild(item.sprite);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
end() {
|
|
||||||
super.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
_onItemDrop(item) {
|
_onItemDrop(item) {
|
||||||
console.log("dropped", item.type);
|
console.log("dropped", item.type);
|
||||||
|
|
||||||
|
|
@ -122,17 +109,13 @@ export class CleanupHS extends TimedGame {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._elementsPlaced >= this._elementCount) {
|
if (this._elementsPlaced >= this._elementCount) {
|
||||||
this.end(true);
|
this._win();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onError() {
|
_onError() {
|
||||||
console.log("wrong placement");
|
console.log("wrong placement");
|
||||||
// apply penalty for putting item in the wrong place
|
// apply penalty for putting item in the wrong place
|
||||||
this.removeTime(5000);
|
//probably a time loss
|
||||||
}
|
|
||||||
|
|
||||||
_timerConsoleDisplay() {
|
|
||||||
console.log("time left", this.getRemainingTime());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import {
|
||||||
getIntersection,
|
getIntersection,
|
||||||
makeUnDragable,
|
makeUnDragable,
|
||||||
} from "../common";
|
} from "../common";
|
||||||
import { TimedGame } from "./timedGame";
|
import { Game } from "./game";
|
||||||
|
|
||||||
class DropZone {
|
class DropZone {
|
||||||
constructor(sprite) {
|
constructor(sprite) {
|
||||||
|
|
@ -22,15 +22,13 @@ class DropZone {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Fridge extends TimedGame {
|
export class Fridge extends Game {
|
||||||
constructor(ticker) {
|
constructor() {
|
||||||
super(10000, ticker);
|
super();
|
||||||
|
|
||||||
this._bottleCount = 6;
|
this._bottleCount = 6;
|
||||||
this._bottlePlaced = 0;
|
this._bottlePlaced = 0;
|
||||||
|
|
||||||
this.timeout = this._bottleCount * 1500; // 1.5s per bottle
|
|
||||||
|
|
||||||
const fridgeContainer = new Container();
|
const fridgeContainer = new Container();
|
||||||
fridgeContainer.layout = { width: "50%" };
|
fridgeContainer.layout = { width: "50%" };
|
||||||
const fridge = Sprite.from("frigo");
|
const fridge = Sprite.from("frigo");
|
||||||
|
|
@ -47,8 +45,8 @@ export class Fridge extends TimedGame {
|
||||||
crate.layout = backgroundLayout;
|
crate.layout = backgroundLayout;
|
||||||
bottleContainer.addChild(crate);
|
bottleContainer.addChild(crate);
|
||||||
|
|
||||||
this._addGameObjectChild(fridgeContainer);
|
this.gameContainer.addChild(fridgeContainer);
|
||||||
this._addGameObjectChild(bottleContainer);
|
this.gameContainer.addChild(bottleContainer);
|
||||||
|
|
||||||
this.bottles = [];
|
this.bottles = [];
|
||||||
this._dropZones = [];
|
this._dropZones = [];
|
||||||
|
|
@ -82,21 +80,21 @@ export class Fridge extends TimedGame {
|
||||||
for (let i = 0; i < this._bottleCount; i++) {
|
for (let i = 0; i < this._bottleCount; i++) {
|
||||||
const sprite = Sprite.from("clubmate_grey");
|
const sprite = Sprite.from("clubmate_grey");
|
||||||
this._dropZones.push(new DropZone(sprite));
|
this._dropZones.push(new DropZone(sprite));
|
||||||
this._addGameObjectChild(sprite);
|
this.gameContainer.addChild(sprite);
|
||||||
|
|
||||||
sprite.x = 0;
|
sprite.x = 0;
|
||||||
sprite.y = 0;
|
sprite.y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < this._bottleCount; i++) {
|
for (let i = 0; i < this._bottleCount; i++) {
|
||||||
const newBottle = Sprite.from("clubmate");
|
const newBottle = Sprite.from("clubmate");
|
||||||
makeDragable(newBottle, (node) => {
|
makeDragable(newBottle, (node) => {
|
||||||
this._onBottleDrop(node);
|
this._onBottleDrop(node);
|
||||||
if (this._bottlePlaced >= this._bottleCount) {
|
if (this._bottlePlaced >= this._bottleCount) {
|
||||||
this.end(true);
|
this._win();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this._addGameObjectChild(newBottle);
|
this.gameContainer.addChild(newBottle);
|
||||||
|
|
||||||
this.bottles.push(newBottle);
|
this.bottles.push(newBottle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Container, RenderLayer } from "pixi.js";
|
import { Container } from "pixi.js";
|
||||||
|
|
||||||
export class Game {
|
export class Game {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -6,14 +6,6 @@ export class Game {
|
||||||
this.won = false;
|
this.won = false;
|
||||||
this.gameContainer = new Container(); // main container, to add the game to a node, add this container as a child
|
this.gameContainer = new Container(); // main container, to add the game to a node, add this container as a child
|
||||||
this.gameContainer.layout = true;
|
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.gameContainer.addChild(this._gameObjectsLayer);
|
|
||||||
this.gameContainer.addChild(this._uiLayer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* should reset the game to its initial position*/
|
/* should reset the game to its initial position*/
|
||||||
|
|
@ -32,14 +24,4 @@ export class Game {
|
||||||
console.log(status ? "game won" : "game lost");
|
console.log(status ? "game won" : "game lost");
|
||||||
// we probably want to call a callback here
|
// we probably want to call a callback here
|
||||||
}
|
}
|
||||||
|
|
||||||
_addGameObjectChild(node) {
|
|
||||||
this.gameContainer.addChild(node);
|
|
||||||
this._gameObjectsLayer.attach(node);
|
|
||||||
}
|
|
||||||
|
|
||||||
_addUiChild(node) {
|
|
||||||
this.gameContainer.addChild(node);
|
|
||||||
this._uiLayer.attach(node);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,15 @@
|
||||||
import { Application, Assets, Container, Sprite } from "pixi.js";
|
import { Application, Assets, Container, Sprite } from "pixi.js";
|
||||||
import { TimedGame } from "./timedGame";
|
import { Game } from "./game";
|
||||||
|
|
||||||
export class Opinator extends TimedGame {
|
export class Opinator extends Game {
|
||||||
constructor(ticker) {
|
constructor() {
|
||||||
super(10000, ticker);
|
super();
|
||||||
this._inMove = false; // indicates if player has grabed the wire (is mouse down)
|
this._inMove = false; // indicates if player has grabed the wire (is mouse down)
|
||||||
this._currentScore = 0;
|
this._currentScore = 0;
|
||||||
this._pixelGoalScore = undefined;
|
this._pixelGoalScore = undefined;
|
||||||
this._baseGoalScore = 8;
|
this._goalScore = 8 * this._difficulty; // goal to match, measured in play area, 10 = moving the mouse on the equivalent of 10 play areas
|
||||||
this._goalScore = this._baseGoalScore * this._difficulty; // goal to match, measured in play area, 10 = moving the mouse on the equivalent of 10 play areas
|
|
||||||
this._lastMousePos = undefined; // use to compute the travelled distance
|
this._lastMousePos = undefined; // use to compute the travelled distance
|
||||||
|
|
||||||
this.timeout = this._baseGoalScore * 1000; // 1s per sprite len
|
|
||||||
|
|
||||||
this._backgroundSprite = Sprite.from("opinator");
|
this._backgroundSprite = Sprite.from("opinator");
|
||||||
|
|
||||||
this._backgroundSprite.eventMode = "static";
|
this._backgroundSprite.eventMode = "static";
|
||||||
|
|
@ -51,14 +48,14 @@ export class Opinator extends TimedGame {
|
||||||
this._pixelGoalScore,
|
this._pixelGoalScore,
|
||||||
);
|
);
|
||||||
if (this._pixelGoalScore < this._currentScore) {
|
if (this._pixelGoalScore < this._currentScore) {
|
||||||
this.end(true);
|
this._win();
|
||||||
}
|
}
|
||||||
} //else ignore, not enough move to get some distance
|
} //else ignore, not enough move to get some distance
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this._backgroundSprite.layout = { objectFit: "contain" };
|
this._backgroundSprite.layout = { objectFit: "contain" };
|
||||||
this.gameContainer.layout = { width: "100%", height: "100%" };
|
this.gameContainer.layout = { width: "100%", height: "100%" };
|
||||||
this._addGameObjectChild(this._backgroundSprite);
|
this.gameContainer.addChild(this._backgroundSprite);
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@ import { TimedGame } from "./timedGame";
|
||||||
import { KeyBoardListener } from "../common";
|
import { KeyBoardListener } from "../common";
|
||||||
|
|
||||||
export class SmartMonday extends TimedGame {
|
export class SmartMonday extends TimedGame {
|
||||||
constructor(ticker) {
|
constructor() {
|
||||||
super(10000, ticker);
|
super(10000); // 10 chars per second
|
||||||
|
|
||||||
this._goal = 100 * this._difficulty; // number of characters
|
this._goal = 100 * this._difficulty; // number of characters
|
||||||
this.timeout = 1000 * (this._goal / 10); // 10 chars per second
|
this.timeout = 1000 * (this._goal / 10); // 10 chars per second
|
||||||
|
|
|
||||||
|
|
@ -1,66 +1,28 @@
|
||||||
import { Game } from "./game";
|
import { Game } from "./game";
|
||||||
import { TimerDisplay } from "../ui";
|
|
||||||
|
|
||||||
export class TimedGame extends Game {
|
export class TimedGame extends Game {
|
||||||
constructor(time, ticker) {
|
constructor(time) {
|
||||||
super();
|
super();
|
||||||
this._timeoutId = undefined;
|
this._timeoutId = undefined;
|
||||||
this.baseTimeout = time;
|
this.timeout = time;
|
||||||
this.currentTimeout = time;
|
|
||||||
|
|
||||||
this._timeoutStartTime = undefined;
|
|
||||||
|
|
||||||
this.timerDisplay = new TimerDisplay(() => {
|
|
||||||
return this.getRemainingTime();
|
|
||||||
}, ticker);
|
|
||||||
this._addUiChild(this.timerDisplay.node);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
super.start();
|
super.start();
|
||||||
this.timerDisplay.start();
|
|
||||||
this._timeoutStartTime = Date.now();
|
|
||||||
this._timeoutId = setInterval(() => {
|
this._timeoutId = setInterval(() => {
|
||||||
this._onTimeout();
|
console.log("time end");
|
||||||
}, this.baseTimeout);
|
this.end(this._win);
|
||||||
}
|
}, this.timeout);
|
||||||
|
|
||||||
/* remove t milliseconds to the current timeout (if any) */
|
|
||||||
removeTime(t) {
|
|
||||||
if (this._timeoutId != undefined) {
|
|
||||||
this.currentTimeout = this.getRemainingTime() - t;
|
|
||||||
clearTimeout(this._timeoutId);
|
|
||||||
if (t <= 0) {
|
|
||||||
this._onTimeout();
|
|
||||||
} else {
|
|
||||||
this._timeoutStartTime = Date.now();
|
|
||||||
this._timeoutId = setInterval(() => {
|
|
||||||
this._onTimeout();
|
|
||||||
}, this.currentTimeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
super.reset();
|
super.reset();
|
||||||
clearTimeout(this._timeoutId);
|
clearTimeout(this._timeoutId);
|
||||||
this._timeoutId = undefined;
|
this._timeoutId = undefined;
|
||||||
this._timeoutStartTime = undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end(status) {
|
end(status) {
|
||||||
super.end(status);
|
super.end(status);
|
||||||
this.timerDisplay.stop();
|
|
||||||
clearTimeout(this._timeoutId);
|
clearTimeout(this._timeoutId);
|
||||||
this._timeoutId = undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
getRemainingTime() {
|
|
||||||
return this.currentTimeout - (Date.now() - this._timeoutStartTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
_onTimeout() {
|
|
||||||
console.log("time end");
|
|
||||||
this.end(this._win);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
src/main.js
16
src/main.js
|
|
@ -96,14 +96,16 @@ function switchToGame(gameContainer, newGame) {
|
||||||
maxHeight: "100%",
|
maxHeight: "100%",
|
||||||
margin: 0,
|
margin: 0,
|
||||||
};
|
};
|
||||||
const opinator = new Opinator(app.ticker);
|
const opinator = new Opinator();
|
||||||
const fridge = new Fridge(app.ticker);
|
const fridge = new Fridge();
|
||||||
const smartMonday = new SmartMonday(app.ticker);
|
const smartMonday = new SmartMonday();
|
||||||
const cleanupHS = new CleanupHS(root.width, root.height, app.ticker);
|
const cleanupHS = new CleanupHS(root.width, root.height);
|
||||||
let currentGame = opinator;
|
//gameContainter.addChild(fridge.gameContainer);
|
||||||
gameContainter.addChild(currentGame.gameContainer);
|
//gameContainter.addChild(opinator.gameContainer);
|
||||||
|
gameContainter.addChild(smartMonday.gameContainer);
|
||||||
|
//gameContainter.addChild(cleanupHS.gameContainer);
|
||||||
|
|
||||||
root.addChild(gameContainter);
|
root.addChild(gameContainter);
|
||||||
|
|
||||||
currentGame.start();
|
smartMonday.start();
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
export { TimerDisplay } from "./timerDisplay";
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
import { Text } from "pixi.js";
|
|
||||||
|
|
||||||
export class TimerDisplay {
|
|
||||||
/* variable callback should be a callback giving the value to display */
|
|
||||||
constructor(variableCallback, ticker) {
|
|
||||||
this.node = new Text({
|
|
||||||
text: "default text",
|
|
||||||
style: {
|
|
||||||
fontFamily: "Arial",
|
|
||||||
fontSize: 24,
|
|
||||||
fill: 0xff1010,
|
|
||||||
align: "center",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
this.variableCallback = variableCallback;
|
|
||||||
this.callback = () => {
|
|
||||||
this.node.text = "" + this.variableCallback();
|
|
||||||
};
|
|
||||||
this.ticker = ticker;
|
|
||||||
}
|
|
||||||
|
|
||||||
start() {
|
|
||||||
this.ticker.add(this.callback);
|
|
||||||
}
|
|
||||||
|
|
||||||
stop() {
|
|
||||||
this.ticker.remove(this.callback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
7
todo.md
7
todo.md
|
|
@ -1,7 +0,0 @@
|
||||||
- game cycle -> launch a game handle end and launch next
|
|
||||||
|
|
||||||
- diplay info
|
|
||||||
- game result
|
|
||||||
- game
|
|
||||||
- game name
|
|
||||||
- play instruction
|
|
||||||
Loading…
Reference in a new issue