2024-07-30 18:56:24 +00:00
|
|
|
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};
|
2024-08-02 14:01:51 +00:00
|
|
|
},
|
2024-08-05 17:36:41 +00:00
|
|
|
oppositeDirection(direction) {
|
|
|
|
if (direction === "left") { return "right" }
|
|
|
|
if (direction === "right") { return "left" }
|
|
|
|
if (direction === "up") { return "down" }
|
|
|
|
return "up";
|
|
|
|
},
|
|
|
|
|
2024-08-02 14:01:51 +00:00
|
|
|
emitEvent(name, detail) {
|
|
|
|
const event = new CustomEvent(name, {
|
|
|
|
detail
|
|
|
|
});
|
|
|
|
document.dispatchEvent(event);
|
|
|
|
|
2024-07-30 18:56:24 +00:00
|
|
|
}
|
|
|
|
}
|