diff --git a/src/components/Employee.ts b/src/components/Employee.ts index 194a2e3..e9516f4 100644 --- a/src/components/Employee.ts +++ b/src/components/Employee.ts @@ -52,11 +52,7 @@ export class Employee extends Button { } update(time: number, delta: number) { - const factor = this.doingCuteThing - ? 0.1 - : this.hasBeenPurchased - ? 0.02 - : 0; + const factor = this.doingCuteThing ? 0.1 : this.hasBeenPurchased ? 0.02 : 0; const squish = 1.0 + factor * Math.sin((6 * time) / 1000); this.spriteCont.setScale(1.0, squish - 0.2 * this.holdSmooth); } @@ -114,6 +110,14 @@ export class Employee extends Button { } } + // Only used when loading levels + forceUpgrade(id: EmployeeId) { + this.hasBeenPurchased = true; + this.setAlpha(1.0); + this.employeeId = id; + this.sprite.setTexture(this.spriteKey); + } + /* Getters */ get employeeType(): EmployeeType { diff --git a/src/components/EmployeeData.ts b/src/components/EmployeeData.ts index 1020f22..2546638 100644 --- a/src/components/EmployeeData.ts +++ b/src/components/EmployeeData.ts @@ -35,7 +35,7 @@ export const EmployeeData: { [key in EmployeeId]: EmployeeInterface } = { spriteKey: "worker", walkSpeed: 1, workSpeed: 1, - cost: 1000, + cost: 300, upgradeTo: EmployeeId.RaccoonTier2, }, [EmployeeId.RaccoonTier2]: { diff --git a/src/components/Levels.ts b/src/components/Levels.ts index 18e0057..6ee0d1b 100644 --- a/src/components/Levels.ts +++ b/src/components/Levels.ts @@ -11,6 +11,7 @@ export interface Level { height: number; cellSize: number; grid: number[][]; + upgradeCost?: number; } export enum BlockType { @@ -42,6 +43,7 @@ export const LevelData: Level[] = [ [X, _, 5, 5, _, 6, _, _], [X, X, X, X, X, X, X, X], ], + upgradeCost: 1000, }, { id: LevelId.Level2, @@ -58,6 +60,7 @@ export const LevelData: Level[] = [ [X, 9, 9, 9, _, _, 6, _, _], [X, X, X, X, X, X, X, X, X], ], + upgradeCost: 2000, }, { id: LevelId.Level3, diff --git a/src/components/Station.ts b/src/components/Station.ts index e7d0505..ca515b1 100644 --- a/src/components/Station.ts +++ b/src/components/Station.ts @@ -239,6 +239,16 @@ export class Station extends Button { } } + // Only used when loading levels + forceUpgrade(id: StationId) { + this.hasBeenPurchased = true; + this.setAlpha(1.0); + this.stationId = id; + this.sprite.setTexture(this.spriteKey); + this.spriteCont.y = this.spriteOffset; + this.sprite.setScale(this.spriteSize / this.sprite.width); + } + applyItem(id: number, sp: string) { this.appliedItems.push(id); let st = new Phaser.GameObjects.Sprite( diff --git a/src/components/UI.ts b/src/components/UI.ts index 117902c..11216a4 100644 --- a/src/components/UI.ts +++ b/src/components/UI.ts @@ -1,6 +1,7 @@ import { GameScene } from "@/scenes/GameScene"; import { Timer } from "./Timer"; import { TextButton } from "./TextButton"; +import { Level } from "./Levels"; export class UI extends Phaser.GameObjects.Container { public scene: GameScene; @@ -72,21 +73,23 @@ export class UI extends Phaser.GameObjects.Container { this.moneyText.setOrigin(0.5); this.panel.add(this.moneyText); - this.nextButton = new TextButton(scene, 0, 300, 300, 80, "Start day"); + this.nextButton = new TextButton(scene, 0, 600, 300, 80, "Start day"); this.panel.add(this.nextButton); this.nextButton.on("click", () => { this.emit("nextDay"); }); - this.newLocationButton = new TextButton(scene, 0, 440, 240, 80, "Move"); + this.newLocationButton = new TextButton(scene, 0, 400, 300, 200, "..."); this.panel.add(this.newLocationButton); this.newLocationButton.on("click", () => { this.emit("nextLevel"); }); - this.newLocationButton.setVisible(false); } - update(time: number, delta: number) {} + update(time: number, delta: number) { + this.nextButton.update(time, delta); + this.newLocationButton.update(time, delta); + } setDay(day: number) { this.dayText.setText(`Day ${day}`); @@ -96,8 +99,21 @@ export class UI extends Phaser.GameObjects.Container { this.dayProgressTimer.redraw(time); } + setLevel(level: Level) { + this.newLocationButton.setData("cost", level.upgradeCost); + this.newLocationButton.setVisible(level.upgradeCost !== undefined); + this.newLocationButton.setText( + `Upgrade\n shop\n $${level.upgradeCost}` + ); + } + setMoney(money: number) { this.moneyText.setText(`Money: $${money}`); + + const upgradeCost = this.newLocationButton.getData("cost"); + const canUpgrade = money >= upgradeCost; + this.newLocationButton.setAlpha(canUpgrade ? 1 : 0.5); + this.newLocationButton.enabled = canUpgrade; } setShoppingMode(isShopping: boolean) { diff --git a/src/scenes/GameScene.ts b/src/scenes/GameScene.ts index 1ad2d9b..a28441a 100644 --- a/src/scenes/GameScene.ts +++ b/src/scenes/GameScene.ts @@ -5,7 +5,7 @@ import { Customer } from "@/components/Customer"; import { CustomerId } from "@/components/CustomerData"; import { Station } from "@/components/Station"; import { UI } from "@/components/UI"; -import { StationId, StationType } from "@/components/StationData"; +import { StationData, StationId, StationType } from "@/components/StationData"; import { Inventory } from "@/components/Inventory"; import { SimpleButton } from "@/components/elements/SimpleButton"; import { ToggleButton } from "@/components/elements/ToggleButton"; @@ -13,7 +13,7 @@ import { ItemButton } from "@/components/ItemButton"; import { ItemHandler } from "@/components/ItemHandler"; import { UpgradeOverlay } from "@/components/UpgradeOverlay"; import { SummaryOverlay } from "@/components/SummaryOverlay"; -import { EmployeeId } from "@/components/EmployeeData"; +import { EmployeeData, EmployeeId } from "@/components/EmployeeData"; import { BlockType, LevelData, LevelId } from "@/components/Levels"; import { Effect } from "@/components/Effect"; import { TextEffect } from "@/components/TextEffect"; @@ -59,7 +59,7 @@ export class GameScene extends BaseScene { public timeOfDay: number = 0; public customerSpawnTimer: Phaser.Time.TimerEvent; public customerSpawnPool: CustomerId[] = []; - public money: number = 0; + public money: number = 500; public dailyStats: { money: number; happyCustomers: number; @@ -89,6 +89,7 @@ export class GameScene extends BaseScene { stations: [ StationId.WaitingSeatTier1, StationId.HornAndNailsTier1, + StationId.ScalePolishTier1, StationId.CashRegister, ], employees: [EmployeeId.RaccoonTier1], @@ -107,6 +108,18 @@ export class GameScene extends BaseScene { this.ui = new UI(this); this.ui.setDepth(1000); + this.ui.on("nextDay", () => { + this.startDay(); + }); + this.ui.on("nextLevel", () => { + const upgradeCost = LevelData[this.level].upgradeCost ?? 0; + if (this.money >= upgradeCost) { + this.money -= upgradeCost; + this.ui.setMoney(this.money); + this.intermission.fadeToIntermission(Mode.NextLevelCutscene); + } + }); + this.iHandler = new ItemHandler(this); this.intermission = new Intermission(this); @@ -152,31 +165,21 @@ export class GameScene extends BaseScene { "blankspr" ); - //UI - this.ui.setMoney(this.money); - this.ui.setDay(this.day); - this.ui.on("nextDay", () => { - this.startDay(); - }); - this.ui.on("nextLevel", () => { - this.intermission.fadeToIntermission(Mode.NextLevelCutscene); - }); - this.upgradeOverlay = new UpgradeOverlay(this); this.upgradeOverlay.setDepth(1010); this.upgradeOverlay.on("upgradeStation", (station: Station) => { this.money -= station.upgradeCost; this.ui.setMoney(this.money); station.upgrade(); - this.upgradeOverlay.close(); - // this.upgradeOverlay.selectStation(station); + this.upgradeOverlay.selectStation(station); + this.updateSavedPurchases(); }); this.upgradeOverlay.on("upgradeEmployee", (employee: Employee) => { this.money -= employee.upgradeCost; this.ui.setMoney(this.money); employee.upgrade(); - // this.upgradeOverlay.selectEmployee(employee); - this.upgradeOverlay.close(); + this.upgradeOverlay.selectEmployee(employee); + this.updateSavedPurchases(); }); this.upgradeOverlay.on("close", () => { this.sortDepth(); @@ -312,20 +315,30 @@ export class GameScene extends BaseScene { // Load saved purchases this.savedPurchases.stations.forEach((id) => { - const station = this.stations.find((s) => s.stationId === id); + const station = this.stations.find( + (s) => !s.hasBeenPurchased && s.stationType === StationData[id].type + ); if (station) { - station.upgrade(); + station.forceUpgrade(id); } }); this.savedPurchases.employees.forEach((id) => { - const employee = this.employees.find((e) => e.employeeId === id); + const employee = this.employees.find( + (e) => !e.hasBeenPurchased && e.employeeType === EmployeeData[id].type + ); if (employee) { - employee.upgrade(); + employee.forceUpgrade(id); } }); - + // Generate navmesh - this.navmesh = GenerateNavMesh(this.board, LevelData[id]) + this.navmesh = GenerateNavMesh(this.board, LevelData[id]); + + this.ui.setLevel(level); + this.ui.setMoney(this.money); + this.ui.setDay(this.day); + + this.setState(GameState.Shopping); } // Start a new day @@ -383,7 +396,7 @@ export class GameScene extends BaseScene { // Attempt to spawn customer and reset timer attemptSpawnCustomer() { // Delay to next customer spawn - let delay = 1000; + let delay = 2000; // Randomly select customer type const id = Phaser.Math.RND.pick(this.customerSpawnPool); @@ -413,16 +426,25 @@ export class GameScene extends BaseScene { updateSpawnPool() { this.customerSpawnPool = []; - const anyTier2Stations = this.stations.some( + const tier2StationCount = this.stations.filter( (s) => s.stationTier >= 2 && s.hasBeenPurchased - ); - const anyTier3Stations = this.stations.some( - (s) => s.stationTier >= 3 && s.hasBeenPurchased - ); + ).length; + const tier3StationCount = this.stations.filter( + (s) => s.stationTier >= 2 && s.hasBeenPurchased + ).length; this.customerSpawnPool.push(CustomerId.Small); - if (anyTier2Stations) this.customerSpawnPool.push(CustomerId.Medium); - if (anyTier3Stations) this.customerSpawnPool.push(CustomerId.Large); + if (tier2StationCount >= 2) this.customerSpawnPool.push(CustomerId.Medium); + if (tier3StationCount >= 2) this.customerSpawnPool.push(CustomerId.Large); + } + + updateSavedPurchases() { + this.savedPurchases.stations = this.stations + .filter((s) => s.hasBeenPurchased) + .map((s) => s.stationId); + this.savedPurchases.employees = this.employees + .filter((e) => e.hasBeenPurchased) + .map((e) => e.employeeId); } // Add new station