This commit is contained in:
Aodhan Collins
2026-01-26 03:31:45 +00:00
parent b42521a008
commit c0e4aaeac5
5 changed files with 263 additions and 92 deletions

View File

@@ -1,32 +1,49 @@
extends GridContainer
extends Control
var cells: Array[ColorRect] = []
var explored_rooms: Array = []
var current_room_id: String = ""
var cell_size: Vector2 = Vector2(20, 20)
var padding: float = 5.0
func _ready():
columns = 4
for i in range(16):
var cell = ColorRect.new()
cell.custom_minimum_size = Vector2(40, 40)
cell.color = Color.DARK_GRAY
add_child(cell)
cells.append(cell)
# Remove any children if they exist (cleanup from previous implementation)
for child in get_children():
child.queue_free()
func update_map(current_room_id: String, explored_rooms: Array):
# Parse "room_x_y"
var parts = current_room_id.split("_")
if parts.size() == 3:
var x = int(parts[1])
var y = int(parts[2])
var index = y * 4 + x
func update_map(new_room_id: String, explored: Array):
current_room_id = new_room_id
explored_rooms = explored
queue_redraw()
func _draw():
if current_room_id == "":
return
for i in range(cells.size()):
var cell_x = i % 4
var cell_y = i / 4
var cell_id = "room_%d_%d" % [cell_x, cell_y]
var center = size / 2
# Parse current room coordinates to center the map
var current_coords = _parse_coords(current_room_id)
for room_id in explored_rooms:
var coords = _parse_coords(room_id)
var rel_x = coords.x - current_coords.x
var rel_y = coords.y - current_coords.y
# Calculate position relative to center
# (rel_x, rel_y) * (cell_size + padding) gives the offset
var offset = Vector2(rel_x, rel_y) * (cell_size + Vector2(padding, padding))
var rect_pos = center + offset - cell_size / 2
var rect = Rect2(rect_pos, cell_size)
var color = Color.LIGHT_GRAY
if room_id == current_room_id:
color = Color.GREEN
if i == index:
cells[i].color = Color.GREEN # Player
elif cell_id in explored_rooms:
cells[i].color = Color.LIGHT_GRAY # Explored
else:
cells[i].color = Color.DARK_GRAY # Unexplored
draw_rect(rect, color, true)
draw_rect(rect, Color.BLACK, false, 1.0) # Border
func _parse_coords(id: String) -> Vector2:
var parts = id.split("_")
if parts.size() >= 3:
return Vector2(int(parts[1]), int(parts[2]))
return Vector2.ZERO