Now About Social Code
summaryrefslogtreecommitdiff
path: root/scripts/bsp_level_generator.gd
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/bsp_level_generator.gd')
-rw-r--r--scripts/bsp_level_generator.gd44
1 files changed, 30 insertions, 14 deletions
diff --git a/scripts/bsp_level_generator.gd b/scripts/bsp_level_generator.gd
index 6985469..57778d4 100644
--- a/scripts/bsp_level_generator.gd
+++ b/scripts/bsp_level_generator.gd
@@ -7,7 +7,7 @@ extends Node3D
@export_category("Geometry Generator")
## Geometry generation config
-@export var wall_thickness: float = 1.3
+@export var wall_thickness: float = 1
@onready var mesh: MeshInstance3D = $MeshInstance3D
enum Direction {LEFT, RIGHT}
@@ -63,6 +63,29 @@ func generate_level(axis: int, min_space: Vector2i, max_space: Vector2i, depth:
func is_leaf(node: BSPNode) -> bool:
return node.left == null and node.right == null
+
+func check_door(grid: Array[Tile.Tile], axis: int, door_pos: Vector2i) -> bool:
+ var other_axis = (axis + 1) % 2
+ door_pos[other_axis] += 1
+
+ var room_left = door_pos
+ room_left[axis] -= 1
+
+ var room_right = door_pos
+ room_right[axis] += 1
+
+ if door_pos.x > grid_width or door_pos.y > grid_height:
+ return false
+ if room_left.x > grid_width or room_left.y > grid_height:
+ return false
+ if room_right.x > grid_width or room_right.y > grid_height:
+ return false
+
+ # Check if there are two spaces to connect
+ # And ensure no door already exists in the space
+ return grid[room_left.y * grid_width + room_left.x] == Tile.Tile.FLOOR \
+ and grid[room_right.y * grid_width + room_right.x] == Tile.Tile.FLOOR \
+ and grid[door_pos.y * grid_width + door_pos.x] == Tile.Tile.WALL
func generate_grid(map: BSPNode, grid: Array[Tile.Tile]) -> void:
if is_leaf(map):
@@ -84,24 +107,17 @@ func generate_grid(map: BSPNode, grid: Array[Tile.Tile]) -> void:
var door_pos = Vector2i.ZERO
door_pos[map.axis] = split_axis
door_pos[other_axis] = test_door + 1
+ var door_pos2 = door_pos
+ door_pos[other_axis] += 1
- var room_left = door_pos
- room_left[map.axis] -= 1
-
- var room_right = door_pos
- room_right[map.axis] += 1
-
- # Check if there are two spaces to connect
- # And ensure no door already exists in the space
- if grid[room_left.y * grid_width + room_left.x] == Tile.Tile.FLOOR \
- and grid[room_right.y * grid_width + room_right.x] == Tile.Tile.FLOOR \
- and grid[door_pos.y * grid_width + door_pos.x] == Tile.Tile.WALL:
+ if check_door(grid, map.axis, door_pos) and check_door(grid, map.axis, door_pos2):
have_door = true
# Place grid for mesh
grid[door_pos.y * grid_width + door_pos.x] = Tile.Tile.FLOOR
- door_pos[map.axis] -= 1
- grid[door_pos.y * grid_width + door_pos.x] = Tile.Tile.FLOOR
+ grid[door_pos2.y * grid_width + door_pos2.x] = Tile.Tile.FLOOR
+ #door_pos[map.axis] -= 1
+ #grid[door_pos.y * grid_width + door_pos.x] = Tile.Tile.FLOOR
tries += 1
if tries > 1000: