diff options
author | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2024-09-23 08:01:56 +0100 |
---|---|---|
committer | Lucas Fryzek <lucas.fryzek@fryzekconcepts.com> | 2024-09-23 08:01:56 +0100 |
commit | b62062c72a2354ba06b53706d94d3db53c224f12 (patch) | |
tree | 3160048a29fd8ebede5cdc6d4dabc1976facadfa | |
parent | 3ef1fc4df2e3178d37061ad13b5d366771193dd2 (diff) |
bsp_level_generator: Increase size of doors to 2 grid tiles
-rw-r--r-- | scripts/bsp_level_generator.gd | 44 | ||||
-rw-r--r-- | scripts/dungeon_manager.gd | 2 |
2 files changed, 31 insertions, 15 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: diff --git a/scripts/dungeon_manager.gd b/scripts/dungeon_manager.gd index 270a5a0..513fcd6 100644 --- a/scripts/dungeon_manager.gd +++ b/scripts/dungeon_manager.gd @@ -11,7 +11,7 @@ func _ready() -> void: pass # Replace with function body. func create_enemies() -> void: - var num_enemies = randi_range(1, 10) + var num_enemies = randi_range(4, 10) for i in range(num_enemies): var enemy = enemy_inst.instantiate() |