Files
DungeonCrawlerWorld/scripts/domain/world/surface_generator.gd
T

39 lines
1.7 KiB
GDScript

class_name SurfaceGenerator
extends RefCounted
const GridMapStateType = preload("res://scripts/domain/grid_map_state.gd")
const FloorStateType = preload("res://scripts/domain/world/floor_state.gd")
const RoomStateType = preload("res://scripts/domain/world/room_state.gd")
const SURFACE_SIZE := Vector2i(42, 16)
const ENTRANCE := Vector2i(4, 7)
const DOOR := Vector2i(36, 7)
const EXIT := Vector2i(39, 7)
# The surface mirrors DCWASCII's current floor-zero contract: an empty authored
# staging area, a straight corridor, one door, and the stairs to the procedural
# dungeon. It intentionally contains no enemies, chest, deadline content, or
# seed-dependent population.
static func generate(_seed: String = "") -> FloorState:
var map := GridMapStateType.new(SURFACE_SIZE, GridMapStateType.CellKind.WALL)
var entrance_room := RoomStateType.new(&"surface_entrance", Rect2i(2, 2, 18, 11), &"entrance")
var landing := RoomStateType.new(&"surface_landing", Rect2i(37, 6, 4, 3), &"open")
_carve_room(map, entrance_room.bounds)
for x in range(20, DOOR.x):
map.set_cell(Vector2i(x, ENTRANCE.y), GridMapStateType.CellKind.FLOOR)
map.set_cell(DOOR, GridMapStateType.CellKind.CLOSED_DOOR)
_carve_room(map, landing.bounds)
map.set_cell(EXIT, GridMapStateType.CellKind.STAIRS)
var floor := FloorStateType.new(map, 0, 0)
floor.rooms = [entrance_room, landing]
floor.entrance = ENTRANCE
floor.exit = EXIT
floor.metadata = {"hand_authored": true, "theme": "surface"}
return floor
static func _carve_room(map: GridMapState, bounds: Rect2i) -> void:
for y in range(bounds.position.y, bounds.end.y):
for x in range(bounds.position.x, bounds.end.x):
map.set_cell(Vector2i(x, y), GridMapStateType.CellKind.FLOOR)