Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LuxxArt committed Aug 17, 2024
2 parents 0fcb342 + b6de3c0 commit ecba8de
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 41 deletions.
Binary file modified src/assets/images/backgrounds/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/Board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ export class Board extends Phaser.GameObjects.Container {
this.size,
this.size,
0xffffff,
0.2,
0.1,
0x000000,
0.5
0.2
);
this.add(this.grid);

Expand Down
26 changes: 16 additions & 10 deletions src/components/Customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export class Customer extends Button {
public doingCuteThing: boolean;
public tasksCompleted: number;
public moneySpent: number;
public maxHappiness: number;
public happiness: number;

// Graphics
Expand All @@ -49,8 +48,7 @@ export class Customer extends Button {
this.doingCuteThing = false;
this.tasksCompleted = 0;
this.moneySpent = 0;
this.maxHappiness = 100;
this.happiness = 100;
this.happiness = 1;

/* Sprite */
const size = 150;
Expand All @@ -60,13 +58,18 @@ export class Customer extends Button {
this.sprite.setScale(size / this.sprite.width);
this.add(this.sprite);

this.thoughtBubble = new ThoughtBubble(scene, 0, -0.75 * size, size);
this.thoughtBubble = new ThoughtBubble(
scene,
0.2 * size,
-0.6 * size,
size
);
this.add(this.thoughtBubble);

this.happinessTimer = new Timer(
scene,
0.3 * size,
-0.4 * size,
-0.3 * size,
-0.3 * size,
0.6 * size,
0xfa9425
);
Expand All @@ -84,18 +87,21 @@ export class Customer extends Button {
const squish =
1.0 + wobble * Math.sin((6 * time) / 1000) - 0.2 * this.holdSmooth;
this.setScale(1.0, squish);
this.sprite.setTint(
interpolateColor(0xffffff, 0xff0000, 1 - this.happiness)
);

if (this.isWaiting) {
this.happinessTimer.setVisible(true);
if (!this.dragged) {
this.happiness -= (100 / 20) * (delta / 1000);
// 20 seconds
this.happiness -= (1 / 20) * (delta / 1000);
}

const factor = this.happiness / this.maxHappiness;
this.happinessTimer.setColor(
interpolateColor(0xff0000, 0x00ff00, factor)
interpolateColor(0xff0000, 0x00ff00, this.happiness)
);
this.happinessTimer.redraw(factor);
this.happinessTimer.redraw(this.happiness);

if (this.happiness <= 0) {
this.leave();
Expand Down
5 changes: 3 additions & 2 deletions src/components/Station.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const StationTypeColors: { [key in StationType]: number } = {
export const StationDuration: { [key in StationType]: number } = {
[StationType.WaitingSeat]: 0,
[StationType.HornAndNails]: 3000,
[StationType.ScalePolish]: 4000,
[StationType.GoldBath]: 2000,
[StationType.ScalePolish]: 2000,
[StationType.GoldBath]: 4000,
[StationType.CashRegister]: 500,
};

Expand Down Expand Up @@ -62,6 +62,7 @@ export class Station extends Button {
text: "Available",
});
this.text.setOrigin(0.5);
this.text.setVisible(false);
this.text.setStroke("#000000", 4);
this.add(this.text);

Expand Down
48 changes: 34 additions & 14 deletions src/components/UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,50 @@ export class UI extends Phaser.GameObjects.Container {

private panel: Phaser.GameObjects.Container;
private background: Phaser.GameObjects.Image;
private moneyText: Phaser.GameObjects.Text;
private dayText: Phaser.GameObjects.Text;
private dayProgressTimer: Timer;
private dayText: Phaser.GameObjects.Text;
private moneyText: Phaser.GameObjects.Text;

constructor(scene: GameScene) {
super(scene, 0, 0);
scene.add.existing(this);
this.scene = scene;

const panelHeight = 200;
const panelWidth = 300;
const panelHeight = 400;

this.panel = this.scene.add.container(0, 0);
this.panel = this.scene.add.container(
scene.W - panelWidth / 2,
panelHeight / 2
);
this.add(this.panel);

this.background = this.scene.add.image(0, 0, "hud");
this.background.setScale(panelHeight / this.background.height);
this.background.setVisible(false);
this.panel.add(this.background);
// this.background = this.scene.add.image(0, 0, "hud");
// this.background.setScale(panelHeight / this.background.height);
// this.background.setVisible(false);
// this.panel.add(this.background);
const rect = this.scene.add.rectangle(
0,
0,
panelWidth,
panelHeight,
0x000000,
0.5
);
this.panel.add(rect);

this.dayProgressTimer = new Timer(
scene,
0,
-0.3 * panelHeight,
200,
0xff7700
);
this.panel.add(this.dayProgressTimer);

this.dayText = this.scene.addText({
x: 100,
y: 200,
x: 0,
y: 0,
size: 60,
color: "#FFFFFF",
text: "Day 1",
Expand All @@ -38,16 +60,14 @@ export class UI extends Phaser.GameObjects.Container {

this.moneyText = this.scene.addText({
x: 0,
y: 240,
y: 0.3 * panelHeight,
size: 40,
color: "#FFFFFF",
text: "Money: $0",
});
this.moneyText.setStroke("black", 4);
this.moneyText.setOrigin(0.5);
this.panel.add(this.moneyText);

this.dayProgressTimer = new Timer(scene, 100, 100, 200, 0xff7700);
this.add(this.dayProgressTimer);
}

update(time: number, delta: number) {}
Expand Down
45 changes: 32 additions & 13 deletions src/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class GameScene extends BaseScene {

// Game stats
private day: number = 0;
private dayDuration: number = 60000; // 1 minute
private timeOfDay: number = 0;
private money: number = 0;

Expand All @@ -35,20 +36,31 @@ export class GameScene extends BaseScene {
this.background.setOrigin(0);
this.fitToScreen(this.background);

this.board = new Board(this, 900, 500);
this.board = new Board(this, 930, 550);

this.stations = [];
this.addStation(0, 0, StationType.WaitingSeat);
this.addStation(1, 0, StationType.WaitingSeat);
this.addStation(2, 0, StationType.WaitingSeat);
this.addStation(1, 2, StationType.HornAndNails);
this.addStation(0, 1, StationType.WaitingSeat);
this.addStation(0, 2, StationType.WaitingSeat);
this.addStation(0, 3, StationType.WaitingSeat);
this.addStation(2, 2, StationType.HornAndNails);
this.addStation(3, 2, StationType.HornAndNails);
this.addStation(5, 1, StationType.ScalePolish);
this.addStation(5, 3, StationType.GoldBath);
this.addStation(7, 5, StationType.CashRegister);
this.addStation(4, 2, StationType.HornAndNails);
this.addStation(2, 0, StationType.HornAndNails);
this.addStation(3, 0, StationType.HornAndNails);
this.addStation(4, 0, StationType.HornAndNails);
this.addStation(6, 1, StationType.ScalePolish);
this.addStation(7, 1, StationType.ScalePolish);
this.addStation(6, 3, StationType.GoldBath);
this.addStation(7, 3, StationType.GoldBath);
this.addStation(2, 4, StationType.GoldBath);
this.addStation(3, 4, StationType.GoldBath);
this.addStation(5, 5, StationType.CashRegister);

this.employees = [];
this.addEmployee(0, 5);
this.addEmployee(1, 5);
this.addEmployee(2, 5);
this.addEmployee(3, 5);

this.customers = [];
Expand Down Expand Up @@ -78,7 +90,7 @@ export class GameScene extends BaseScene {
this.tweens.add({
targets: this,
timeOfDay: { from: 1, to: 0 },
duration: 3 * 60 * 1000,
duration: this.dayDuration,
onUpdate: (tween) => {
this.timeOfDay = tween.getValue();
this.ui.setTimeOfDay(this.timeOfDay);
Expand All @@ -87,6 +99,18 @@ export class GameScene extends BaseScene {
this.endDay();
},
});

// Spawn customers every 3 seconds
this.time.addEvent({
delay: 3000,
callback: () => {
// Spawn new customer if shop is still open
if (this.timeOfDay > 0 && this.getAvailableWaitingSeat()) {
this.addCustomer();
}
},
loop: true,
});
}

endDay() {}
Expand Down Expand Up @@ -205,11 +229,6 @@ export class GameScene extends BaseScene {
customer.on("offscreen", () => {
this.customers = this.customers.filter((c) => c !== customer);
customer.destroy();

// Spawn new customer if shop is still open
if (this.timeOfDay > 0 && this.getAvailableWaitingSeat()) {
this.addCustomer();
}
});

// Customer completing their itinerary and paying
Expand Down

0 comments on commit ecba8de

Please sign in to comment.