boxes/js/world.mjs

31 lines
522 B
JavaScript

export const BOX_SIZE = 9;
export const CENTER = Math.floor(BOX_SIZE / 2);
function create_world (size) {
return {
tiles: Array(BOX_SIZE).fill(0).map(_ => Array(BOX_SIZE).fill(0)),
};
}
const world = create_world(BOX_SIZE);
export function set_tile (world, x, y, tile) {
world.tiles[x][y] = tile;
}
export function get_tile (world, x, y) {
return world.tiles[x][y];
}
export function create_box (parent) {
return {
...create_world(BOX_SIZE),
parent,
};
}
export function get_root () {
return world;
}