Twin-stick combat: aim and fire with a second stick, MOBA-style ability ring
The fleet's guns picked their own targets and fired on their own, so combat happened whether or not the player did anything - there was nothing to aim and nothing to decide, and the right half of the screen held nothing at all. Firing is now an action. VesselWeaponComponent no longer seeks a target; it shoots along a heading, and the only thing that supplies one is the new right-hand stick via FireStickController. A fleet arriving from another scene starts with its guns silent, which is the correct resting state. A subtle dashed guide runs from the fleet along the aimed heading while the stick is held, out to the guns' OWN range - read from a weapon that is actually aboard, so the line can never promise reach the fleet does not have. Layout: the two sticks take the bottom corners, the pivot pair is centred between them at the bottom edge, and the laser and gas bomb sit on an arc up and left of the fire stick where a thumb already is. Those four are now round - IconButton grew a round_frame mode, and the in-world action controls use it while panel and menu buttons stay square, so the two kinds of button read as different kinds of thing. Worth recording, because it cost a screenshot to find: a script-declared property set BEFORE the `script = ExtResource(...)` line in a .tscn is silently dropped. Godot's parser has no idea the property exists yet. The round frames were all correctly set in both scenes and none of them applied. Also fixed researtch_lab_garrison.tres, which was authored under the void profile - that is the black hole surface, so a lab garrison was spawning on black holes. Suite 110/110. test_enemy_combat's whole premise was auto-fire; it now holds the real stick toward the enemy rather than poking weapon components, so it exercises the path the player uses. test_fire_stick is new and covers the change itself: an idle stick leaves a target parked well inside range untouched, which is precisely what the old gun would never have done. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
8ba2cca6b6
commit
0fb8f9300b
15 changed files with 561 additions and 131 deletions
35
tests/_hud_preview.gd
Normal file
35
tests/_hud_preview.gd
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
extends Node2D
|
||||
|
||||
# Preview, not a test - the full combat HUD with every ability control
|
||||
# visible, so the arrangement around the fire stick can be looked at.
|
||||
#
|
||||
# bash tests/screenshot.sh res://tests/_hud_preview.tscn /tmp/hud.png 30 720x1280
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
GameState.buildings.clear()
|
||||
GameState.extractors.clear()
|
||||
GameState.vessel_levels["unlock_laser"] = 1
|
||||
GameState.vessel_levels["unlock_gas_bomber"] = 1
|
||||
GameState.deposit_fleet_resource(GameState.RESOURCE_ENERGY, 200)
|
||||
GameState.deposit_fleet_resource(GameState.RESOURCE_GAS, 200)
|
||||
var main: Node = load("res://Main.tscn").instantiate()
|
||||
add_child(main)
|
||||
main.get_node("EnemySpawner").set_process(false)
|
||||
main.get_node("AsteroidField").set_process(false)
|
||||
var fleet: Node = main.get_node("Fleet")
|
||||
fleet.spawn_ships(3, Vector2.ZERO, PackedStringArray([
|
||||
GameState.VESSEL_INTERCEPTOR, GameState.VESSEL_LASER, GameState.VESSEL_GAS_BOMBER]))
|
||||
main.get_node("LaserController")._process(0.0)
|
||||
main.get_node("GasBombController")._process(0.0)
|
||||
# Push the fire stick, so its knob shows deflected the way it looks in use.
|
||||
var stick: Control = main.get_node("UI/FireStick")
|
||||
var press := InputEventScreenTouch.new()
|
||||
press.index = 4
|
||||
press.pressed = true
|
||||
press.position = stick.global_position + stick.size * 0.5
|
||||
stick.handle_touch(press)
|
||||
var drag := InputEventScreenDrag.new()
|
||||
drag.index = 4
|
||||
drag.position = press.position + Vector2(46.0, -52.0)
|
||||
stick.handle_drag(drag)
|
||||
1
tests/_hud_preview.gd.uid
Normal file
1
tests/_hud_preview.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://ddyyllwj5g76j
|
||||
6
tests/_hud_preview.tscn
Normal file
6
tests/_hud_preview.tscn
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://tests/_hud_preview.gd" id="1"]
|
||||
|
||||
[node name="HudPreview" type="Node2D"]
|
||||
script = ExtResource("1")
|
||||
|
|
@ -2,9 +2,15 @@ extends SceneTree
|
|||
|
||||
# Headless gameplay test: run with
|
||||
# godot --headless -s res://tests/test_enemy_combat.gd
|
||||
# Verifies the fleet auto-fires on an enemy within range and kills it after
|
||||
# a few hits, without the enemy ever having to touch a ship, and that a
|
||||
# coherent red light-burst explosion VFX spawns at the moment it dies.
|
||||
# Verifies the fleet kills an enemy it is AIMED at, without the enemy ever
|
||||
# having to touch a ship, and that a coherent red light-burst explosion VFX
|
||||
# spawns at the moment it dies.
|
||||
#
|
||||
# The fleet used to fire on its own and this test only had to wait. Firing is
|
||||
# now the right-hand stick, so the test holds it toward the enemy - through
|
||||
# the real control, not by poking the weapon components, so what it exercises
|
||||
# is the path the player uses. See tests/test_fire_stick.gd for the aiming
|
||||
# behaviour itself.
|
||||
|
||||
const TEST_DURATION: float = 3.0
|
||||
const SPAWN_OFFSET: Vector2 = Vector2(220, 0) # inside fire_range, outside collision radius
|
||||
|
|
@ -43,13 +49,14 @@ func _physics_process(delta: float) -> bool:
|
|||
enemy = enemy_scene.instantiate()
|
||||
enemy.position = fleet.get_centroid() + SPAWN_OFFSET
|
||||
main_scene.add_child(enemy)
|
||||
_hold_fire_toward(SPAWN_OFFSET)
|
||||
started = true
|
||||
return false
|
||||
|
||||
elapsed += delta
|
||||
|
||||
if not is_instance_valid(enemy):
|
||||
_finish(true, "enemy destroyed by fleet fire after %.2fs" % elapsed)
|
||||
_finish(true, "enemy destroyed by aimed fleet fire after %.2fs" % elapsed)
|
||||
return true
|
||||
|
||||
if elapsed >= TEST_DURATION:
|
||||
|
|
@ -59,6 +66,22 @@ func _physics_process(delta: float) -> bool:
|
|||
return false
|
||||
|
||||
|
||||
# Presses the fire stick and holds it on the given heading. The stick keeps
|
||||
# reporting that direction until it is released, so this is called once.
|
||||
func _hold_fire_toward(heading: Vector2) -> void:
|
||||
var stick: Control = main_scene.get_node("UI/FireStick")
|
||||
var centre: Vector2 = stick.global_position + stick.size * 0.5
|
||||
var press := InputEventScreenTouch.new()
|
||||
press.index = 6
|
||||
press.pressed = true
|
||||
press.position = centre
|
||||
stick.handle_touch(press)
|
||||
var drag := InputEventScreenDrag.new()
|
||||
drag.index = 6
|
||||
drag.position = centre + heading.normalized() * stick.max_radius
|
||||
stick.handle_drag(drag)
|
||||
|
||||
|
||||
func _finish(ok: bool, message: String) -> void:
|
||||
print("ships_remaining=%d" % fleet.ships.size())
|
||||
print(message)
|
||||
|
|
|
|||
188
tests/test_fire_stick.gd
Normal file
188
tests/test_fire_stick.gd
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
extends SceneTree
|
||||
|
||||
# Headless gameplay test: run with
|
||||
# godot --headless -s res://tests/test_fire_stick.gd
|
||||
# The fleet's guns used to pick their own targets and fire on their own, so
|
||||
# combat happened whether or not the player did anything. Firing is now an
|
||||
# action: the right-hand stick aims it, and nothing else fires it.
|
||||
#
|
||||
# Covers:
|
||||
# A. an idle stick means an idle gun - an enemy parked well inside fire
|
||||
# range takes no shots at all. This is the behaviour that CHANGED, so it
|
||||
# is checked against a target the old auto-aim would certainly have hit
|
||||
# B. pushing the stick fires, and the shots travel along the stick's
|
||||
# heading rather than at whatever happens to be nearest
|
||||
# C. releasing the stick stops the gun
|
||||
# D. the stick claims only touches inside its own rect, so the right half
|
||||
# of the screen does not swallow pinches and taps meant for the world
|
||||
# E. the dotted aim guide is drawn only while aiming, and reaches exactly as
|
||||
# far as the guns actually shoot - a guide that outruns the gun would be
|
||||
# worse than none
|
||||
|
||||
const FIRE_DIRECTION := Vector2(1.0, 0.0)
|
||||
|
||||
var game_state: Node
|
||||
var main: Node
|
||||
var fleet: Node
|
||||
var fire_stick: Control
|
||||
var controller: Node
|
||||
var decoy: Node
|
||||
var stage: int = 0
|
||||
var elapsed: float = 0.0
|
||||
var shots_while_idle: int = 0
|
||||
|
||||
|
||||
func _initialize() -> void:
|
||||
game_state = root.get_node("GameState")
|
||||
game_state.buildings.clear()
|
||||
game_state.extractors.clear()
|
||||
game_state.reset_progression()
|
||||
main = load("res://Main.tscn").instantiate()
|
||||
root.add_child(main)
|
||||
current_scene = main
|
||||
fleet = main.get_node("Fleet")
|
||||
fire_stick = main.get_node("UI/FireStick")
|
||||
controller = main.get_node("FireStickController")
|
||||
|
||||
|
||||
func _projectile_count() -> int:
|
||||
return get_nodes_in_group("player_projectiles").size()
|
||||
|
||||
|
||||
func _push_stick(direction: Vector2) -> void:
|
||||
var centre: Vector2 = fire_stick.global_position + fire_stick.size * 0.5
|
||||
var press := InputEventScreenTouch.new()
|
||||
press.index = 3
|
||||
press.pressed = true
|
||||
press.position = centre
|
||||
if not fire_stick.handle_touch(press):
|
||||
push_error("the fire stick refused a touch at its own centre")
|
||||
var drag := InputEventScreenDrag.new()
|
||||
drag.index = 3
|
||||
drag.position = centre + direction.normalized() * fire_stick.max_radius
|
||||
fire_stick.handle_drag(drag)
|
||||
|
||||
|
||||
func _release_stick() -> void:
|
||||
var release := InputEventScreenTouch.new()
|
||||
release.index = 3
|
||||
release.pressed = false
|
||||
release.position = fire_stick.global_position + fire_stick.size * 0.5
|
||||
fire_stick.handle_touch(release)
|
||||
|
||||
|
||||
func _process(delta: float) -> bool:
|
||||
elapsed += delta
|
||||
match stage:
|
||||
0:
|
||||
if elapsed < 0.3:
|
||||
return false
|
||||
main.get_node("EnemySpawner").set_process(false)
|
||||
main.get_node("AsteroidField").set_process(false)
|
||||
for hazard in get_nodes_in_group("asteroids") + get_nodes_in_group("enemies"):
|
||||
if is_instance_valid(hazard):
|
||||
hazard.queue_free()
|
||||
for projectile in get_nodes_in_group("player_projectiles"):
|
||||
projectile.free()
|
||||
|
||||
fleet.spawn_ships(1, Vector2.ZERO, PackedStringArray([GameState.VESSEL_INTERCEPTOR]))
|
||||
var ship: Node2D = fleet.ships[0]
|
||||
var weapon: Node = ship.get_component("weapon")
|
||||
if weapon == null:
|
||||
return _fail("the default vessel has no weapon component to test")
|
||||
# Parked at a third of fire range, dead ahead: the old auto-aiming
|
||||
# gun would have opened up on this immediately.
|
||||
decoy = load("res://Enemy.tscn").instantiate()
|
||||
decoy.position = ship.global_position + Vector2(weapon.fire_range * 0.33, 0.0)
|
||||
main.add_child(decoy)
|
||||
decoy.speed = 0.0
|
||||
print("a target sits %.0f away, well inside the gun's %.0f range" \
|
||||
% [ship.global_position.distance_to(decoy.position), weapon.fire_range])
|
||||
stage = 1
|
||||
elapsed = 0.0
|
||||
return false
|
||||
1:
|
||||
# --- A. idle stick, idle gun -----------------------------------
|
||||
shots_while_idle = maxi(shots_while_idle, _projectile_count())
|
||||
if elapsed < 1.5:
|
||||
return false
|
||||
if shots_while_idle != 0:
|
||||
return _fail("the fleet fired %d shot(s) with the stick untouched - the gun is still aiming itself" \
|
||||
% shots_while_idle)
|
||||
print("1.5s with the stick untouched: no shots fired")
|
||||
|
||||
_push_stick(FIRE_DIRECTION)
|
||||
if fire_stick.direction.normalized().distance_to(FIRE_DIRECTION) > 0.01:
|
||||
return _fail("pushing the stick reported direction %s, expected %s" \
|
||||
% [fire_stick.direction, FIRE_DIRECTION])
|
||||
stage = 2
|
||||
elapsed = 0.0
|
||||
return false
|
||||
2:
|
||||
# --- B. it fires, along the stick ------------------------------
|
||||
if elapsed < 0.6:
|
||||
return false
|
||||
var projectiles: Array = get_nodes_in_group("player_projectiles")
|
||||
if projectiles.is_empty():
|
||||
return _fail("pushing the fire stick did not fire anything")
|
||||
for projectile in projectiles:
|
||||
var heading: Vector2 = projectile.velocity.normalized()
|
||||
if heading.distance_to(FIRE_DIRECTION) > 0.05:
|
||||
return _fail("a shot travelled along %s, but the stick was pushed %s" \
|
||||
% [heading, FIRE_DIRECTION])
|
||||
print("%d shot(s) fired, every one along the stick's heading" % projectiles.size())
|
||||
|
||||
# --- E. the aim guide ------------------------------------------
|
||||
if controller.aim_direction == Vector2.ZERO:
|
||||
return _fail("the aim guide has no heading while the stick is held")
|
||||
if controller.aim_direction.normalized().distance_to(FIRE_DIRECTION) > 0.05:
|
||||
return _fail("the guide points along %s but the stick was pushed %s" \
|
||||
% [controller.aim_direction.normalized(), FIRE_DIRECTION])
|
||||
var weapon: Node = fleet.ships[0].get_component("weapon")
|
||||
if not is_equal_approx(controller.guide_range(), weapon.fire_range):
|
||||
return _fail("the guide reaches %.0f but the gun shoots %.0f" \
|
||||
% [controller.guide_range(), weapon.fire_range])
|
||||
print("aim guide drawn along the stick, reaching the gun's own %.0f range" % weapon.fire_range)
|
||||
|
||||
_release_stick()
|
||||
if fire_stick.direction != Vector2.ZERO:
|
||||
return _fail("releasing the stick left it reporting %s" % fire_stick.direction)
|
||||
# One frame for the controller to push the release through to the
|
||||
# weapons, then clear the sky so what follows is unambiguous.
|
||||
controller._process(0.0)
|
||||
for projectile in get_nodes_in_group("player_projectiles"):
|
||||
projectile.free()
|
||||
stage = 3
|
||||
elapsed = 0.0
|
||||
return false
|
||||
3:
|
||||
# --- C. released means stopped ---------------------------------
|
||||
if _projectile_count() != 0:
|
||||
return _fail("the gun kept firing after the stick was released")
|
||||
if elapsed < 1.2:
|
||||
return false
|
||||
if controller.is_firing():
|
||||
return _fail("a weapon still reports itself firing after release")
|
||||
if controller.aim_direction != Vector2.ZERO:
|
||||
return _fail("the aim guide is still drawn after the stick was released")
|
||||
print("1.2s after release: nothing fired")
|
||||
|
||||
# --- D. the stick claims only its own rect ---------------------
|
||||
var outside := InputEventScreenTouch.new()
|
||||
outside.index = 5
|
||||
outside.pressed = true
|
||||
outside.position = fire_stick.global_position - Vector2(40.0, 40.0)
|
||||
if fire_stick.handle_touch(outside):
|
||||
return _fail("the fire stick claimed a touch outside its own rect, which would swallow world gestures")
|
||||
print("a touch outside the stick's rect falls through")
|
||||
|
||||
print("TEST_FIRE_STICK: PASS")
|
||||
quit(0)
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _fail(message: String) -> bool:
|
||||
print("TEST_FIRE_STICK: FAIL (%s)" % message)
|
||||
quit(1)
|
||||
return true
|
||||
1
tests/test_fire_stick.gd.uid
Normal file
1
tests/test_fire_stick.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://da87mqssstsx6
|
||||
1
tests/test_setup_file_identity.gd.uid
Normal file
1
tests/test_setup_file_identity.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://cvw1mjejsu7pv
|
||||
Loading…
Reference in a new issue