#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:
parent
f0291133fd
commit
962c7b0b93
9 changed files with 138 additions and 149 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue