46 lines
1.5 KiB
GDScript
46 lines
1.5 KiB
GDScript
extends Node2D
|
|
|
|
var map_size: Vector2i = Vector2i.ZERO
|
|
var tile_size: int = 16
|
|
var explored_map: PackedInt32Array = PackedInt32Array()
|
|
var visible_map: PackedInt32Array = PackedInt32Array()
|
|
var fog_color_unseen: Color = Color(0, 0, 0, 1.0)
|
|
var fog_color_seen: Color = Color(0, 0, 0, 0.85)
|
|
var debug_lines: Array = []
|
|
var debug_enabled: bool = false
|
|
|
|
func setup(new_map_size: Vector2i, new_tile_size: int = 16) -> void:
|
|
map_size = new_map_size
|
|
tile_size = new_tile_size
|
|
|
|
func set_maps(new_explored_map: PackedInt32Array, new_visible_map: PackedInt32Array) -> void:
|
|
explored_map = new_explored_map
|
|
visible_map = new_visible_map
|
|
queue_redraw()
|
|
|
|
func set_debug_lines(lines: Array, enabled: bool) -> void:
|
|
debug_lines = lines
|
|
debug_enabled = enabled
|
|
queue_redraw()
|
|
|
|
func _draw() -> void:
|
|
if map_size == Vector2i.ZERO or explored_map.is_empty() or visible_map.is_empty():
|
|
return
|
|
|
|
for x in range(map_size.x):
|
|
for y in range(map_size.y):
|
|
var idx = x + y * map_size.x
|
|
if idx >= explored_map.size() or idx >= visible_map.size():
|
|
continue
|
|
var pos = Vector2(x * tile_size, y * tile_size)
|
|
if visible_map[idx] == 1:
|
|
continue
|
|
if explored_map[idx] == 0:
|
|
draw_rect(Rect2(pos, Vector2(tile_size, tile_size)), fog_color_unseen, true)
|
|
else:
|
|
draw_rect(Rect2(pos, Vector2(tile_size, tile_size)), fog_color_seen, true)
|
|
|
|
if debug_enabled:
|
|
for line in debug_lines:
|
|
if line is Array and line.size() == 2:
|
|
draw_line(line[0], line[1], Color(0, 1, 0, 0.4), 1.0) |