Merge #46: sprint becomes a permanent speed upgrade
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
7e510bb446
9 changed files with 138 additions and 149 deletions
|
|
@ -263,7 +263,8 @@ func _hidden_items(r: GameTestRunner) -> void:
|
|||
## multipliers multiply). upgrades_bought counts every level. The menu names the next level
|
||||
## ("Heavy seeds II") with its text and cost, says when it opens, and shows "Max" at the end.
|
||||
## Levels survive a save, the next morning, and a retry, and an old save's {"rapid_fire": 1}
|
||||
## loads as level 1.
|
||||
## loads as level 1. Sprint (#46) is a speed upgrade now: its text names sprint_speed_mult, the
|
||||
## menu offers it as that, and an old save's {"sprint": 1} still owns it (the id is unchanged).
|
||||
func _tiers(r: GameTestRunner) -> void:
|
||||
var c := r.make_campaign((load("res://game/resources/game_config.tres") as GameConfig).duplicate(true) as GameConfig)
|
||||
var cfg := c.config
|
||||
|
|
@ -275,6 +276,11 @@ func _tiers(r: GameTestRunner) -> void:
|
|||
r.check(tiered == 9 and Upgrades.max_level(cfg, "sprint") == 1 and Upgrades.max_level(cfg, "corn_shooter") == 1
|
||||
and Upgrades.max_level(cfg, "alien_ray") == 1 and Upgrades.max_level(cfg, "radar") == 1,
|
||||
"the nine stat upgrades have 3 levels; Sprint, the weapons, and Radar one (%d with 3)" % tiered)
|
||||
var defaults := GameConfig.new()
|
||||
var says := "Run %d%% faster, always"
|
||||
r.check(Upgrades.text_at(cfg, "sprint", 1) == says % roundi((cfg.sprint_speed_mult - 1.0) * 100.0)
|
||||
and Upgrades.text_at(defaults, "sprint", 1) == says % roundi((defaults.sprint_speed_mult - 1.0) * 100.0),
|
||||
"Sprint says what it does: '%s' (x%.2f; game_config.gd's defaults agree)" % [Upgrades.text_at(cfg, "sprint", 1), cfg.sprint_speed_mult])
|
||||
# Costs grow.
|
||||
var grows := true
|
||||
for id: String in cfg.upgrades:
|
||||
|
|
@ -304,6 +310,9 @@ func _tiers(r: GameTestRunner) -> void:
|
|||
var row := panel._rows["heavy_seeds"] as Button
|
||||
r.check(row.text == "Heavy seeds I — Each kernel does 2 damage (%s)" % ResourceStore.describe(Upgrades.cost(cfg, "heavy_seeds", 1)) and not row.disabled,
|
||||
"the menu offers level I: '%s'" % row.text)
|
||||
var sprint_row := panel._rows["sprint"] as Button
|
||||
r.check(sprint_row.text == "Sprint — %s (%s)" % [Upgrades.text_at(cfg, "sprint", 1), ResourceStore.describe(Upgrades.cost(cfg, "sprint", 1))]
|
||||
and not sprint_row.disabled, "the menu offers Sprint as the speed upgrade: '%s'" % sprint_row.text)
|
||||
var damage := cfg.shot_damage
|
||||
r.check(Upgrades.buy(c, "heavy_seeds").contains("done:") and Upgrades.level(s, "heavy_seeds") == 1
|
||||
and roundi(Upgrades.value(cfg, s, "shot_damage")) == damage + 1, "level 1 on day 1: kernels do %d damage" % (damage + 1))
|
||||
|
|
@ -373,13 +382,15 @@ func _tiers(r: GameTestRunner) -> void:
|
|||
"and a retry from that morning keeps them")
|
||||
# A save from before levels: {"rapid_fire": 1} is level 1.
|
||||
var old := c.state.to_dict()
|
||||
old["upgrades"] = {"corn_shooter": 1, "rapid_fire": 1}
|
||||
old["upgrades"] = {"corn_shooter": 1, "rapid_fire": 1, "sprint": 1}
|
||||
var was := SaveGame.read(TIERS_SAVE).state if SaveGame.write(old, TIERS_SAVE) == OK else null
|
||||
SaveGame.delete(TIERS_SAVE)
|
||||
r.check(was != null and Upgrades.level(was, "rapid_fire") == 1 and Upgrades.owned(was, "rapid_fire")
|
||||
and is_equal_approx(Upgrades.value(cfg, was, "fire_rate"), cfg.fire_rate * Upgrades.per_level(mult, 1))
|
||||
and Upgrades.next_cost(cfg, was, "rapid_fire") == Upgrades.cost(cfg, "rapid_fire", 2),
|
||||
"an old save's {\"rapid_fire\": 1} loads as level 1, with level 2 next")
|
||||
r.check(was != null and Upgrades.owned(was, "sprint") and Upgrades.level(was, "sprint") == 1,
|
||||
"and its {\"sprint\": 1} still owns Sprint, now the speed upgrade (same id)")
|
||||
c.queue_free()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -193,7 +193,7 @@ func _upgrades(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void
|
|||
var morning := s.to_dict()
|
||||
var shed := s.resources.shed_total()
|
||||
var spent := 0
|
||||
r.check(not player.can_sprint(), "(no sprint before the Sprint upgrade)")
|
||||
r.check(not player.has_sprint() and player.speed_factor() == 1.0, "(no Sprint before the upgrade: 1x speed)")
|
||||
var day := s.night
|
||||
s.night = 14 # every shed item is in stock by day 14 (#26's from_day)
|
||||
for id in Upgrades.ORDER:
|
||||
|
|
@ -202,7 +202,8 @@ func _upgrades(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void
|
|||
r.check(Upgrades.level(s, id) == 1 and text.contains("done:"), "bought %s: '%s'" % [id, text])
|
||||
s.night = day
|
||||
r.check(s.resources.shed_total() == shed - spent, "all %d cost %d materials together (level 1 each)" % [Upgrades.ORDER.size(), spent])
|
||||
r.check(player.can_sprint(), "sprint: the scarecrow can sprint")
|
||||
r.check(player.has_sprint() and is_equal_approx(player.speed_factor(), cfg.sprint_speed_mult),
|
||||
"sprint: the scarecrow is faster for good (x%.2f)" % player.speed_factor())
|
||||
r.check(Upgrades.buy(c, "sprint", st).contains("already done") and Upgrades.buy(c, "rapid_fire", st).contains("level 2 opens on day 8")
|
||||
and Upgrades.level(s, "rapid_fire") == 1, "a one-off can't be bought twice, and an upgrade's level 2 waits for day 8")
|
||||
r.check(sim.combat.interval_ticks() < int(before["interval"]) and sim.combat.shot_damage() == int(before["damage"]) + 1,
|
||||
|
|
@ -261,12 +262,20 @@ func _upgrades(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void
|
|||
_step(sim, 1)
|
||||
c.retry_night()
|
||||
r.check(s != c.state and c.state.upgrades == bought, "a retry from that morning keeps them")
|
||||
r.check(is_equal_approx(player.speed_factor(), cfg.sprint_speed_mult), "Sprint's speed too, after the retry (x%.2f)" % player.speed_factor())
|
||||
var old := FarmState.from_dict(morning)
|
||||
r.check(old.upgrades.is_empty() and old.resources.shed_total() == shed, "(the morning before they were bought had none, and the materials)")
|
||||
c.new_campaign()
|
||||
_step(sim, 1)
|
||||
r.check(c.state.upgrades.is_empty() and sim.combat.shot_damage() == 1 and st.max_hp("fence") == cfg.fence_hp and not player.can_sprint(),
|
||||
r.check(c.state.upgrades.is_empty() and sim.combat.shot_damage() == 1 and st.max_hp("fence") == cfg.fence_hp and not player.has_sprint()
|
||||
and player.speed_factor() == 1.0,
|
||||
"a new vacation starts without them")
|
||||
c.load_state(back)
|
||||
_step(sim, 1)
|
||||
r.check(player.has_sprint() and is_equal_approx(player.speed_factor(), cfg.sprint_speed_mult),
|
||||
"continuing the save brings Sprint's speed back (x%.2f)" % player.speed_factor())
|
||||
c.new_campaign()
|
||||
_step(sim, 1)
|
||||
player.global_position = AWAY
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,16 +4,18 @@ extends RefCounted
|
|||
## not through cover, not while fleeing), fear (only thieves in range flee, carriers drop their
|
||||
## crop, thieves mid-steal lose their progress, the cooldown, thieves come back afterwards),
|
||||
## patching up (heals after the full channel while rooted; release, a hit, or fear cancel it;
|
||||
## not at full health), sprint (only with the Sprint upgrade: faster while held and moving, 3 s at
|
||||
## most, then a 10 s recharge; letting go or stopping ends it early; the HUD line), defeat (Game
|
||||
## Over ahead of a stripped farm, the fall, the end panel and its Retry), the morning revive, and
|
||||
## the new input actions.
|
||||
## not at full health), Sprint (#46: the upgrade makes it sprint_speed_mult times as fast for
|
||||
## good, walking and running, with nothing to hold, no time limit, no cooldown, and no stamina
|
||||
## bar), defeat (Game Over ahead of a stripped farm, the fall, the end panel and its Retry), the
|
||||
## morning revive, and the new input actions.
|
||||
|
||||
const S := LootSystem.Status
|
||||
const T := ThiefBehavior.State
|
||||
const DT := 1.0 / 60.0
|
||||
const AWAY := Vector3(-11.0, 0.0, 13.0)
|
||||
const SPOT := Vector2(8.0, -10.0) # open ground between the pen, the shed, and the field
|
||||
## A light stick: it walks (under run_threshold even with the Sprint upgrade).
|
||||
const WALK_STICK := 0.4
|
||||
|
||||
|
||||
func run(r: GameTestRunner) -> void:
|
||||
|
|
@ -40,7 +42,7 @@ func run(r: GameTestRunner) -> void:
|
|||
|
||||
|
||||
func _input_actions(r: GameTestRunner) -> void:
|
||||
for action in ["fear", "patch", "interact", "build_mode", "rotate_left", "rotate_right", "cancel", "pause", "sprint"]:
|
||||
for action in ["fear", "patch", "interact", "build_mode", "rotate_left", "rotate_right", "cancel", "pause"]:
|
||||
var keyboard := false
|
||||
var pad := false
|
||||
if InputMap.has_action(action):
|
||||
|
|
@ -184,59 +186,90 @@ func _patch(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter) -> void:
|
|||
_heal(sim)
|
||||
|
||||
|
||||
## Sprint (#46): owning the upgrade makes the scarecrow sprint_speed_mult times as fast for good,
|
||||
## walking and running alike, on desktop and phones. Nothing is held (the old sprint key does
|
||||
## nothing), and there's no time limit, no cooldown, and no stamina bar.
|
||||
func _sprint(r: GameTestRunner, sim: FarmSim, player: PlayerCharacter, hud: ScarecrowHud) -> void:
|
||||
var cfg := sim.config
|
||||
var mult := cfg.sprint_speed_mult
|
||||
var s := sim.campaign.state
|
||||
var start := Vector3(0.0, 0.0, 6.0) # the open ground south-west of the pen
|
||||
s.upgrades.erase("sprint")
|
||||
hud._process(0.0)
|
||||
r.check(not player.can_sprint() and not hud.stamina_shown(), "no sprint before the upgrade (and no stamina bar on the HUD)")
|
||||
# On the real body, over physics frames: the open ground south-west of the pen.
|
||||
player.global_position = Vector3(0.0, 0.0, 6.0)
|
||||
player.velocity = Vector3.ZERO
|
||||
Input.action_press("move_right")
|
||||
Input.action_press("sprint")
|
||||
await _frames(r, 30)
|
||||
var speed := Vector2(player.velocity.x, player.velocity.z).length()
|
||||
r.check(not player.sprinting and speed <= player.run_speed + 0.05, "without it, holding sprint just runs (%.1f m/s)" % speed)
|
||||
r.check(not player.has_sprint() and player.speed_factor() == 1.0 and not hud.has_method(&"stamina"),
|
||||
"no Sprint before the upgrade: 1x speed (and the HUD has no stamina bar)")
|
||||
# On the real body, over physics frames: a full stick runs, a light one walks.
|
||||
var old_key := InputMap.has_action("sprint")
|
||||
if old_key:
|
||||
Input.action_press("sprint") # the old hold-to-sprint key
|
||||
var run0: float = await _speed_after(r, player, start, 1.0)
|
||||
var walk0: float = await _speed_after(r, player, start, WALK_STICK)
|
||||
if old_key:
|
||||
Input.action_release("sprint")
|
||||
r.check(absf(run0 - player.run_speed) < 0.05, "without it, it runs at %.2f m/s, even holding the old sprint key" % run0)
|
||||
s.upgrades["sprint"] = 1
|
||||
await _frames(r, 30)
|
||||
speed = Vector2(player.velocity.x, player.velocity.z).length()
|
||||
r.check(player.sprinting and absf(speed - player.run_speed * cfg.sprint_speed_mult) < 0.1,
|
||||
"with the Sprint upgrade, holding sprint while moving sprints: %.1f m/s (runs at %.1f)" % [speed, player.run_speed])
|
||||
r.check(player.animation_player.current_animation == player.run_animation and player.animation_player.speed_scale > 1.5,
|
||||
"the run clip plays faster (x%.2f)" % player.animation_player.speed_scale)
|
||||
r.check(player.move_strength() > 1.5, "the partner's machine is told it's sprinting (strength %.2f)" % player.move_strength())
|
||||
r.check(hud.stamina_shown() and hud.stamina() < 1.0 and is_equal_approx(hud.stamina(), player.sprint_left / cfg.sprint_time),
|
||||
"the HUD's stamina bar appears, and drains while sprinting (%.2f)" % hud.stamina())
|
||||
var run1: float = await _speed_after(r, player, start, 1.0)
|
||||
r.check(absf(run1 - player.run_speed * mult) < 0.05,
|
||||
"with the Sprint upgrade it runs x%.2f with nothing held: %.2f m/s (%.2f without)" % [mult, run1, run0])
|
||||
r.check(player.animation_player.current_animation == player.run_animation and absf(player.animation_player.speed_scale - mult) < 0.02,
|
||||
"the run clip plays x%.2f to match" % player.animation_player.speed_scale)
|
||||
r.check(absf(player.move_strength() - mult) < 0.02, "the partner's machine is told it's faster (strength %.2f)" % player.move_strength())
|
||||
var walk1: float = await _speed_after(r, player, start, WALK_STICK)
|
||||
r.check(walk0 > 0.5 and absf(walk1 - walk0 * mult) < 0.05 and player.animation_player.current_animation == player.walk_animation,
|
||||
"walking (a light stick) is x%.2f too: %.2f m/s (%.2f without), on the walk clip" % [walk1 / maxf(walk0, 0.001), walk1, walk0])
|
||||
# No time limit: 30 s of moving without a stop, the body stepped tick by tick inside one physics
|
||||
# frame and put back on the open ground each second.
|
||||
Input.action_press("move_right")
|
||||
await r.physics_frame
|
||||
var span := _hand_step(player, start, 30.0)
|
||||
var last := Vector2(player.velocity.x, player.velocity.z).length()
|
||||
r.check(absf(span.x - run1) < 0.05 and absf(span.y - run1) < 0.05 and absf(last - run1) < 0.05,
|
||||
"no time limit: after 30 s of moving it still runs %.2f m/s (%.2f..%.2f m/s throughout)" % [last, span.x, span.y])
|
||||
# No cooldown: stop, then go again.
|
||||
Input.action_release("move_right")
|
||||
await _frames(r, 2)
|
||||
r.check(not player.sprinting and player.sprint_recharge > cfg.sprint_cooldown - 0.1, "stopping ends it, and the recharge starts")
|
||||
r.check(hud.stamina() < 0.1, "and starts filling back as it recharges (%.2f)" % hud.stamina())
|
||||
Input.action_release("sprint")
|
||||
var stopped := _hand_step(player, start, 1.0)
|
||||
Input.action_press("move_right")
|
||||
var again := _hand_step(player, start, 0.5)
|
||||
r.check(stopped.y < 0.05 and absf(again.x - run1) < 0.05 and absf(again.y - run1) < 0.05,
|
||||
"no cooldown: stopped, then off again at once at %.2f m/s" % again.y)
|
||||
Input.action_release("move_right")
|
||||
sim.scarecrow.reset_for_morning()
|
||||
r.check(is_equal_approx(player.speed_factor(), mult), "a new morning keeps it (x%.2f)" % player.speed_factor())
|
||||
# Phones: the speed path never asks the platform, so MobilePort.active() makes no difference.
|
||||
var asks := false
|
||||
for script: GDScript in [player.get_script(), load("res://game/scripts/upgrades.gd")]:
|
||||
asks = asks or script.source_code.contains("MobilePort")
|
||||
r.check(not asks, "the speed doesn't depend on the platform (PlayerCharacter and Upgrades never ask MobilePort; phone mode here: %s)" % MobilePort.active())
|
||||
s.upgrades.erase("sprint")
|
||||
await _frames(r, 30)
|
||||
player.velocity = Vector3.ZERO
|
||||
player.global_position = Vector3(SPOT.x, 0.0, SPOT.y)
|
||||
# The timing, tick by tick.
|
||||
player.reset_sprint()
|
||||
var ticks := 0
|
||||
player.step_sprint(DT, true, true)
|
||||
while player.sprinting and ticks < 1200:
|
||||
player.step_sprint(DT, true, true)
|
||||
ticks += 1
|
||||
r.check(absf(ticks * DT - cfg.sprint_time) < DT * 2.0, "held, a sprint lasts %.1f s" % (ticks * DT))
|
||||
ticks = 0
|
||||
while not player.sprinting and ticks < 1200:
|
||||
player.step_sprint(DT, true, true)
|
||||
ticks += 1
|
||||
r.check(absf(ticks * DT - cfg.sprint_cooldown) < DT * 2.0, "then %.1f s to recharge, and still held it starts again" % (ticks * DT))
|
||||
player.step_sprint(1.0, true, true)
|
||||
player.step_sprint(DT, false, true)
|
||||
r.check(not player.sprinting and is_equal_approx(player.sprint_recharge, cfg.sprint_cooldown), "letting go early ends it, and the full recharge starts")
|
||||
player.step_sprint(DT, true, false)
|
||||
r.check(not player.sprinting, "and it doesn't start standing still")
|
||||
sim.scarecrow.reset_for_morning()
|
||||
r.check(player.sprint_recharge == 0.0 and hud.stamina() == 1.0, "a new morning has it ready (a full bar)")
|
||||
s.upgrades.erase("sprint")
|
||||
|
||||
|
||||
## Puts the scarecrow at a spot at rest, holds move_right at a stick strength for 30 physics
|
||||
## frames, and returns its speed (m/s). move_right stays held.
|
||||
func _speed_after(r: GameTestRunner, player: PlayerCharacter, at: Vector3, strength: float) -> float:
|
||||
player.global_position = at
|
||||
player.velocity = Vector3.ZERO
|
||||
Input.action_press("move_right", strength)
|
||||
await _frames(r, 30)
|
||||
return Vector2(player.velocity.x, player.velocity.z).length()
|
||||
|
||||
|
||||
## Steps the body by hand for that many seconds of 60 Hz ticks (call it right after awaiting
|
||||
## physics_frame, so move_and_slide moves by DT), putting it back at the spot every second so it
|
||||
## stays on open ground. Returns the lowest and highest speed (m/s) over the ticks after the
|
||||
## first quarter second (the speed-up).
|
||||
func _hand_step(player: PlayerCharacter, at: Vector3, seconds: float) -> Vector2:
|
||||
var span := Vector2(INF, 0.0)
|
||||
var ticks := roundi(seconds / DT)
|
||||
for i in ticks:
|
||||
if i % 60 == 0:
|
||||
player.global_position = at
|
||||
player._physics_process(DT)
|
||||
if i >= 15:
|
||||
var v := Vector2(player.velocity.x, player.velocity.z).length()
|
||||
span = Vector2(minf(span.x, v), maxf(span.y, v))
|
||||
return span
|
||||
|
||||
|
||||
func _frames(r: GameTestRunner, n: int) -> void:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue