extends CanvasLayer signal exit(success) @onready var pivot = $Pivot as Node2D @onready var hand_pivot = $Pivot/HandPivot as Node2D var dialogue_c02 = preload("res://asset/dialogue/c02.dialogue") func _ready() -> void: layer = GlobalConfig.CANVAS_LAYER_LITTLE_GAME wave_hand() DialogueManager.show_dialogue_balloon(dialogue_c02, "c02_弹珠游戏1") func reload() -> void: # 重新加载 var ball_scene = preload("res://scene/little_game/弹珠游戏/ball.tscn") var ball = ball_scene.instantiate() ball.is_shooter = true pivot.add_child(ball) pivot.move_child(ball, 0) ball.rand_id() var wave_tween: Tween var shooting = false func wave_hand() -> void: # 转动 pivot if wave_tween: if not wave_tween.is_running(): wave_tween.play() return wave_tween = create_tween() var timeout = 2.0 ( wave_tween . tween_property(hand_pivot, "rotation", 1.0, timeout) . set_ease(Tween.EASE_OUT) . set_trans(Tween.TRANS_SINE) ) ( wave_tween . tween_property(hand_pivot, "rotation", 0.0, timeout) . set_ease(Tween.EASE_IN) . set_trans(Tween.TRANS_SINE) ) ( wave_tween . tween_property(hand_pivot, "rotation", -1.0, timeout) . set_ease(Tween.EASE_OUT) . set_trans(Tween.TRANS_SINE) ) ( wave_tween . tween_property(hand_pivot, "rotation", 0.0, timeout) . set_ease(Tween.EASE_IN) . set_trans(Tween.TRANS_SINE) ) wave_tween.set_loops(9999999) func shoot() -> void: if shooting: return shooting = true # 触发射击事件 if wave_tween and wave_tween.is_running(): wave_tween.stop() var ball = pivot.get_child(0) as RigidBody2D var direction = Vector2(0, -1).rotated(hand_pivot.rotation) ball.linear_velocity = direction * 200 ball.angular_velocity = 20.0 ball.hit_ball.connect(_on_hit_ball) ball.hit_boundary.connect(_on_hit_boundary) var hit_count = 0 func _on_hit_ball(): print("_on_hit_ball") reload() wave_hand() shooting = false hit_count += 1 if hit_count >= 2: # 触发游戏结束 print("round 1 game over") hit_count = 0 game_over() func _on_hit_boundary(): # 重开游戏 print("hit boundary, restart") reload() wave_hand() shooting = false func _unhandled_input(event: InputEvent) -> void: if event.is_action_pressed("interact"): shoot() func game_over() -> void: exit.emit(true) # 0:默认; 1:寻找弹珠(老虎钳可以换弹珠); 2:游戏结束 ArchiveManager.set_global_entry("c02_ball_game_stage", 2) SceneManager.disable_prop_item("prop_弹珠") SceneManager.pop_debug_dialog_info("弹珠", "游戏关卡待完善") DialogueManager.show_dialogue_balloon(dialogue_c02, "c02_弹珠游戏5")