boxes/js/world.mjs
2023-06-24 14:15:27 +02:00

37 lines
703 B
JavaScript

export const BOX_SIZE = 9;
export const CENTER = Math.floor(BOX_SIZE / 2);
function create_world (size) {
return Array(BOX_SIZE).fill(0).map(_ => Array(BOX_SIZE).fill(0));
}
const world = create_world(BOX_SIZE);
const parent_stack = [];
let current_world = world;
export function set_tile (x, y, tile) {
current_world[x][y] = tile;
}
export function get_tile (x, y) {
return current_world[x][y];
}
export function create_box () {
return create_world(BOX_SIZE);
}
export function enter_box (box) {
parent_stack.push(current_world);
current_world = box;
}
export function exit_box () {
if (parent_stack.length > 0) {
current_world = parent_stack.pop();
return true;
}
return false;
}