Skip to content

Commit

Permalink
Adding debugging info for pathfinding
Browse files Browse the repository at this point in the history
  • Loading branch information
agitperson committed Jan 1, 2018
1 parent d3447e0 commit 6809aa6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/core/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Map {
grid: null, // a 0/1 grid of blocked tiles
finder: new PF.DijkstraFinder(),
current: {
name: '',
length: 0, // Number of steps in current path
path: {
walking: [], // Current path walking
Expand Down Expand Up @@ -47,6 +48,7 @@ class Map {
grid: null,
finder: new PF.DijkstraFinder(),
current: {
name: '',
length: 0,
path: {
walking: [],
Expand Down Expand Up @@ -119,6 +121,7 @@ class Map {
this.path.current.path.set = path;
this.path.current.length = path.length;
this.path.current.step = 0;
this.path.current.name = window.btoa(Math.random()).slice(-4);

// We start moving the player along their path
this.player.walkPath(this.path.current, this);
Expand Down
2 changes: 1 addition & 1 deletion src/core/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Player {
if (!this.checkCollision(map, direction)) {
this.y += 1;
}

break;
}

Expand Down Expand Up @@ -79,6 +78,7 @@ class Player {
// so that the setTimeouts queue up and do not mix with each other
(() => {
setTimeout(() => {
console.log('Timestamp:', path.name, '- Step', (path.step + 1), '/', (path.length - 1));
if (!onStep.loop || onStep.last === onStep.loop) {
// If equal, it means our last step is the same as from
// when our pathfinding first started, so we keep going.
Expand Down

0 comments on commit 6809aa6

Please sign in to comment.