Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
LuxxArt committed Aug 19, 2024
2 parents f90bfd7 + 819b4ed commit 28d0937
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
29 changes: 22 additions & 7 deletions src/components/Employee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,40 @@ export class Employee extends Button {
this.currentCustomer = customer;
}

walkTo(targetX: number, targetY: number) {
walkTo(paths: Array<{x: number, y: number}>) {
// TODO: Replace with pathfinding algorithm

if(paths.length <= 0) return;

console.log("walkTo", paths);

const last = paths[paths.length-1]

// Temporary: set duration based on distance
const distance = Phaser.Math.Distance.Between(
this.x,
this.y,
targetX,
targetY
last.x,
last.y
);

const path = paths.reduce((path, pos) => {
return path.lineTo(pos.x, pos.y);
}, new Phaser.Curves.Path(this.x, this.y));

console.log(path);

// Add tween to move from current position to the target
this.scene.tweens.add({
targets: this,
x: targetX,
y: targetY,
this.scene.tweens.addCounter({
duration: 2 * distance,
ease: "Linear",

onUpdate: ({progress}) => {
const pos = path.getPoint(progress);
this.setX(pos.x);
this.setY(pos.y);
},

onComplete: () => {
this.emit("walkend");
},
Expand Down
42 changes: 19 additions & 23 deletions src/scenes/GameScene.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ export class GameScene extends BaseScene {

//this.stations.forEach((s) => s.returnItems());
this.sound.play("endday");
this.employees.forEach((e) => e.walkTo(e.startX, e.startY));
// Fix this later
// this.employees.forEach((e) => e.walkTo(e.startX, e.startY));
this.setState(GameState.Shopping);
}

Expand All @@ -409,8 +410,8 @@ export class GameScene extends BaseScene {
this.addCustomer(id);

// TODO: Adjust to difficulty
let delayMin = Math.max(1000, 5000 - 500 * this.day);
let delayMax = delayMin + 4000 - 500 * this.day;
let delayMin = Math.max(1000, 4000 - 400 * this.day);
let delayMax = delayMin + 5000 - 500 * this.day;
delay = Phaser.Math.Between(delayMin, delayMax);

console.log(`Customer spawned. Waiting ${delay} ms`);
Expand All @@ -430,16 +431,15 @@ export class GameScene extends BaseScene {
updateSpawnPool() {
this.customerSpawnPool = [];

const tier2StationCount = this.stations.filter(
(s) => s.stationTier >= 2 && s.hasBeenPurchased
).length;
const tier3StationCount = this.stations.filter(
(s) => s.stationTier >= 2 && s.hasBeenPurchased
).length;
this.stations.forEach((s) => {
if (s.hasBeenPurchased) {
if (s.stationTier >= 1) this.customerSpawnPool.push(CustomerId.Small);
if (s.stationTier >= 2) this.customerSpawnPool.push(CustomerId.Medium);
if (s.stationTier >= 3) this.customerSpawnPool.push(CustomerId.Large);
}
});

this.customerSpawnPool.push(CustomerId.Small);
if (tier2StationCount >= 2) this.customerSpawnPool.push(CustomerId.Medium);
if (tier3StationCount >= 2) this.customerSpawnPool.push(CustomerId.Large);
console.log("Spawn pool:", this.customerSpawnPool);
}

updateSavedPurchases() {
Expand Down Expand Up @@ -704,26 +704,22 @@ export class GameScene extends BaseScene {
customer.setEmployee(closestEmployee);

closestEmployee.setCustomer(customer);
closestEmployee.walkTo(x, y);

const [cx, cy] = centerOnSubdividedCoord(this.board, station, 7);

const posEmp = this.board.coordToGrid(closestEmployee.x, closestEmployee.y);
const posSta = this.board.coordToGrid(station.x, station.y);


console.log(posEmp, posSta)
const scale = ({gridX, gridY}: GridPoint) => {
return {x: gridX*7, y: gridY*7}
}

//this.navmesh.findPath({})

console.log(scale(posEmp))

const path = this.navmesh.findPath(scale(posEmp), scale(posSta));

const path = this.navmesh.findPath(scale(posEmp), scale(posSta))!.map((pos) =>
this.board.gridToCoord(pos.x/7, pos.y/7)
);

console.log(path)

console.log("path", path)
closestEmployee.walkTo(path);

// Wait for employee.on("walkend")
}
Expand Down
3 changes: 1 addition & 2 deletions src/utils/NavMeshHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ export function GenerateNavMesh(board: Board, level: Level) {
case BlockType.HornAndNails:
case BlockType.ScalePolish:
case BlockType.GoldBath:
case BlockType.CashRegister:
for(let sx = 0; sx < stationMask.length; sx++) {
for(let sy = 0; sy < stationMask.length; sy++) {
if(!stationMask[sx][sy]) {
nav[x*subdivision + sx][y*subdivision + sy] = false;
}
}
}
//case BlockType.CashRegister:
//this.addStation(x, y, StationId.CashRegister);
break;
}
}
Expand Down

0 comments on commit 28d0937

Please sign in to comment.