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.gd53
1 files changed, 51 insertions, 2 deletions
diff --git a/scripts/bsp_level_generator.gd b/scripts/bsp_level_generator.gd
index 0f38b96..543eb1d 100644
--- a/scripts/bsp_level_generator.gd
+++ b/scripts/bsp_level_generator.gd
@@ -133,8 +133,8 @@ func generate_grid(map: BSPNode, grid: Array[Tile.Tile]) -> void:
func get_tile(grid: Array[Tile.Tile], pos: Vector2i) -> Tile.Tile:
return grid[pos.y * grid_width + pos.x]
-
-func populate_grid(grid: Array[Tile.Tile]) -> void:
+
+func place_lockers(grid: Array[Tile.Tile]) -> void:
for room in rooms:
var num_lockers = randi_range(0, 2)
print("Generating ", num_lockers, "Lockers")
@@ -153,6 +153,55 @@ func populate_grid(grid: Array[Tile.Tile]) -> void:
and get_tile(grid, pos + Vector2i(0, -1)) != Tile.Tile.DOOR:
grid[pos.y * grid_width + pos.x] = Tile.Tile.LOCKER
found = true
+
+func place_player(grid: Array[Tile.Tile]) -> Rect2i:
+ var player_room: Rect2i = rooms.pick_random()
+ var player_pos = Vector2i(player_room.position.x + player_room.size.x / 2, player_room.position.y + player_room.size.y / 2)
+
+ grid[player_pos.y * grid_width + player_pos.x] = Tile.Tile.PLAYER
+ return player_room
+
+func place_enemies(grid: Array[Tile.Tile], player_room: Rect2i) -> void:
+ var num_enemies = randi_range(4, 10)
+
+ for i in range(num_enemies):
+ var found_pos = false
+ while not found_pos:
+ var room: Rect2i = rooms.pick_random()
+ if room == player_room:
+ continue
+
+ var pos = Vector2i(randi_range(room.position.x, room.end.x - 1), randi_range(room.position.y, room.end.y - 1))
+ if grid[pos.y * grid_width + pos.x] == Tile.Tile.FLOOR:
+ grid[pos.y * grid_width + pos.x] = Tile.Tile.ENEMY
+ found_pos = true
+
+func place_exit(grid: Array[Tile.Tile], player_room: Rect2i) -> void:
+ var found_pos = false
+
+ while not found_pos:
+ var room: Rect2i = rooms.pick_random()
+ if room == player_room:
+ continue
+
+ var pos = Vector2i(randi_range(room.position.x, room.end.x - 1), randi_range(room.position.y, room.end.y - 1))
+ var left = pos + Vector2i.LEFT
+ var right = pos + Vector2i.RIGHT
+ var up = pos + Vector2i.UP
+ var down = pos + Vector2i.DOWN
+ if grid[pos.y * grid_width + pos.x] == Tile.Tile.FLOOR \
+ and grid[left.y * grid_width + left.x] == Tile.Tile.FLOOR \
+ and grid[right.y * grid_width + right.x] == Tile.Tile.FLOOR \
+ and grid[up.y * grid_width + up.x] == Tile.Tile.FLOOR \
+ and grid[down.y * grid_width + down.x] == Tile.Tile.FLOOR:
+ grid[pos.y * grid_width + pos.x] = Tile.Tile.PORTAL
+ found_pos = true
+
+func populate_grid(grid: Array[Tile.Tile]) -> void:
+ place_lockers(grid)
+ var player_room = place_player(grid)
+ place_exit(grid, player_room)
+ place_enemies(grid, player_room)
func generate_plane(array: Array, pos: Vector3, dim: Array[Vector3], normal: Vector3) -> void:
var index = len(array[Mesh.ARRAY_VERTEX])