Openings between rooms
This commit is contained in:
@@ -31,6 +31,12 @@ const INNER_CORNER_UPPER_RIGHT_RECT := Rect2(156, 0, 50, 50)
|
|||||||
const INNER_CORNER_LOWER_LEFT_RECT := Rect2(0, 156, 50, 50)
|
const INNER_CORNER_LOWER_LEFT_RECT := Rect2(0, 156, 50, 50)
|
||||||
const INNER_CORNER_LOWER_RIGHT_RECT := Rect2(156, 156, 50, 50)
|
const INNER_CORNER_LOWER_RIGHT_RECT := Rect2(156, 156, 50, 50)
|
||||||
|
|
||||||
|
# -- Openings (drawn on top of wall segments at doorway edges) --
|
||||||
|
## Vertical opening: tiles separated on y-axis (north-south doorway through a horizontal wall)
|
||||||
|
const VERTICAL_OPENING_RECT := Rect2(206, 43, 31, 29)
|
||||||
|
## Horizontal opening: tiles separated on x-axis (east-west doorway through a vertical wall)
|
||||||
|
const HORIZONTAL_OPENING_RECT := Rect2(217, 0, 28, 31)
|
||||||
|
|
||||||
## Wall thickness in game pixels (how far the border extends into the tile)
|
## Wall thickness in game pixels (how far the border extends into the tile)
|
||||||
const WALL_THICKNESS := 20.0
|
const WALL_THICKNESS := 20.0
|
||||||
## Inner corner piece size in game pixels (quarter of a tile)
|
## Inner corner piece size in game pixels (quarter of a tile)
|
||||||
@@ -54,6 +60,7 @@ func draw_walls_for_layout(map_layout: MapLayout) -> void:
|
|||||||
for tile in tile_edges:
|
for tile in tile_edges:
|
||||||
var edges: Array = tile_edges[tile]
|
var edges: Array = tile_edges[tile]
|
||||||
_build_tile_walls(tile, edges)
|
_build_tile_walls(tile, edges)
|
||||||
|
_build_opening_sprites(map_layout)
|
||||||
queue_redraw()
|
queue_redraw()
|
||||||
|
|
||||||
|
|
||||||
@@ -66,30 +73,32 @@ func _draw() -> void:
|
|||||||
|
|
||||||
func _collect_tile_edges(map_layout: MapLayout) -> Dictionary:
|
func _collect_tile_edges(map_layout: MapLayout) -> Dictionary:
|
||||||
## Returns {Vector2i: Array[StringName]} mapping each tile to its wall edge directions.
|
## Returns {Vector2i: Array[StringName]} mapping each tile to its wall edge directions.
|
||||||
|
## Includes both true walls and opening edges, so wall sprites are drawn underneath openings.
|
||||||
var tile_edges: Dictionary = {}
|
var tile_edges: Dictionary = {}
|
||||||
var walls := map_layout.get_walls()
|
for edge_pair in map_layout.get_walls():
|
||||||
|
_add_edge_pair(tile_edges, edge_pair, map_layout)
|
||||||
|
for edge_pair in map_layout.get_openings():
|
||||||
|
_add_edge_pair(tile_edges, edge_pair, map_layout)
|
||||||
|
return tile_edges
|
||||||
|
|
||||||
for wall in walls:
|
|
||||||
var tile_a: Vector2i = wall[0]
|
func _add_edge_pair(tile_edges: Dictionary, edge_pair: Array, map_layout: MapLayout) -> void:
|
||||||
var tile_b: Vector2i = wall[1]
|
var tile_a: Vector2i = edge_pair[0]
|
||||||
|
var tile_b: Vector2i = edge_pair[1]
|
||||||
var diff: Vector2i = tile_b - tile_a
|
var diff: Vector2i = tile_b - tile_a
|
||||||
|
|
||||||
# Determine which edge of tile_a faces the wall
|
|
||||||
var edge_a := _direction_to_edge(diff)
|
var edge_a := _direction_to_edge(diff)
|
||||||
if edge_a != &"":
|
if edge_a != &"":
|
||||||
if not tile_edges.has(tile_a):
|
if not tile_edges.has(tile_a):
|
||||||
tile_edges[tile_a] = []
|
tile_edges[tile_a] = []
|
||||||
tile_edges[tile_a].append(edge_a)
|
tile_edges[tile_a].append(edge_a)
|
||||||
|
|
||||||
# Determine which edge of tile_b faces the wall (opposite direction)
|
|
||||||
var edge_b := _direction_to_edge(-diff)
|
var edge_b := _direction_to_edge(-diff)
|
||||||
if edge_b != &"" and map_layout.is_tile_valid(tile_b):
|
if edge_b != &"" and map_layout.is_tile_valid(tile_b):
|
||||||
if not tile_edges.has(tile_b):
|
if not tile_edges.has(tile_b):
|
||||||
tile_edges[tile_b] = []
|
tile_edges[tile_b] = []
|
||||||
tile_edges[tile_b].append(edge_b)
|
tile_edges[tile_b].append(edge_b)
|
||||||
|
|
||||||
return tile_edges
|
|
||||||
|
|
||||||
|
|
||||||
func _direction_to_edge(dir: Vector2i) -> StringName:
|
func _direction_to_edge(dir: Vector2i) -> StringName:
|
||||||
match dir:
|
match dir:
|
||||||
@@ -163,6 +172,58 @@ func _queue_segment(pos: Vector2, target_size: Vector2, source_rect: Rect2) -> v
|
|||||||
_segments.append([Rect2(pos, target_size), source_rect])
|
_segments.append([Rect2(pos, target_size), source_rect])
|
||||||
|
|
||||||
|
|
||||||
|
func _build_opening_sprites(map_layout: MapLayout) -> void:
|
||||||
|
## Composites opening (doorway) sprites on top of the wall segments at opening edges.
|
||||||
|
## Each opening is split in half across the shared edge, half drawn on each tile.
|
||||||
|
for opening in map_layout.get_openings():
|
||||||
|
var tile_a: Vector2i = opening[0]
|
||||||
|
var tile_b: Vector2i = opening[1]
|
||||||
|
var diff: Vector2i = tile_b - tile_a
|
||||||
|
|
||||||
|
# Normalize so the pair is ordered along the positive axis (tile_a < tile_b).
|
||||||
|
if diff == Vector2i.LEFT or diff == Vector2i.UP:
|
||||||
|
var swap := tile_a
|
||||||
|
tile_a = tile_b
|
||||||
|
tile_b = swap
|
||||||
|
diff = -diff
|
||||||
|
|
||||||
|
var origin_a := Vector2(tile_a) * TILE_SIZE
|
||||||
|
var origin_b := Vector2(tile_b) * TILE_SIZE
|
||||||
|
|
||||||
|
if diff == Vector2i.DOWN:
|
||||||
|
_queue_vertical_opening(origin_a, origin_b)
|
||||||
|
elif diff == Vector2i.RIGHT:
|
||||||
|
_queue_horizontal_opening(origin_a, origin_b)
|
||||||
|
|
||||||
|
|
||||||
|
func _queue_vertical_opening(origin_upper: Vector2, origin_lower: Vector2) -> void:
|
||||||
|
# Vertical opening: tiles vertically adjacent; horizontal wall edge between them.
|
||||||
|
var src := VERTICAL_OPENING_RECT
|
||||||
|
var w: float = src.size.x
|
||||||
|
var h_total: float = src.size.y
|
||||||
|
var h_upper: float = floorf(h_total / 2.0) # 14
|
||||||
|
var h_lower: float = h_total - h_upper # 15
|
||||||
|
var x_offset := (TILE_SIZE - w) / 2.0
|
||||||
|
var src_upper := Rect2(src.position, Vector2(w, h_upper))
|
||||||
|
var src_lower := Rect2(src.position + Vector2(0, h_upper), Vector2(w, h_lower))
|
||||||
|
_queue_segment(origin_upper + Vector2(x_offset, TILE_SIZE - h_upper), Vector2(w, h_upper), src_upper)
|
||||||
|
_queue_segment(origin_lower + Vector2(x_offset, 0), Vector2(w, h_lower), src_lower)
|
||||||
|
|
||||||
|
|
||||||
|
func _queue_horizontal_opening(origin_left: Vector2, origin_right: Vector2) -> void:
|
||||||
|
# Horizontal opening: tiles horizontally adjacent; vertical wall edge between them.
|
||||||
|
var src := HORIZONTAL_OPENING_RECT
|
||||||
|
var w_total: float = src.size.x
|
||||||
|
var h: float = src.size.y
|
||||||
|
var w_left: float = floorf(w_total / 2.0) # 14
|
||||||
|
var w_right: float = w_total - w_left # 14
|
||||||
|
var y_offset := (TILE_SIZE - h) / 2.0
|
||||||
|
var src_left := Rect2(src.position, Vector2(w_left, h))
|
||||||
|
var src_right := Rect2(src.position + Vector2(w_left, 0), Vector2(w_right, h))
|
||||||
|
_queue_segment(origin_left + Vector2(TILE_SIZE - w_left, y_offset), Vector2(w_left, h), src_left)
|
||||||
|
_queue_segment(origin_right + Vector2(0, y_offset), Vector2(w_right, h), src_right)
|
||||||
|
|
||||||
|
|
||||||
func _build_outer_corners(_tile: Vector2i, _tile_origin: Vector2, _edges: Array) -> void:
|
func _build_outer_corners(_tile: Vector2i, _tile_origin: Vector2, _edges: Array) -> void:
|
||||||
# TODO: Implement outer corner segments
|
# TODO: Implement outer corner segments
|
||||||
# Check pairs of adjacent edges (e.g., "top" + "left" → top-left outer corner)
|
# Check pairs of adjacent edges (e.g., "top" + "left" → top-left outer corner)
|
||||||
|
|||||||
@@ -48,6 +48,14 @@ func is_passable(from: Vector2i, to: Vector2i) -> bool:
|
|||||||
return _opening_set.has(_edge_key(from, to))
|
return _opening_set.has(_edge_key(from, to))
|
||||||
|
|
||||||
|
|
||||||
|
func get_openings() -> Array:
|
||||||
|
## Returns an array of [Vector2i, Vector2i] pairs representing opening edges.
|
||||||
|
var result: Array = []
|
||||||
|
for i in range(0, openings.size(), 2):
|
||||||
|
result.append([openings[i], openings[i + 1]])
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
func get_walls() -> Array:
|
func get_walls() -> Array:
|
||||||
## Returns an array of [Vector2i, Vector2i] pairs representing wall edges.
|
## Returns an array of [Vector2i, Vector2i] pairs representing wall edges.
|
||||||
## A wall exists where a room tile borders void or a different room (without an opening).
|
## A wall exists where a room tile borders void or a different room (without an opening).
|
||||||
|
|||||||
Reference in New Issue
Block a user