diff --git a/js/world.mjs b/js/world.mjs index f5e0191..5a6116a 100644 --- a/js/world.mjs +++ b/js/world.mjs @@ -11,10 +11,12 @@ function create_world (size) { const world = create_world(BOX_SIZE); export function set_tile (world, x, y, tile) { + if (out_of_bounds(x, y)) return; world.tiles[x][y] = tile; } export function get_tile (world, x, y) { + if (out_of_bounds(x, y)) return { type: "out_of_bounds" }; return world.tiles[x][y]; } @@ -25,7 +27,11 @@ export function create_box (parent) { }; } - export function get_root () { return world; } + +export function out_of_bounds (x, y) { + return x < 0 || x >= BOX_SIZE || + y < 0 || y >= BOX_SIZE +}