Files
hello-godot/tests/smoke_sim.gd
T

66 lines
2.2 KiB
GDScript

extends SceneTree
## 冒烟测试(时间驱动,与无头模式实际帧率无关):
## 主动模式:模拟移动+按住开火跑满 110s,覆盖波次→Boss 战→下一轮全链路;
## idle 模式:站桩 75s 被打死,覆盖掉命/游戏结束。
## 运行:godot --headless -s tests/smoke_sim.gd [-- idle]
const ACTIVE_DURATION := 110.0
const IDLE_DURATION := 75.0
var _time := 0.0
var _duration := ACTIVE_DURATION
var _next_print := 10.0
var _next_bomb := 30.0
var game: Game
var idle := false
func _initialize() -> void:
idle = OS.get_cmdline_user_args().has("idle")
if idle:
_duration = IDLE_DURATION
var scene := load("res://scenes/game.tscn") as PackedScene
game = scene.instantiate()
root.add_child(game)
if not idle:
Input.action_press("fire")
print("[smoke] game scene instantiated (idle=%s)" % str(idle))
func _process(delta: float) -> bool:
# 游戏结束确认后会切回标题场景,模拟随之终止
if not is_instance_valid(game):
print("[smoke] left game scene (back to title) — stopping simulation")
return true
_time += delta
if not idle:
# 左右往返扫射(1.5s 周期),模拟真实操作
if fmod(_time, 1.5) < 0.75:
Input.action_release("move_left")
Input.action_press("move_right")
else:
Input.action_release("move_right")
Input.action_press("move_left")
# 每 10 秒打印一次局面快照
if _time >= _next_print:
_next_print += 10.0
var boss_alive := is_instance_valid(game._boss)
print("[smoke] t=%ds state=%d score=%d lives=%d bombs=%d boss=%s bar=%s enemies=%d pbullets=%d ebullets=%d" % [
int(_time), game.state, game.score, game.lives, game.player.bombs,
str(boss_alive), str(game._boss_bar_bg.visible and boss_alive),
(game.get_node("Enemies") as Node2D).get_child_count(),
(game.get_node("PlayerBullets") as Node2D).get_child_count(),
(game.get_node("EnemyBullets") as Node2D).get_child_count(),
])
# 主动模式每 30 秒投一颗炸弹(无头无法可靠模拟 just_pressed 边沿,直调公开接口)
if not idle and _time >= _next_bomb:
_next_bomb += 30.0
game.player.use_bomb()
if _time >= _duration:
print("[smoke] finished, no crash")
return true
return false