#46: sprint becomes a permanent speed upgrade

Owning the Sprint upgrade now multiplies the scarecrow's speed by
sprint_speed_mult (1.25) all the time, walking and running, on every
platform; the run clip speeds up to match. The hold-to-sprint burst is
gone: sprint_time, sprint_cooldown, the stamina state in PlayerCharacter
(can_sprint is now has_sprint), and the HUD's stamina bar. The upgrade
keeps its id, cost, and name; its text is "Run 25% faster, always".
The sprint input action stays in project.godot, unused.

Tests: test_scarecrow's sprint checks cover 1x without it, x1.25 with it
(run and walk, clip speed, network strength), 30 s with no time limit,
no cooldown, the next morning, and no platform dependence; test_nights
checks it after the retry and a loaded save; test_economy checks the
text matches the multiplier, the menu row, and that an old save's
{"sprint": 1} still owns it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-14 14:32:39 -04:00
parent f0291133fd
commit 962c7b0b93
9 changed files with 138 additions and 149 deletions

View file

@ -142,7 +142,7 @@ func _ready() -> void:
var t0 := Time.get_ticks_msec()
config = campaign.config
campaign.set_physics_process(false) # ticked from step(), after the simulation
player.config = config # the sprint
player.config = config # Sprint's speed boost
player.campaign = campaign
var shed_zone := zones.zone(FarmZone.Kind.SUPPLY_SHED)
var pen_zone := zones.zone(FarmZone.Kind.ANIMAL_PEN)

View file

@ -45,12 +45,11 @@ extends Resource
## Patch up: hold for patch_time (rooted, no shooting) to restore patch_heal HP.
@export var patch_time: float = 2.0
@export_range(1, 100) var patch_heal: int = 3
## Sprint (the workbench's Sprint upgrade): hold sprint while moving to run sprint_speed_mult
## times as fast for up to sprint_time seconds; once it ends, sprint_cooldown seconds until the
## next one.
@export var sprint_speed_mult: float = 1.8
@export var sprint_time: float = 4.0
@export var sprint_cooldown: float = 10.0
## Sprint (the workbench's Sprint upgrade): once it's bought, the scarecrow moves
## sprint_speed_mult times as fast for good, walking and running alike (PlayerCharacter). No
## button, time limit, or cooldown. Its "text" in upgrades below names the boost: keep the two
## in step.
@export var sprint_speed_mult: float = 1.25
@export_group("Farm assets")
## Crop units and animals on the farm when the vacation starts; they must match the farm scene
@ -148,8 +147,8 @@ extends Resource
## "name", "track" (the menu's heading), "text": what it does.
## "stat": the one stat it changes. Stats are GameConfig settings, plus scarecrow_max_hp (the
## scarecrow's, in FarmState) and barrier_hp (fences' and gates' health). One without a stat
## unlocks something instead (sprint: PlayerCharacter; the weapons: ScarecrowCombat; radar:
## RadarHud).
## does something else instead (sprint: PlayerCharacter's speed, by sprint_speed_mult; the
## weapons: ScarecrowCombat; radar: RadarHud).
## "mult" multiplies the stat, "add" adds to it: a number (the same every level) or an Array
## with one entry per level. Each owned level's entry applies in turn, so they stack.
## "levels": how many times it can be bought (1 by default). Level L costs costs[id] x
@ -180,7 +179,7 @@ extends Resource
"texts": ["+2 max health", "+2 more max health", "+2 more max health"]},
"pouch_upgrade": {"name": "Bigger pouch", "track": "Scarecrow", "stat": "pouch_capacity", "add": [8, 4, 4], "levels": 3,
"texts": ["+8 pouch capacity (16 total)", "+4 pouch capacity (20 total)", "+4 pouch capacity (24 total)"]},
"sprint": {"name": "Sprint", "text": "Sprint 80% faster for 4 s at a time, every 10 s", "track": "Scarecrow"},
"sprint": {"name": "Sprint", "text": "Run 25% faster, always", "track": "Scarecrow"},
"reinforced_fences": {"name": "Reinforced fences", "track": "Defenses", "stat": "barrier_hp", "mult": [1.5, 1.25, 1.25], "levels": 3,
"texts": ["Fences and gates +50% health", "Fences and gates another +25% health", "Fences and gates +25% health again"]},
"long_range": {"name": "Long-range defenses", "track": "Defenses", "stat": "turret_range", "mult": [1.3, 1.15, 1.15], "levels": 3,

View file

@ -7,15 +7,16 @@ extends CharacterBody3D
## (start_channel: patching up, gathering) it is rooted and loops the channel's clip; once fallen
## (die) it plays the death clip and takes no input until revived. set_flash() tints the model
## for hit feedback.
## Sprint (the workbench's Sprint upgrade): holding sprint (Shift / L3) while moving runs at
## GameConfig.sprint_speed_mult times run_speed, the run clip sped up to match, for up to
## sprint_time seconds; once it ends (time's up, let go, or stopped) it takes sprint_cooldown
## seconds to come back. FarmSim sets config and campaign; without them, or without the upgrade,
## there's no sprint.
## Sprint (the workbench's Sprint upgrade): once it's bought, the scarecrow moves
## GameConfig.sprint_speed_mult times as fast for good (speed_factor), walking and running alike,
## on every platform, and the run clip plays that much faster to match. There's no button, time
## limit, or cooldown. FarmSim sets config and campaign; without them, or without the upgrade, it
## moves at run_speed.
## Co-op: the other machine's scarecrow is remote_driven: it eases toward the position and facing
## it was last sent (net_position, net_yaw) and animates by net_speed (like input strength: 1 at
## run speed, more while sprinting) instead of reading the input. Each scarecrow sprints on the
## machine that plays it. set_tint() and set_tag() tell the two scarecrows apart.
## run speed, more with the Sprint upgrade) instead of reading the input. Each scarecrow's speed
## is worked out on the machine that plays it. set_tint() and set_tag() tell the two scarecrows
## apart.
## The core glow: every scarecrow has a small blue core in its chest (the alien part it absorbed
## in the opening intro): a glowing gem on the chest bone (so it follows the animation), a soft
## halo, and a weak blue light, pulsing slowly. It's unshaded (the toon look and the hit flash
@ -90,13 +91,9 @@ var net_position := Vector3.ZERO
var net_yaw: float = 0.0
var net_speed: float = 0.0
## Set by FarmSim: the sprint's tuning, and the farm state that says whether it's unlocked.
## Set by FarmSim: Sprint's speed boost, and the farm state that says whether it's bought.
var config: GameConfig
var campaign: CampaignController
## Sprinting now, seconds of it left, and seconds until the next one (0 = ready).
var sprinting := false
var sprint_left: float = 0.0
var sprint_recharge: float = 0.0
var _aim := Vector2.ZERO
var _aim_hold: float = 0.0
@ -130,7 +127,6 @@ func _physics_process(delta: float) -> void:
_follow_net(delta)
return
var move := _move_direction() if alive and not rooted else Vector3.ZERO
step_sprint(delta, can_sprint() and input_enabled and Input.is_action_pressed("sprint"), move.length_squared() > 1e-4)
var horizontal := Vector3(velocity.x, 0.0, velocity.z).move_toward(move * run_speed * speed_factor(), acceleration * delta)
velocity.x = horizontal.x
velocity.z = horizontal.z
@ -169,46 +165,20 @@ func snap_to_net(at: Vector3, yaw: float) -> void:
model.rotation.y = yaw
## Movement strength for the network: 0 standing .. 1 at run speed (more while sprinting).
## Movement strength for the network: 0 standing .. 1 at run speed (sprint_speed_mult at full
## speed with the Sprint upgrade).
func move_strength() -> float:
return clampf(Vector2(velocity.x, velocity.z).length() / run_speed, 0.0, 2.0)
## Whether the Sprint upgrade is owned.
func can_sprint() -> bool:
func has_sprint() -> bool:
return config != null and campaign != null and Upgrades.owned(campaign.state, "sprint")
## Speed relative to run_speed: sprint_speed_mult while sprinting.
## Speed relative to run_speed: sprint_speed_mult with the Sprint upgrade, else 1.
func speed_factor() -> float:
return config.sprint_speed_mult if sprinting else 1.0
## One tick of the sprint: starts one while held and moving (when unlocked and recharged); ends
## it when its time is up, it's let go, or the scarecrow stops; then counts the recharge down.
func step_sprint(dt: float, held: bool, moving: bool) -> void:
if sprinting:
sprint_left -= dt
if sprint_left <= 0.0 or not held or not moving or not alive or not can_sprint():
_end_sprint()
return
sprint_recharge = maxf(sprint_recharge - dt, 0.0)
if held and moving and alive and sprint_recharge == 0.0 and can_sprint():
sprinting = true
sprint_left = config.sprint_time
## Ready to sprint again at once (a new morning).
func reset_sprint() -> void:
sprinting = false
sprint_left = 0.0
sprint_recharge = 0.0
func _end_sprint() -> void:
sprinting = false
sprint_left = 0.0
sprint_recharge = config.sprint_cooldown if config != null else 0.0
return config.sprint_speed_mult if has_sprint() else 1.0
## Shows or hides the core glow in the chest (on from the start).
@ -342,7 +312,6 @@ func stop_channel() -> void:
func die() -> void:
alive = false
rooted = false
reset_sprint()
animation_player.speed_scale = 1.0
animation_player.play(death_animation, 0.15)
@ -351,7 +320,6 @@ func revive() -> void:
alive = true
rooted = false
_aim_hold = 0.0
reset_sprint()
animation_player.play(idle_animation, 0.1)
@ -382,7 +350,7 @@ func _update_animation(strength: float) -> void:
clip = run_animation
elif strength > 0.0:
clip = walk_animation
# A sprint (strength above 1) plays the run clip faster.
# The Sprint upgrade's speed (strength above 1) plays the run clip faster.
animation_player.speed_scale = maxf(strength, 1.0) if clip == run_animation else 1.0
if animation_player.current_animation != clip:
animation_player.play(clip, blend_time)

View file

@ -5,8 +5,7 @@ extends Control
## arc sweeping round while fear recharges, glowing blue when it's ready (a flash as it
## becomes ready); greyed out while the scarecrow is down. Beside it the health bar, one
## segment per point of max health (red filled, grey empty; while patching, the segments the
## patch will fill fill in), and under it, once the Sprint upgrade is bought, a thin green
## bar: the sprint's stamina (draining while sprinting, filling back while it recharges).
## patch will fill fill in).
## * Bottom-center: the hotbar, one slot per main weapon owned (locked ones aren't shown),
## numbered by the key that picks it (ScarecrowCombat.owned_main: weapon_k picks slot k), the
## one in hand highlighted; then past a divider the off-hand weapons owned (pumpkin bombs), in a
@ -24,10 +23,8 @@ const SEGMENT_SKEW := 7.0
## The health bar grows a segment per point of max health up to this width, then its segments
## get narrower.
const BAR_MAX_WIDTH := 360.0
const STAMINA_HEIGHT := 6.0
const HEALTH := Color(0.88, 0.14, 0.12)
const EMPTY := Color(0.62, 0.62, 0.6, 0.85)
const STAMINA := Color(0.3, 0.9, 0.25)
const SLOT := Vector2(78.0, 72.0)
const SLOT_GAP := 16.0
const DIVIDER_GAP := 30.0
@ -88,24 +85,6 @@ func _process(delta: float) -> void:
queue_redraw()
## Whether the green stamina bar shows: only once the Sprint upgrade is bought.
func stamina_shown() -> bool:
var body := kit.player if kit != null else null
return body != null and body.config != null and body.can_sprint()
## The green bar's fill, 0..1: the sprint left while sprinting, its recharge after, else full.
func stamina() -> float:
if not stamina_shown():
return 1.0
var body := kit.player
if body.sprinting:
return clampf(body.sprint_left / maxf(body.config.sprint_time, 0.001), 0.0, 1.0)
if body.sprint_recharge > 0.0:
return clampf(1.0 - body.sprint_recharge / maxf(body.config.sprint_cooldown, 0.001), 0.0, 1.0)
return 1.0
## The hotbar's slots as shown, left to right: {weapon, key (the number that picks it; 0 for
## the off-hand), offhand, selected}. Empty while it's hidden (build mode, no weapons).
func slots() -> Array[Dictionary]:
@ -163,7 +142,6 @@ func _draw_health() -> void:
var hp := kit.hp()
var step := minf(SEGMENT.x + SEGMENT_GAP, (BAR_MAX_WIDTH + SEGMENT_GAP) / top)
var seg := Vector2(maxf(step - SEGMENT_GAP, 4.0), SEGMENT.y)
var width := step * top - SEGMENT_GAP
var healing := 0
var heal_frac := 0.0
if kit.patching:
@ -179,16 +157,6 @@ func _draw_health() -> void:
if i < hp: # a darker stroke along the bottom, like paint pooling
Sketch.line(self, at + Vector2(3.0, seg.y - 4.0), at + Vector2(seg.x - 3.0, seg.y - 4.0), full.darkened(0.3), 3.0, 60.0 + i, 0.6)
Sketch.outline(self, pts, Color(Sketch.INK, 0.55), 1.5, 80.0 + i, 0.8, 1)
if not stamina_shown():
return
# The stamina bar, as wide as the health bar.
var bar := Rect2(BAR_ORIGIN + Vector2(0.0, SEGMENT.y + 12.0), Vector2(maxf(width, 120.0), STAMINA_HEIGHT))
var y := bar.get_center().y
Sketch.line(self, Vector2(bar.position.x, y), Vector2(bar.end.x, y), Color(Sketch.INK, 0.6), STAMINA_HEIGHT + 3.0, 101.0, 0.6)
Sketch.line(self, Vector2(bar.position.x, y), Vector2(bar.end.x, y), Color(0.16, 0.3, 0.14, 0.9), STAMINA_HEIGHT, 101.0, 0.6)
var fill := stamina()
if fill > 0.0:
Sketch.line(self, Vector2(bar.position.x, y), Vector2(bar.position.x + bar.size.x * fill, y), STAMINA, STAMINA_HEIGHT, 102.0, 0.6)
## A health segment: a slanted brush stroke.

View file

@ -15,8 +15,9 @@ extends RefCounted
## the scarecrow's max health (FarmState) when a level is bought, and the Bigger pouch upgrade
## raises pouch_capacity (ResourceStore, shared: every scarecrow's pouch grows) the same way. The
## buyer pays from their own pouch and the shed (slot). Sprint, the weapons, and radar change no
## stat: owning them (owned(): level 1 or more) unlocks sprinting (PlayerCharacter), the weapons
## (ScarecrowCombat), and the minimap (RadarHud). Rapid fire and heavy seeds (bought at the
## stat here; owning one (owned(): level 1 or more) is what counts: Sprint makes the scarecrow
## faster for good (PlayerCharacter.speed_factor, by GameConfig.sprint_speed_mult), the weapons
## unlock in ScarecrowCombat, and radar's minimap in RadarHud. Rapid fire and heavy seeds (bought at the
## workbench) need the corn shooter (bought at the shed) first ("requires" crosses shops freely).
## Menu order, grouped by track.
@ -31,8 +32,8 @@ static func level(state: FarmState, id: String) -> int:
return int(state.upgrades.get(id, 0)) if state != null else 0
## Owned at any level (level 1 or more): what "requires" and the unlocks (sprint, the weapons,
## radar) ask.
## Owned at any level (level 1 or more): what "requires" and the stat-less ones (sprint's speed,
## the weapons, radar) ask.
static func owned(state: FarmState, id: String) -> bool:
return level(state, id) > 0