boxes/js/world.mjs

37 lines
703 B
JavaScript
Raw Normal View History

export const BOX_SIZE = 9;
2023-06-23 10:05:40 +00:00
export const CENTER = Math.floor(BOX_SIZE / 2);
2023-06-23 10:05:40 +00:00
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) {
2023-06-23 10:05:40 +00:00
current_world[x][y] = tile;
}
export function get_tile (x, y) {
2023-06-23 10:05:40 +00:00
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;
}