boxes/js/world.mjs

32 lines
522 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 {
tiles: Array(BOX_SIZE).fill(0).map(_ => Array(BOX_SIZE).fill(0)),
};
2023-06-23 10:05:40 +00:00
}
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];
2023-06-23 10:05:40 +00:00
}
export function create_box (parent) {
return {
...create_world(BOX_SIZE),
parent,
};
2023-06-23 10:05:40 +00:00
}
export function get_root () {
return world;
}