fix: apply map-aware FOV and align actor rendering
This commit is contained in:
@@ -20,16 +20,36 @@ func try_player_action(direction: Vector2i) -> Array[TurnResult]:
|
||||
update_exploration()
|
||||
return results
|
||||
|
||||
func compute_visible_cells(origin: Vector2i, radius: int) -> Dictionary[Vector2i, bool]:
|
||||
func compute_visible_cells(game_map: GridMapState, origin: Vector2i, radius: int) -> Dictionary[Vector2i, bool]:
|
||||
var visible: Dictionary[Vector2i, bool] = {}
|
||||
for y in range(origin.y - radius, origin.y + radius + 1):
|
||||
for x in range(origin.x - radius, origin.x + radius + 1):
|
||||
var cell := Vector2i(x, y)
|
||||
if map.is_inside(cell) and origin.distance_to(cell) <= radius:
|
||||
if game_map.is_inside(cell) and origin.distance_to(cell) <= radius and _has_line_of_sight(game_map, origin, cell):
|
||||
visible[cell] = true
|
||||
return visible
|
||||
|
||||
func update_exploration() -> void:
|
||||
visible_cells = compute_visible_cells(player.cell, 6)
|
||||
visible_cells = compute_visible_cells(map, player.cell, 6)
|
||||
for cell in visible_cells:
|
||||
explored_cells[cell] = true
|
||||
|
||||
func _has_line_of_sight(game_map: GridMapState, origin: Vector2i, target: Vector2i) -> bool:
|
||||
var current := origin
|
||||
var delta_x: int = abs(target.x - origin.x)
|
||||
var step_x: int = 1 if origin.x < target.x else -1
|
||||
var delta_y: int = -abs(target.y - origin.y)
|
||||
var step_y: int = 1 if origin.y < target.y else -1
|
||||
var error: int = delta_x + delta_y
|
||||
|
||||
while current != target:
|
||||
var doubled_error: int = 2 * error
|
||||
if doubled_error >= delta_y:
|
||||
error += delta_y
|
||||
current.x += step_x
|
||||
if doubled_error <= delta_x:
|
||||
error += delta_x
|
||||
current.y += step_y
|
||||
if current != target and game_map.is_opaque(current):
|
||||
return false
|
||||
return true
|
||||
|
||||
@@ -10,4 +10,4 @@ func set_actor(new_actor: ActorState) -> void:
|
||||
|
||||
func refresh() -> void:
|
||||
if actor != null:
|
||||
position = Vector2(actor.cell * TILE_SIZE) + Vector2(TILE_SIZE) / 2.0
|
||||
position = Vector2(actor.cell) * Vector2(TILE_SIZE)
|
||||
|
||||
Reference in New Issue
Block a user