Skip to content

Commit

Permalink
Golen pls fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcticFqx committed Aug 19, 2024
1 parent 3f4119e commit 819b4ed
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 21 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
21 changes: 9 additions & 12 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 Down Expand Up @@ -703,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 819b4ed

Please sign in to comment.