90ff4fe2ff
added changing maps all done like this https://www.youtube.com/watch?v=U7fYOnedjzs&list=PLcjhmZ8oLT0r9dSiIK6RB_PuBWlG1KSq_&index=9
39 lines
744 B
JavaScript
39 lines
744 B
JavaScript
const utils = {
|
|
withGrid(n) {
|
|
return n * 16;
|
|
},
|
|
asGridCoord(x, y) {
|
|
return `${x*16},${y*16}`
|
|
},
|
|
nextPosition(initialX, initialY, direction) {
|
|
let x = initialX;
|
|
let y = initialY;
|
|
const size = 16;
|
|
|
|
if (direction === "left") {
|
|
x -= size;
|
|
} else if (direction === "right") {
|
|
x += size;
|
|
} else if (direction === "up") {
|
|
y -= size;
|
|
} else if (direction === "down") {
|
|
y += size;
|
|
}
|
|
|
|
return {x, y};
|
|
},
|
|
oppositeDirection(direction) {
|
|
if (direction === "left") { return "right" }
|
|
if (direction === "right") { return "left" }
|
|
if (direction === "up") { return "down" }
|
|
return "up";
|
|
},
|
|
|
|
emitEvent(name, detail) {
|
|
const event = new CustomEvent(name, {
|
|
detail
|
|
});
|
|
document.dispatchEvent(event);
|
|
|
|
}
|
|
} |