Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NightLightLumie committed Aug 20, 2024
2 parents c9a7626 + 4e9b032 commit 40fd9f6
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 32 deletions.
2 changes: 2 additions & 0 deletions src/assets/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ const audios: Audio[] = [
sound('goldbath', 'goldbath', 0.5),
sound('fail', 'rip', 0.5),
sound('sqk', 'sqk', 0.5),
sound('squish1', 'squish1', 0.5),
sound('squish2', 'squish2', 0.5),
sound('endday', 'endday', 0.5),
sound('chomp', 'chomp', 0.5),
sound('bite', 'bite', 0.5),
Expand Down
Binary file modified src/assets/images/ui/bubble.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/sounds/squish1.mp3
Binary file not shown.
Binary file added src/assets/sounds/squish2.mp3
Binary file not shown.
12 changes: 8 additions & 4 deletions src/components/Customer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export class Customer extends Button {
this.sprList = [];

this.bindInteractive(this.sprite, true);
this.sprite.input!.enabled = false;
}

update(time: number, delta: number) {
Expand Down Expand Up @@ -234,10 +235,10 @@ export class Customer extends Button {
);
this.emit("pay", this.moneySpent);
} else {
this.scene.sound.play("rip", { volume: 0.4 });
this.scene.sound.play("rip", { volume: 0.3 });
}
} else {
this.scene.sound.play("rip", { volume: 0.4 });
this.scene.sound.play("rip", { volume: 0.3 });
}
this.leave();
this.thoughtBubble.showSymbol("sad");
Expand Down Expand Up @@ -268,7 +269,7 @@ export class Customer extends Button {
}
}
if (this.playFail) {
this.scene.sound.play("rip", { volume: 0.4 });
this.scene.sound.play("rip", { volume: 0.3 });
this.playFail = false;
}
}
Expand Down Expand Up @@ -385,6 +386,7 @@ export class Customer extends Button {
this.sprite.setTexture(this.spriteKeys.sit);
this.sprite.flipX = false;
this.hasEnteredShop = true;
this.sprite.input!.enabled = true;
this.scene.sound.play("letgo1", { volume: 0.2 });
this.emit("seated");
},
Expand Down Expand Up @@ -420,7 +422,7 @@ export class Customer extends Button {
this.untoggleTimer();
this.lockTimer();
}
this.thoughtBubble.showSymbol(Phaser.Math.RND.pick(["happy", "love"]));
this.thoughtBubble.showSymbol("love");
}

setAction(temp: boolean) {
Expand Down Expand Up @@ -511,6 +513,8 @@ export class Customer extends Button {
this.emit("offscreen");
},
});

// this.scene.moveCustomerToEntrance(this);
}
recheckHappiness() {
if (this.hasCompleted) {
Expand Down
1 change: 1 addition & 0 deletions src/components/PatienceTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class PatienceTimer extends Phaser.GameObjects.Container {
this.sparks = new Phaser.GameObjects.Sprite(this.scene,0,64,"defaultspark");
this.sparks.setTint(0x00FF00);
this.sparks.setScale(0.5);
this.anger.setVisible(false);

this.add(this.bar);
this.add(this.sparks);
Expand Down
9 changes: 7 additions & 2 deletions src/components/UI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { TextButton } from "./TextButton";
import { Level } from "./Levels";
import { RoundRectangle } from "./elements/RoundRectangle";
import { numberWithCommas } from "@/utils/functions";
import { Color, ColorStr } from "@/utils/colors";

export class UI extends Phaser.GameObjects.Container {
public scene: GameScene;
Expand Down Expand Up @@ -56,7 +57,7 @@ export class UI extends Phaser.GameObjects.Container {
this.clockText = this.scene.addText({
x: 0,
y: this.dayProgressTimer.y,
size: 40,
size: 35,
color: "#FFFFFF",
text: "09:00",
});
Expand Down Expand Up @@ -124,13 +125,17 @@ export class UI extends Phaser.GameObjects.Container {

const startHour = 9;
const endHour = 16;
const hour = endHour - time * (endHour - startHour);
const hour = startHour + time * (endHour - startHour);
const minute = (hour % 1) * 60;
const hourStr = Math.floor(hour).toString().padStart(2, "0");
const minuteStr = (Math.floor(minute / 10) * 10)
.toString()
.padStart(2, "0");
this.clockText.setText(`${hourStr}:${minuteStr}`);

if (time == 1) {
this.clockText.setText(`Closed`);
}
}

setLevel(level: Level) {
Expand Down
87 changes: 61 additions & 26 deletions src/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class GameScene extends BaseScene {

this.ui = new UI(this);
this.ui.setDepth(1000);
this.ui.setTimeOfDay(1);
this.ui.on("nextDay", () => {
if (this.inventory.isOpen) this.toggleInventory();
this.startDay();
Expand Down Expand Up @@ -514,7 +515,7 @@ export class GameScene extends BaseScene {
this.sound.play("endday", { volume: 0.2 });
},
onUpdate: (tween) => {
this.ui.setTimeOfDay(1 - this.timeOfDay / 100);
this.ui.setTimeOfDay(this.timeOfDay / 100);
},
onComplete: () => {
this.sound.play("endday", { volume: 0.2 });
Expand Down Expand Up @@ -698,29 +699,7 @@ export class GameScene extends BaseScene {
customer.setStation(seat);
// customer.snapTo(seat.x, seat.y);

// Pathfinding to seat
const startY = LevelData[this.level].height - 3;
const startCoord = this.board.gridToCoord(0, startY);
const start = this.board.coordToNav(startCoord.x, startCoord.y);
const goal = this.board.coordToNav(seat.x, seat.y);

// Starting location outside of screen
customer.snapTo(startCoord.x - 2 * this.board.size, startCoord.y, true);

const navPath = this.navmesh.findPath(start, goal);
if (navPath) {
const points = navPath.map((pos) =>
this.board.navGridToCoord(pos.x, pos.y)
);
const path = new Phaser.Curves.Path();
path.moveTo(customer.x, customer.y);
points.forEach((point) => path.lineTo(point.x, point.y));

customer.walk(path);
} else {
// Snap to station if pathfinding fails
console.warn("No path found", start, "->", goal);
}
this.moveCustomerToSeat(customer, seat);
} else {
console.error("Whoops");
}
Expand Down Expand Up @@ -778,7 +757,11 @@ export class GameScene extends BaseScene {
customer.destroy();

// Open overlay if no more customers
if (this.customers.length === 0) {
if (
this.state == GameState.Day &&
this.timeOfDay >= 100 &&
this.customers.length === 0
) {
this.endDay();
}
});
Expand Down Expand Up @@ -919,7 +902,59 @@ export class GameScene extends BaseScene {
closestEmployee.walk(path);
}
} else {
this.sound.play("sqk", { volume: 0.6 });
this.sound.play("squish1", { volume: 0.6 });
}
}

moveCustomerToSeat(customer: Customer, seat: Station) {
// Pathfinding to seat
const startY = LevelData[this.level].height - 3;
const startCoord = this.board.gridToCoord(0, startY);
const start = this.board.coordToNav(startCoord.x, startCoord.y);
const goal = this.board.coordToNav(seat.x, seat.y);

// Starting location outside of screen
customer.snapTo(startCoord.x - 2 * this.board.size, startCoord.y, true);

const navPath = this.navmesh.findPath(start, goal);
if (navPath) {
const points = navPath.map((pos) =>
this.board.navGridToCoord(pos.x, pos.y)
);
const path = new Phaser.Curves.Path();
path.moveTo(customer.x, customer.y);
points.forEach((point) => path.lineTo(point.x, point.y));

customer.walk(path);
} else {
const path = new Phaser.Curves.Path();
path.moveTo(customer.x, customer.y);
path.lineTo(seat.x, seat.y);
}
}

moveCustomerToEntrance(customer: Customer) {
// Pathfinding to left entrance
const doorY = LevelData[this.level].height - 3;
const doorCoord = this.board.gridToCoord(0, doorY);
const goal = this.board.coordToNav(doorCoord.x, doorCoord.y);
const start = this.board.coordToNav(customer.x, customer.y);

const navPath = this.navmesh.findPath(start, goal);
if (navPath) {
const points = navPath.map((pos) =>
this.board.navGridToCoord(pos.x, pos.y)
);
const path = new Phaser.Curves.Path();
path.moveTo(customer.x, customer.y);
points.forEach((point) => path.lineTo(point.x, point.y));
path.lineTo(-this.board.size, doorCoord.y);

customer.walk(path);
} else {
const path = new Phaser.Curves.Path();
path.moveTo(customer.x, customer.y);
path.lineTo(doorCoord.x, doorCoord.y);
}
}

Expand Down

0 comments on commit 40fd9f6

Please sign in to comment.