ENTER: Close this Dialog, Interact with things on screen Arrow Keys: Movement (WASD or VIM keys also work)
Walk over to my resume and click ENTER',
'controls': 'Use ARROW KEYS or WASD or VIM keys (HJKL) to move around. Press the ENTER key to interact with what you see on the screen.
',
- 'resume': 'Walk over to the DESK and click on my RESUME. The RESUME is marked by the flashing red indicator light.
',
+ // 'resume': 'Walk over to the DESK and click on my RESUME. The RESUME is marked by the flashing red indicator light.
',
'portfolio': 'Thanks for looking at my Resume! Check out my PORTFOLIO by clicking on the BOOKSHELF. ',
'other': 'Now that you have looked through my Porfolio, go explore the rest of the site!
Click on the GUITAR to hear my music.
Mess around on the Terminal on the COMPUTER
And before you leave, go to the TV and play some of the games I have made!
Thanks for stopping by!'
}
diff --git a/assets/js/keystroke.js b/assets/js/keystroke.js
index 39fe698..c691a25 100644
--- a/assets/js/keystroke.js
+++ b/assets/js/keystroke.js
@@ -1,4 +1,4 @@
-function getKeystroke() {
+function getKeystroke(ignoreEnter=false) {
_listener = function (event) {
if (
["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight"].indexOf(
@@ -18,7 +18,9 @@ function getKeystroke() {
player.move('right')
} else if (
event.key === "Enter" &&
- !terminal.active
+ !terminal.active &&
+ !dialogMode &&
+ !ignoreEnter
) {
onEnter();
}
diff --git a/assets/js/pathfinder.js b/assets/js/pathfinder.js
new file mode 100644
index 0000000..d421c66
--- /dev/null
+++ b/assets/js/pathfinder.js
@@ -0,0 +1,164 @@
+const timer = ms => new Promise(res => setTimeout(res, ms))
+
+var cols = 8
+var rows = 8
+
+let grid = new Array(cols);
+
+let openSet = [];
+let closedSet = [];
+
+let start;
+let end;
+let path = [];
+
+function heuristic(position0, position1) {
+ let d1 = Math.abs(position1.x - position0.x);
+ let d2 = Math.abs(position1.y - position0.y);
+
+ return d1 + d2;
+}
+
+
+function GridPoint(x, y) {
+ this.x = x;
+ this.y = y;
+ this.f = 0;
+ this.g = 0;
+ this.h = 0;
+ this.neighbors = [];
+ this.parent = undefined;
+
+
+ this.updateNeighbors = function(grid) {
+ let i = this.x;
+ let j = this.y;
+ var tmpNeighbor;
+ if (i < cols - 1) {
+ tmpNeighbor = grid[i + 1][j]
+ if (!player.isBoundary([tmpNeighbor.x, tmpNeighbor.y])) {
+ this.neighbors.push(tmpNeighbor);
+ }
+ }
+ if (i > 0) {
+ tmpNeighbor = grid[i - 1][j]
+ if (!player.isBoundary([tmpNeighbor.x, tmpNeighbor.y])) {
+ this.neighbors.push(tmpNeighbor);
+ }
+ }
+ if (j < rows - 1) {
+ tmpNeighbor = grid[i][j + 1]
+ if (!player.isBoundary([tmpNeighbor.x, tmpNeighbor.y])) {
+ this.neighbors.push(tmpNeighbor);
+ }
+ }
+ if (j > 0) {
+ tmpNeighbor = grid[i][j - 1]
+ if (!player.isBoundary([tmpNeighbor.x, tmpNeighbor.y])) {
+ this.neighbors.push(tmpNeighbor);
+ }
+ }
+ };
+}
+
+
+function init(destX, destY) {
+
+ for (let i = 0; i < cols; i++) {
+ grid[i] = new Array(rows);
+ }
+
+ for (let i = 0; i < cols; i++) {
+ for (let j = 0; j < rows; j++) {
+ grid[i][j] = new GridPoint(i, j);
+ }
+ }
+
+ for (let i = 0; i < cols; i++) {
+ for (let j = 0; j < rows; j++) {
+ grid[i][j].updateNeighbors(grid);
+ }
+ }
+
+ start = grid[player.canvasX][player.canvasY];
+ end = grid[destX][destY]
+
+ openSet.push(start);
+
+ console.log(grid);
+}
+
+
+function search(destX, destY) {
+ path = [];
+ init(destX, destY);
+ while (openSet.length > 0) {
+
+ let lowestIndex = 0;
+ for (let i = 0; i < openSet.length; i++) {
+ if (openSet[i].f < openSet[lowestIndex].f) {
+ lowestIndex = i;
+ }
+ }
+ let current = openSet[lowestIndex];
+
+ if (current === end) {
+ let temp = current;
+ path.push(temp);
+ while (temp.parent) {
+ path.push(temp.parent);
+ temp = temp.parent;
+ }
+
+ return path.reverse()
+ }
+
+
+ openSet.splice(lowestIndex, 1);
+
+ closedSet.push(current);
+
+ let neighbors = current.neighbors;
+
+ for (let i = 0; i < neighbors.length; i++) {
+ let neighbor = neighbors[i];
+
+ if (!closedSet.includes(neighbor)) {
+ let possibleG = current.g + 1;
+
+ if (!openSet.includes(neighbor)) {
+ openSet.push(neighbor);
+ } else if (possibleG >= neighbor.g) {
+ continue;
+ }
+
+ neighbor.g = possibleG;
+ neighbor.h = heuristic(neighbor, end);
+ neighbor.f = neighbor.g + neighbor.h;
+ neighbor.parent = current;
+ }
+ }
+ }
+
+ return [];
+}
+
+async function pathfind(destX, destY) {
+ var newPath = search(destX, destY)
+ for (let i = 0; i < newPath.length; i++) {
+ if (newPath[i].x > player.canvasX) {
+ player.direction = 'right'
+ } else if (newPath[i].x < player.canvasX) {
+ player.direction = 'left'
+ }
+
+ if (newPath[i].y > player.canvasY) {
+ player.direction = 'down'
+ } else if (newPath[i].y < player.canvasY) {
+ player.direction = 'up'
+ }
+ player.canvasX = newPath[i].x
+ player.canvasY = newPath[i].y
+ await timer(100)
+ }
+}
diff --git a/index.html b/index.html
index 612084a..f9d6b81 100644
--- a/index.html
+++ b/index.html
@@ -21,6 +21,7 @@
+
@@ -29,6 +30,18 @@