extends Node2D const ENEMY = preload("res://scenes/game/enemy_ship.tscn") const SHOT = preload("res://scenes/game/weapon_projectile.tscn") var ship: CharacterBody2D func make_enemy(point: Vector2) -> CharacterBody2D: var enemy := ENEMY.instantiate() as CharacterBody2D enemy.position = point add_child(enemy) enemy.set_physics_process(false) enemy.set("_player", ship) return enemy func _ready() -> void: GameState.start_new_run() ship = preload("res://scenes/game/player_ship.tscn").instantiate() add_child(ship) ship.set_physics_process(false) ship.get_node("WeaponController").set_physics_process(false) ship.get_node("ExtensionSystems").set_physics_process(false) var infected := make_enemy(Vector2(200, 0)) var hostile := make_enemy(Vector2(400, 0)) infected.set_virus_controlled(true) infected.hull = infected.max_hull infected.shields = infected.max_shields assert(hostile.select_combat_target() == ship) assert(infected.select_combat_target() == hostile) var xp_after_conversion := GameState.captain.experience await get_tree().physics_frame await get_tree().physics_frame # Actual physics ray used by the player laser detects the converted ship. var query := PhysicsRayQueryParameters2D.create(Vector2(100, 0), Vector2(250, 0), preload("res://scripts/game/weapon_controller.gd").RAY_COLLISION_MASK) var hit := get_world_2d().direct_space_state.intersect_ray(query) assert(hit.get("collider") == infected) # Real swept projectile collision: plasma, bullets and gamma all hit layer 64. for kind in [ItemDefinition.WeaponKind.PLASMA, ItemDefinition.WeaponKind.MACHINE_GUN, ItemDefinition.WeaponKind.GAMMA]: infected.hull = infected.max_hull infected.shields = infected.max_shields var shot := SHOT.instantiate() shot.configure(Vector2(100, 0), Vector2.RIGHT, kind, 1000.0, 5.0, 400.0) add_child(shot) shot.set_physics_process(false) var before: float = infected.hull + infected.shields shot._physics_process(0.15) assert(infected.hull + infected.shields < before) # Player rocket splash reaches infected ships; converted rockets cannot hurt player. infected.shields = infected.max_shields var rocket := SHOT.instantiate() rocket.configure(Vector2(220, 0), Vector2.RIGHT, ItemDefinition.WeaponKind.MISSILE, 100.0, 5.0, 400.0) add_child(rocket) rocket.set_physics_process(false) var before: float = infected.hull + infected.shields rocket._explode_at_target(hostile) assert(infected.hull + infected.shields < before) rocket.queue_free() # A missile already tracking this ship retains it after infection. var seeker := SHOT.instantiate() seeker.configure(Vector2(-500, 0), Vector2.RIGHT, ItemDefinition.WeaponKind.MISSILE, 10.0, 5.0, 1000.0, infected) add_child(seeker) seeker.set_physics_process(false) seeker._physics_process(0.01) assert(seeker.homing_target == infected) seeker.queue_free() # Destruction remains possible, with no second XP payout after conversion. infected.shields = 0.0 infected.hull = 1.0 var lethal := SHOT.instantiate() lethal.configure(Vector2(100, 0), Vector2.RIGHT, ItemDefinition.WeaponKind.MACHINE_GUN, 1000.0, 1000.0, 400.0) add_child(lethal) lethal.set_physics_process(false) lethal._physics_process(0.15) assert(infected.is_queued_for_deletion()) assert(GameState.captain.experience == xp_after_conversion) print("VIRUS_PLAYER_DAMAGE_TEST: PASS target selection, laser ray, plasma/bullet/gamma collisions, rocket splash, retained seeker target, destruction and single XP payout") get_tree().quit()