make all games timed games

This commit is contained in:
lagaffe 2026-04-26 15:09:57 +02:00
parent 5cb4c299a3
commit 0e1444ca47
5 changed files with 25 additions and 18 deletions

View file

@ -1,12 +1,12 @@
import { Application, Assets, Container, Sprite, Rectangle } from "pixi.js"; import { Application, Assets, Container, Sprite, Rectangle } from "pixi.js";
import { Game } from "./game"; 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 Game { export class CleanupHS extends TimedGame {
constructor(width, height) { constructor(width, height) {
super(); super(10000);
this._elementCount = this._difficulty * 6; this._elementCount = this._difficulty * 6;
this._elementsPlaced = 0; this._elementsPlaced = 0;
@ -14,6 +14,8 @@ export class CleanupHS extends Game {
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%",
@ -109,7 +111,7 @@ export class CleanupHS extends Game {
} }
if (this._elementsPlaced >= this._elementCount) { if (this._elementsPlaced >= this._elementCount) {
this._win(); this.end(true);
} }
} }

View file

@ -5,7 +5,7 @@ import {
getIntersection, getIntersection,
makeUnDragable, makeUnDragable,
} from "../common"; } from "../common";
import { Game } from "./game"; import { TimedGame } from "./timedGame";
class DropZone { class DropZone {
constructor(sprite) { constructor(sprite) {
@ -22,13 +22,15 @@ class DropZone {
} }
} }
export class Fridge extends Game { export class Fridge extends TimedGame {
constructor() { constructor() {
super(); super(10000);
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");
@ -85,16 +87,16 @@ export class Fridge extends Game {
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._win(); this.end(true);
} }
}); });
this.gameContainer.addChild(newBottle); this.gameContainer.addChild(newBottle);
this.bottles.push(newBottle); this.bottles.push(newBottle);
} }
} }

View file

@ -1,15 +1,18 @@
import { Application, Assets, Container, Sprite } from "pixi.js"; import { Application, Assets, Container, Sprite } from "pixi.js";
import { Game } from "./game"; import { TimedGame } from "./timedGame";
export class Opinator extends Game { export class Opinator extends TimedGame {
constructor() { constructor() {
super(); super(10000);
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._goalScore = 8 * this._difficulty; // goal to match, measured in play area, 10 = moving the mouse on the equivalent of 10 play areas this._baseGoalScore = 8;
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";
@ -48,7 +51,7 @@ export class Opinator extends Game {
this._pixelGoalScore, this._pixelGoalScore,
); );
if (this._pixelGoalScore < this._currentScore) { if (this._pixelGoalScore < this._currentScore) {
this._win(); this.end(true);
} }
} //else ignore, not enough move to get some distance } //else ignore, not enough move to get some distance
} }

View file

@ -4,7 +4,7 @@ import { KeyBoardListener } from "../common";
export class SmartMonday extends TimedGame { export class SmartMonday extends TimedGame {
constructor() { constructor() {
super(10000); // 10 chars per second super(10000);
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

View file

@ -102,10 +102,10 @@ function switchToGame(gameContainer, newGame) {
const cleanupHS = new CleanupHS(root.width, root.height); const cleanupHS = new CleanupHS(root.width, root.height);
//gameContainter.addChild(fridge.gameContainer); //gameContainter.addChild(fridge.gameContainer);
//gameContainter.addChild(opinator.gameContainer); //gameContainter.addChild(opinator.gameContainer);
gameContainter.addChild(smartMonday.gameContainer); //gameContainter.addChild(smartMonday.gameContainer);
//gameContainter.addChild(cleanupHS.gameContainer); gameContainter.addChild(cleanupHS.gameContainer);
root.addChild(gameContainter); root.addChild(gameContainter);
smartMonday.start(); cleanupHS.start();
})(); })();