Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LuxxArt committed Aug 18, 2024
2 parents 11b16d5 + 8253826 commit 1fdb61e
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 61 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
},
"dependencies": {
"@neutralinojs/lib": "^5.3.0",
"navmesh": "^2.3.1",
"phaser": "^3.80.1",
"phaser3-rex-plugins": "^1.80.6"
},
Expand Down
Binary file modified src/assets/images/backgrounds/grid2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 13 additions & 1 deletion src/components/Board.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { GameScene } from "@/scenes/GameScene";

export type GridPoint = {
gridX: number,
gridY: number
};

export class Board extends Phaser.GameObjects.Container {
public scene: GameScene;
public size: number;
public width: number;
public height: number;

private grid: Phaser.GameObjects.Grid;
private things: any[];
Expand All @@ -21,6 +28,9 @@ export class Board extends Phaser.GameObjects.Container {

// this.size = scene.H / (height + 2);
this.size = cellSize;
this.width = width;
this.height = height

this.grid = this.scene.add.grid(
0,
0,
Expand All @@ -44,6 +54,8 @@ export class Board extends Phaser.GameObjects.Container {
resize(width: number, height: number, cellSize: number) {
// this.size = this.scene.H / height;
this.size = cellSize;
this.width = width;
this.height = height

this.grid.destroy();
this.grid = this.scene.add.grid(
Expand All @@ -70,7 +82,7 @@ export class Board extends Phaser.GameObjects.Container {
}

// Return grid cell of the coordinates
coordToGrid(x: number, y: number) {
coordToGrid(x: number, y: number): GridPoint {
const gridX = Math.floor((x - this.x + this.grid.width / 2) / this.size);
const gridY = Math.floor((y - this.y + this.grid.height / 2) / this.size);
return { gridX, gridY };
Expand Down
27 changes: 23 additions & 4 deletions src/components/Employee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { EmployeeData, EmployeeId, EmployeeType } from "./EmployeeData";

export class Employee extends Button {
public employeeId: EmployeeId;
public hasBeenPurchased: boolean;
public currentCustomer: Customer | null;
public doingCuteThing: boolean;

Expand Down Expand Up @@ -33,6 +34,9 @@ export class Employee extends Button {
this.startX = x;
this.startY = y;

// Initially not purchased
this.hasBeenPurchased = false;

/* Sprite */
this.spriteCont = this.scene.add.container(0, this.spriteOffset);
this.add(this.spriteCont);
Expand All @@ -48,13 +52,17 @@ export class Employee extends Button {
}

update(time: number, delta: number) {
const factor = this.doingCuteThing ? 0.1 : 0.02;
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);
}

setCustomer(customer: Customer | null) {
if(customer){
if (customer) {
this.scene.sound.play("sqk");
}

Expand Down Expand Up @@ -95,7 +103,12 @@ export class Employee extends Button {
}

upgrade() {
if (this.upgradeTo) {
// this.scene.sound.play("upgrade");

if (!this.hasBeenPurchased) {
this.hasBeenPurchased = true;
this.setAlpha(1.0);
} else if (this.upgradeTo) {
this.employeeId = this.upgradeTo!;
this.sprite.setTexture(this.spriteKey);
}
Expand Down Expand Up @@ -140,7 +153,13 @@ export class Employee extends Button {
}

get upgradeCost(): number {
return EmployeeData[this.employeeId].upgradeCost ?? 0;
if (!this.hasBeenPurchased) {
return EmployeeData[this.employeeId].cost;
}
if (this.upgradeTo) {
return EmployeeData[this.upgradeTo].cost;
}
return 0;
}

get upgradeTo(): EmployeeId | undefined {
Expand Down
12 changes: 7 additions & 5 deletions src/components/EmployeeData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface EmployeeInterface {
spriteKey: string; // Employee image key
walkSpeed: number; // Speed of the employee walking
workSpeed: number; // Speed of the employee working
upgradeCost?: number; // Cost to upgrade the employee
cost: number; // Cost to purchase that tier of employee
upgradeTo?: EmployeeId; // Employee to upgrade to
}

Expand All @@ -35,7 +35,7 @@ export const EmployeeData: { [key in EmployeeId]: EmployeeInterface } = {
spriteKey: "worker",
walkSpeed: 1,
workSpeed: 1,
upgradeCost: 100,
cost: 1000,
upgradeTo: EmployeeId.RaccoonTier2,
},
[EmployeeId.RaccoonTier2]: {
Expand All @@ -45,7 +45,7 @@ export const EmployeeData: { [key in EmployeeId]: EmployeeInterface } = {
spriteKey: "worker",
walkSpeed: 2,
workSpeed: 2,
upgradeCost: 500,
cost: 400,
upgradeTo: EmployeeId.RaccoonTier3,
},
[EmployeeId.RaccoonTier3]: {
Expand All @@ -55,6 +55,7 @@ export const EmployeeData: { [key in EmployeeId]: EmployeeInterface } = {
spriteKey: "worker",
walkSpeed: 3,
workSpeed: 3,
cost: 800,
},

[EmployeeId.HumanTier1]: {
Expand All @@ -64,7 +65,7 @@ export const EmployeeData: { [key in EmployeeId]: EmployeeInterface } = {
spriteKey: "player",
walkSpeed: 1,
workSpeed: 1,
upgradeCost: 100,
cost: 1000,
upgradeTo: EmployeeId.HumanTier2,
},
[EmployeeId.HumanTier2]: {
Expand All @@ -74,7 +75,7 @@ export const EmployeeData: { [key in EmployeeId]: EmployeeInterface } = {
spriteKey: "player",
walkSpeed: 2,
workSpeed: 2,
upgradeCost: 500,
cost: 400,
upgradeTo: EmployeeId.HumanTier3,
},
[EmployeeId.HumanTier3]: {
Expand All @@ -84,5 +85,6 @@ export const EmployeeData: { [key in EmployeeId]: EmployeeInterface } = {
spriteKey: "player",
walkSpeed: 3,
workSpeed: 3,
cost: 800,
},
};
10 changes: 5 additions & 5 deletions src/components/Levels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ export const LevelData: Level[] = [
cellSize: 190,
grid: [
[X, X, X, X, X, X, X, X],
[X, 2, _, 9, 9, _, 4, X],
[X, 2, _, 3, 3, _, 4, X],
[X, 2, _, _, _, _, 4, X],
[_, _, _, 5, 5, _, _, X],
[X, 9, 9, _, _, 6, _, _],
[_, _, _, _, _, _, _, X],
[X, _, 5, 5, _, 6, _, _],
[X, X, X, X, X, X, X, X],
],
customerArrivalTimes: [0, 10, 20, 30, 40, 50, 60, 70, 80, 90],
Expand All @@ -67,10 +67,10 @@ export const LevelData: Level[] = [
},
{
id: LevelId.Level3,
background: "grid3",
background: "grid2",
width: 8 + 2,
height: 6 + 2,
cellSize: 109,
cellSize: 138,
grid: [
[X, X, X, X, X, X, X, X, X, X],
[X, 2, _, _, _, _, _, _, _, X],
Expand Down
35 changes: 26 additions & 9 deletions src/components/Station.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { TextEffect } from "./TextEffect";

export class Station extends Button {
public stationId: StationId;
public hasBeenPurchased: boolean;
public currentCustomer: Customer | null; // The customer using the station
//public taskDuration: number; // Time it takes to complete a task
public taskSpeed: number = 1; // For permanent bonuses

//temp variables
Expand Down Expand Up @@ -54,6 +54,9 @@ export class Station extends Button {
this.cellSize = cellSize;
this.currentCustomer = null;

// Initially not purchased
this.hasBeenPurchased = false;

/* Sprite */
this.spriteCont = this.scene.add.container(0, this.spriteOffset);
this.add(this.spriteCont);
Expand Down Expand Up @@ -109,7 +112,8 @@ export class Station extends Button {
}

update(time: number, delta: number) {
const squish = 1.0 + 0.02 * Math.sin((6 * time) / 1000);
const amount = this.hasBeenPurchased ? 0.02 : 0;
const squish = 1.0 + amount * Math.sin((6 * time) / 1000);
this.spriteCont.setScale(1.0, squish - 0.2 * this.holdSmooth);
}

Expand All @@ -124,7 +128,7 @@ export class Station extends Button {
? (this.taskHaste *= this.currentCustomer.workMultiplier)
: (this.taskHaste *= 1);
this.parseItems();
if(this.queueFail) {
if (this.queueFail) {
this.scene.sound.play("rip");
} else {
this.playJingle();
Expand Down Expand Up @@ -222,7 +226,12 @@ export class Station extends Button {
}

upgrade() {
if (this.upgradeTo) {
// this.scene.sound.play("upgrade");

if (!this.hasBeenPurchased) {
this.hasBeenPurchased = true;
this.setAlpha(1.0);
} else if (this.upgradeTo) {
this.stationId = this.upgradeTo!;
this.sprite.setTexture(this.spriteKey);
this.spriteCont.y = this.spriteOffset;
Expand Down Expand Up @@ -280,15 +289,17 @@ export class Station extends Button {
//this.scene.sound.play("meme_explosion_sound");
}

playJingle(){
switch(this.stationType){
playJingle() {
switch (this.stationType) {
case StationType.ScalePolish: {
this.scene.sound.play("polish");
break;
} case StationType.GoldBath: {
}
case StationType.GoldBath: {
this.scene.sound.play("goldbath");
break;
} case StationType.HornAndNails: {
}
case StationType.HornAndNails: {
this.scene.sound.play("snip");
break;
}
Expand Down Expand Up @@ -334,7 +345,13 @@ export class Station extends Button {
}

get upgradeCost(): number {
return StationData[this.stationId].upgradeCost ?? 0;
if (!this.hasBeenPurchased) {
return StationData[this.stationId].cost;
}
if (this.upgradeTo) {
return StationData[this.upgradeTo].cost;
}
return 0;
}

get upgradeTo(): StationId | undefined {
Expand Down
Loading

0 comments on commit 1fdb61e

Please sign in to comment.