Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NightLightLumie committed Aug 16, 2024
2 parents 49a0adb + 76e8420 commit 8720675
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 9 deletions.
39 changes: 39 additions & 0 deletions src/components/Customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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");
},
});
}
}
12 changes: 9 additions & 3 deletions src/components/Station.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,6 +35,7 @@ export class Station extends Button {

this.currentCustomer = null;
this.taskDuration = 3000;
this.admissionFee = 10;

/* Sprite */
const size = 150;
Expand Down
46 changes: 40 additions & 6 deletions src/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
});
}
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 8720675

Please sign in to comment.