Add missing boundary checks to interior map generation

This commit is contained in:
kayomn 2023-02-09 11:11:48 +00:00
parent ee37075778
commit 200f0939c3
3 changed files with 12 additions and 9 deletions

Binary file not shown.

View File

@ -95,15 +95,18 @@ class Chunk:
# Find floor tile types. # Find floor tile types.
for y in _CHUNK_SIZE: for y in _CHUNK_SIZE:
for x in _CHUNK_SIZE: for x in _CHUNK_SIZE:
if floor_map.get_bitv(offset + Vector2i(x, y)): var map_area := Rect2i(Vector2.ZERO, map_size)
var map_coordinates := offset + Vector2i(x, y)
if map_area.has_point(map_coordinates) and floor_map.get_bitv(map_coordinates):
var tile := 0 var tile := 0
for i in Orientation.values().size(): for i in Orientation.values().size():
var delta_x := roundi(cos(i * PI / 2.0)) var map_neighbor := map_coordinates + Vector2i(
var delta_y := roundi(sin(i * PI / 2.0)) roundi(cos(i * PI / 2.0)), roundi(sin(i * PI / 2.0)))
if (0 <= (y + int(delta_y < map_size.y))) and (0 <= (x + int(delta_x < map_size.x))): if map_area.has_point(map_neighbor):
tile += int(floor_map.get_bit(x + delta_x, y + delta_y)) * 2 ** i tile += int(floor_map.get_bitv(map_neighbor)) * 2 ** i
positions_by_floor_tile[tile].append(Vector2(x, y)) positions_by_floor_tile[tile].append(Vector2(x, y))

BIN
map_editor.scn (Stored with Git LFS)

Binary file not shown.