This commit is contained in:
2025-12-08 21:56:36 +08:00
parent 438c0c0d6e
commit ac463185de
5 changed files with 162 additions and 59 deletions
+21 -7
View File
@@ -355,9 +355,10 @@ func _physics_process(delta):
rpc("remote_set_position", global_position)
last_sent_position = global_position
# Add continuous finish line check
if race_manager and current_position in race_manager.finish_locations and can_finish and not is_player_moving:
start_new_lap()
# Add continuous finish line check (uses lap-aware finish locations)
var current_finish = race_manager.get_current_finish_locations() if race_manager else []
if race_manager and current_position in current_finish and can_finish and not is_player_moving:
finish_race() # This handles lap increment and calls start_new_lap properly
# --------------------------------------------------------------------
# Input
@@ -536,14 +537,15 @@ func start_movement_along_path(path: Array, clear_visual: bool = true):
tween.set_ease(Tween.EASE_IN_OUT)
for point in path:
tween.tween_property(self, "position", grid_to_world(Vector2i(point.x, point.y)), 0.5)
tween.tween_property(self, "position", grid_to_world(Vector2i(point.x, point.y)), 0.25)
tween.tween_callback(func():
current_position = Vector2i(path[-1].x, path[-1].y)
is_player_moving = false
# Check if we've reached the finish line
if current_position in finish_locations and can_finish:
# Check if we've reached the finish line (uses lap-aware finish locations)
var current_finish_locs = race_manager.get_current_finish_locations() if race_manager else finish_locations
if current_position in current_finish_locs and can_finish:
finish_race()
var main = get_tree().get_root().get_node_or_null("Main")
@@ -1030,6 +1032,12 @@ func sync_grid_item(x: int, y: int, z: int, item: int):
func sync_goals(new_goals: Array):
goals = new_goals.duplicate() # Make sure to duplicate the array
# Also update race_manager's goals directly
if race_manager:
race_manager.goals = new_goals.duplicate()
# Re-check finish availability with new goals
race_manager.update_finish_availability()
# Update the AllPlayerGoals UI
var main = get_tree().get_root().get_node_or_null("Main")
if main and main.has_method("_update_goals_ui_for_player"):
@@ -1053,7 +1061,8 @@ func _after_action_completed():
action_manager.after_action_completed()
func is_finish_position(pos: Vector2i) -> bool:
return pos in finish_locations
var current_finish = race_manager.get_current_finish_locations() if race_manager else finish_locations
return pos in current_finish
func consume_action_points(points: int):
action_manager.consume_action_points(points)
@@ -1092,3 +1101,8 @@ func sync_position(pos: Vector2i):
func highlight_valid_obstacle_cells():
action_manager.highlight_valid_obstacle_cells()
@rpc("any_peer", "call_local", "reliable")
func complete_race(final_position: int):
if race_manager:
race_manager.on_race_completed(final_position)