diff --git a/src/components/Customer.ts b/src/components/Customer.ts index 61ba3eb..59aee91 100644 --- a/src/components/Customer.ts +++ b/src/components/Customer.ts @@ -10,8 +10,15 @@ export class Customer extends Button { public dragY: number; public currentStation: Station | null; public currentEmployee: Employee | null; + + // Requests + public itinerary: StationType[]; // List of stations to visit public requestedStation: StationType | null; + + // Customer stats public doingCuteThing: boolean; + public tasksCompleted: number; + public moneySpent: number; // Customer sprite private sprite: Phaser.GameObjects.Sprite; @@ -31,8 +38,14 @@ export class Customer extends Button { this.dragY = y; this.currentStation = null; this.currentEmployee = null; + + this.itinerary = []; this.requestedStation = null; + this.doingCuteThing = false; + this.tasksCompleted = 0; + this.moneySpent = 0; + /* Sprite */ const size = 150; this.sprite = this.scene.add.sprite(0, 0, "player"); @@ -109,4 +122,30 @@ export class Customer extends Button { this.bubbleImage.setVisible(false); } } + + nextActivity() { + if (this.itinerary.length > 0) { + this.setRequest(this.itinerary.shift() || null); + } else { + if (this.currentStation) { + this.currentStation.setCustomer(null); + this.setStation(null); + } + this.leave(); + } + } + + leave() { + this.sprite.input!.enabled = false; + this.scene.tweens.add({ + targets: this, + dragX: this.lastX + 1920, + dragY: this.lastY, + duration: 2000, + ease: "Linear", + onComplete: () => { + this.emit("offscreen"); + }, + }); + } } diff --git a/src/components/Station.ts b/src/components/Station.ts index 2bc077b..7e674c8 100644 --- a/src/components/Station.ts +++ b/src/components/Station.ts @@ -3,21 +3,26 @@ import { Button } from "./elements/Button"; import { Customer } from "./Customer"; export enum StationType { - HornAndNails = 0, - ScalePolish = 1, - GoldBath = 2, + WaitingSeat, + HornAndNails, + ScalePolish, + GoldBath, + CashRegister, } export const StationTypeColors: { [key in StationType]: number } = { + [StationType.WaitingSeat]: 0x777777, [StationType.HornAndNails]: 0xff0000, [StationType.ScalePolish]: 0x00ff00, [StationType.GoldBath]: 0x0000ff, + [StationType.CashRegister]: 0xffff00, }; export class Station extends Button { public stationType: StationType; public currentCustomer: Customer | null; // The customer using the station public taskDuration: number; // Time it takes to complete a task + public admissionFee: number; // Cost to use the station private sprite: Phaser.GameObjects.Rectangle; private text: Phaser.GameObjects.Text; @@ -30,6 +35,7 @@ export class Station extends Button { this.currentCustomer = null; this.taskDuration = 3000; + this.admissionFee = 10; /* Sprite */ const size = 150; diff --git a/src/scenes/GameScene.ts b/src/scenes/GameScene.ts index bd79cf4..3bff62d 100644 --- a/src/scenes/GameScene.ts +++ b/src/scenes/GameScene.ts @@ -24,6 +24,7 @@ export class GameScene extends BaseScene { this.fade(false, 200, 0x000000); this.input.addPointer(2); + this.input.dragDistanceThreshold = 10; this.background = this.add.image(0, 0, "background"); this.background.setOrigin(0); @@ -75,7 +76,9 @@ export class GameScene extends BaseScene { employee.setAction(false); employee.setCustomer(null); - this.setCustomerRequest(customer); + customer.tasksCompleted += 1; + customer.moneySpent += station.admissionFee; + customer.nextActivity(); } }); } @@ -112,8 +115,8 @@ export class GameScene extends BaseScene { const customer = new Customer(this, coord.x, coord.y); this.customers.push(customer); - // Set random customer request - this.setCustomerRequest(customer); + // Set list of activities for customer + this.setCustomerItinerary(customer); // Picking up a customer customer.on("pickup", () => { @@ -156,6 +159,17 @@ export class GameScene extends BaseScene { customer.on("click", () => { this.callEmployee(customer); }); + + // Customer leaving the game + customer.on("offscreen", () => { + this.customers = this.customers.filter((c) => c !== customer); + customer.destroy(); + + // Spawn new customer + const x = Phaser.Math.Between(0, 3); + const y = Phaser.Math.Between(0, 1); + this.addCustomer(x, y); + }); } // Find the closest station to the customer that is not occupied @@ -222,8 +236,28 @@ export class GameScene extends BaseScene { } // Set a random request for the customer - setCustomerRequest(customer: Customer) { - const type = Phaser.Math.RND.between(0, 2); - customer.setRequest(type); + setCustomerItinerary(customer: Customer) { + function getActivities() { + let activities = []; + if (Math.random() < 0.5) { + activities.push(StationType.HornAndNails); + } + if (Math.random() < 0.5) { + activities.push(StationType.ScalePolish); + } + if (Math.random() < 0.5) { + activities.push(StationType.GoldBath); + } + return activities; + } + + let activities: StationType[] = []; + while (activities.length === 0) { + activities = getActivities(); + } + + customer.itinerary = activities; + customer.requestedStation = activities[0]; + customer.nextActivity(); } }