Merge task #18: Alien Ray fires a piercing beam

Held beam ticking every alien_ray_tick_interval, clipped at walls,
hitting up to alien_ray_pierce enemies along it (EnemySystem.path_hits);
AlienBeam visual on the held-effect pattern from #17; zap cue.
alien_ray_speed/lifetime/cooldown replaced by range/width/tick/pierce.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Forrest 2026-10-06 13:39:38 -04:00
commit 0012b8c098
13 changed files with 554 additions and 44 deletions

View file

@ -31,5 +31,6 @@ for before release.
`synth/` is generated by `game/tools/synth_audio.gd` (deterministic, fixed seeds): the day and
night ambience loops, the crow caws and squawk, the farmers' car (engine loop and horn), the
pitchfork's whoosh, the pumpkin bomb's burst, and the propane torch's roar. Kenney's packs have
no farm ambience, birds, vehicles, explosions, or fire. Re-run the tool to regenerate them.
pitchfork's whoosh, the pumpkin bomb's burst, the propane torch's roar, and the alien ray's hum.
Kenney's packs have no farm ambience, birds, vehicles, explosions, or fire. Re-run the tool to
regenerate them.

Binary file not shown.

View file

@ -0,0 +1,24 @@
[remap]
importer="wav"
type="AudioStreamWAV"
uid="uid://ceto7qi6bygq3"
path="res://.godot/imported/alien_beam.wav-642f51d82976a361c6cc469d9ac0236b.sample"
[deps]
source_file="res://assets/audio/synth/alien_beam.wav"
dest_files=["res://.godot/imported/alien_beam.wav-642f51d82976a361c6cc469d9ac0236b.sample"]
[params]
force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2

View file

@ -104,7 +104,7 @@ upgrades = {
"hidden": true,
"name": "Alien ray",
"shop": "shed",
"text": "A salvaged alien weapon: a fast, powerful beam",
"text": "A salvaged alien weapon: a long beam that pierces everything in its line while held",
"track": "Weapon"
},
"corn_shooter": {

178
game/scripts/alien_beam.gd Normal file
View file

@ -0,0 +1,178 @@
class_name AlienBeam
extends Node3D
## The Alien Ray's beam (#18): a glowing green ray from the gun's muzzle straight out for length m,
## cut short at the first wall, with a green glow at the muzzle and a flare where a wall stops
## it. A WeaponModels held effect: it sits at the muzzle facing the way the scarecrow's model does
## (-Z), so it follows the model's yaw, which is all the partner's machine knows of the other
## scarecrow's aim. set_lit() shows it and hides it.
## While lit it is laid out again every frame (rebuild): trace() runs the same wall test as the
## damage does (ScarecrowCombat.beam_path), from the scarecrow's center through the muzzle and on,
## so its end is where the damage stops, on either machine (the walls are the same static farm on
## both, so the partner's machine needs nothing sent for it).
## The beam's parts, as shares of the ray's hit width (alien_ray_width): a white-hot core and a
## green glow around it, both unshaded and brighter than white (HDR), so the beam still burns
## through the night look's dimmed picture, and unfogged.
const CORE := 0.22
const GLOW := 0.75
const CORE_COLOR := Color(0.85, 2.2, 1.0)
const GLOW_COLOR := Color(0.25, 1.6, 0.45, 0.45)
## The glow's width pulses this much (share), this fast (Hz), so the beam hums.
const PULSE := 0.18
const PULSE_HZ := 9.0
const LIGHT_COLOR := Color(0.4, 1.0, 0.5)
const LIGHT_ENERGY := 1.8
const LIGHT_RANGE := 3.2
const FLARE_SIZE := 0.5
const WORLD_LAYER := 1
## The ray it was built for (m): how far it reaches past the muzzle, and how wide it hits.
var length: float
var width: float
var lit := false
## The beam as last laid out (world space): from the muzzle to where it ends, and whether a wall
## stopped it (at the barrel: nothing is drawn).
var start := Vector3.ZERO
var end := Vector3.ZERO
var blocked := false
var _core: MeshInstance3D
var _glow: MeshInstance3D
var _flare: MeshInstance3D
var _light: OmniLight3D
var _ray := PhysicsRayQueryParameters3D.new()
var _time := 0.0
func _init(p_length: float = 20.0, p_width: float = 0.5) -> void:
length = p_length
width = p_width
name = "AlienBeam"
_ray.collision_mask = WORLD_LAYER
_ray.collide_with_areas = false
_core = _part("Core", _cylinder(), _material(CORE_COLOR, false))
_glow = _part("Glow", _cylinder(), _material(GLOW_COLOR, true))
var ball := SphereMesh.new()
ball.radius = 0.5
ball.height = 1.0
ball.radial_segments = 12
ball.rings = 6
_flare = _part("Flare", ball, _material(GLOW_COLOR, true))
_light = OmniLight3D.new()
_light.name = "Glow"
_light.light_color = LIGHT_COLOR
_light.light_energy = LIGHT_ENERGY
_light.omni_range = LIGHT_RANGE
_light.shadow_enabled = false
add_child(_light)
set_lit(false)
## Shows the beam (laid out now and every frame after), or hides it.
func set_lit(on: bool) -> void:
lit = on
_light.visible = on
if on and is_inside_tree():
rebuild(global_transform)
else:
for mi: MeshInstance3D in [_core, _glow, _flare]:
mi.visible = false
## Lays the beam out from a transform of this node (its global one, or the interpolated one each
## frame): the muzzle is its origin, the aim its -Z (level), and the scarecrow's center the point
## at the muzzle's height straight above the model's origin. Returns how long it is (m).
func rebuild(xform: Transform3D) -> float:
var fwd := -xform.basis.z
fwd.y = 0.0
fwd = fwd.normalized() if fwd.length() > 1e-4 else Vector3.FORWARD
var center := xform * Vector3(-position.x, 0.0, -position.z) # (this node has no turn of its own)
var space := get_world_3d().direct_space_state if is_inside_tree() else null
var path := trace(space, _ray, center, xform.origin, fwd, length)
start = xform.origin
end = path[path.size() - 1]
blocked = path.size() < 3 or end.distance_to(start) < length - 1e-3
var shown := lit and path.size() == 3
var span := end - start
var span_len := span.length() if shown else 0.0
_core.visible = shown and span_len > 1e-3
_glow.visible = _core.visible
_flare.visible = _core.visible and blocked
if _core.visible:
var pulse := 1.0 + PULSE * sin(TAU * PULSE_HZ * _time)
_lay(_core, start, fwd, span_len, width * CORE)
_lay(_glow, start, fwd, span_len, width * GLOW * pulse)
_flare.global_transform = Transform3D(Basis.IDENTITY.scaled(Vector3.ONE * FLARE_SIZE * pulse), end)
return span_len
## The beam's path, world space at the gun's height: from center (the scarecrow's) through muzzle,
## then along dir (unit, level) for length m, cut at the first wall (space: the farm's physics,
## query: a ray on the world layer; null space: no walls). [center, muzzle, end], or, when a
## wall stands between the center and the muzzle (a barrel poking through it), [center, the hit].
## Shared with ScarecrowCombat, so the damage and the beam drawn end at the same wall.
static func trace(space: PhysicsDirectSpaceState3D, query: PhysicsRayQueryParameters3D, center: Vector3,
muzzle: Vector3, dir: Vector3, p_length: float) -> PackedVector3Array:
var path := PackedVector3Array([center])
for to: Vector3 in [muzzle, muzzle + dir * p_length]:
if space != null:
query.from = path[path.size() - 1]
query.to = to
var hit := space.intersect_ray(query)
if not hit.is_empty():
path.append(hit["position"])
return path
path.append(to)
return path
func _process(delta: float) -> void:
if not lit:
return
_time = fmod(_time + delta, 1.0)
rebuild(get_global_transform_interpolated())
## A part of the beam, placed in world space (top_level) each frame, drawn as it's placed.
func _part(part_name: String, mesh: Mesh, mat: Material) -> MeshInstance3D:
var mi := MeshInstance3D.new()
mi.name = part_name
mi.mesh = mesh
mi.material_override = mat
mi.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
mi.top_level = true
mi.physics_interpolation_mode = Node.PHYSICS_INTERPOLATION_MODE_OFF
add_child(mi)
return mi
## A cylinder 1 m long (along Y) and 1 m across: _lay stretches it.
static func _cylinder() -> CylinderMesh:
var c := CylinderMesh.new()
c.top_radius = 0.5
c.bottom_radius = 0.5
c.height = 1.0
c.radial_segments = 10
c.rings = 1
c.cap_top = false
c.cap_bottom = false
return c
## Stretches a unit cylinder from `from` along dir (unit, level) for span m, thick m across.
static func _lay(mi: MeshInstance3D, from: Vector3, dir: Vector3, span: float, thick: float) -> void:
var side := dir.cross(Vector3.UP)
mi.global_transform = Transform3D(Basis(side * thick, dir * span, Vector3.UP * thick), from + dir * span * 0.5)
static func _material(color: Color, blend: bool) -> StandardMaterial3D:
var mat := StandardMaterial3D.new()
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
mat.albedo_color = color
mat.emission_enabled = true
mat.emission = Color(color.r, color.g, color.b)
mat.disable_fog = true
mat.cull_mode = BaseMaterial3D.CULL_DISABLED
if blend:
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
mat.render_priority = 1
return mat

View file

@ -0,0 +1 @@
uid://db40w7us6cn6d

View file

@ -570,6 +570,46 @@ func sweep_hit(x0: float, z0: float, x1: float, z1: float, use_motion: bool) ->
return best
## Every living enemy along a path at combat height (a polyline: the Alien Ray's beam, #18, from
## the scarecrow through the muzzle to where it ends), flyers included like sweep_hit (their hit
## proxy stays at combat height): those whose hit proxy (hit_radius) comes within half_width of
## the path, ordered by how far along it they are (dense slots, at most max_hits; 0: all). Unlike
## sweep_hit (the nearest only, for shots that stop) it's for a beam that pierces. The ends are
## flat: nothing behind the path's start or past its end (a wall that cut it short) is hit, even
## if its proxy reaches across. Current positions (no motion test), every slot checked rather than
## the grid, which misses enemies spawned since the last step.
func path_hits(path: PackedVector2Array, half_width: float, max_hits: int = 0) -> PackedInt32Array:
var out := PackedInt32Array()
var last := path.size() - 2
if last < 0:
return out
var head := path[1] - path[0]
var tail := path[last + 1] - path[last]
var found: Array = [] # [distance along the path, slot]
for i in active_count:
if alive[i] == 0:
continue
var e := Vector2(pos_x[i], pos_z[i])
if (e - path[0]).dot(head) < 0.0 or (e - path[last + 1]).dot(tail) > 0.0:
continue # behind its start, or past its end
var reach := half_width + t_hit_radius[type[i]]
var along := 0.0
for k in last + 1:
var a := path[k]
var ab := path[k + 1] - a
var seg := ab.length()
if seg > 1e-6:
var u := clampf((e - a).dot(ab) / (seg * seg), 0.0, 1.0)
if e.distance_squared_to(a + ab * u) <= reach * reach:
found.append([along + u * seg, i])
break
along += seg
found.sort_custom(func(x: Array, y: Array) -> bool: return x[0] < y[0])
for k in (found.size() if max_hits <= 0 else mini(found.size(), max_hits)):
out.append(found[k][1])
return out
## Releases this tick's removals: emits enemy_removed (handle still valid), then swaps the last
## active enemy into each freed slot and updates every mapping.
func commit_removals() -> void:

View file

@ -4,8 +4,8 @@ extends Node3D
## stingers and outcomes; SFX: everything else; Ambience: the day and night loops). FarmSim
## creates it and setup() connects it to the farm's systems:
## * scarecrow: footsteps, its weapons (a pitchfork's whoosh and what it strikes, corn shots,
## the propane torch's roar, a pumpkin bomb's toss and burst), hurt, fall, fear and fear
## ready, patching and patched
## the propane torch's roar, the alien ray's hum, a pumpkin bomb's toss and burst), hurt,
## fall, fear and fear ready, patching and patched
## * enemies: crow caws and thieves' / fence breakers' / UFOs' arrivals (from where they come
## in), hits and deaths by type
## * theft: grabbed, dropped, recovered, carried off (with an alarm tone), animals following
@ -44,6 +44,8 @@ const CUES := {
"stab": {"files": ["synth/pitchfork_whoosh.wav"], "db": -6.0, "pitch": 0.12, "max": 3},
# The Propane Torch: one roar per tick, each longer than a tick, so a held torch roars on.
"burn": {"files": ["synth/torch_roar.wav"], "db": -7.0, "pitch": 0.08, "gap": 0.1, "max": 3},
# The Alien Ray: one hum per tick, likewise longer than a tick, so a held ray hums on.
"zap": {"files": ["synth/alien_beam.wav"], "db": -10.0, "pitch": 0.04, "gap": 0.07, "max": 3},
"throw": {"files": ["kenney/rpg/cloth*.ogg"], "db": -4.0, "pitch": 0.1},
"boom": {"files": ["synth/pumpkin_boom.wav"], "db": 0.0, "pitch": 0.08, "gap": 0.05, "max": 4},
"hurt": {"files": ["kenney/impact/impactSoft_heavy_00*.ogg"], "db": -1.0, "pitch": 0.1, "gap": 0.1},
@ -303,6 +305,7 @@ func _wire_weapons(combat: ScarecrowCombat, at: Callable) -> void:
combat.fired.connect(func() -> void: play("shot", where.call()))
combat.stabbed.connect(func(_n: int) -> void: play("stab", where.call()))
combat.burned.connect(func(_n: int) -> void: play("burn", where.call()))
combat.zapped.connect(func(_n: int) -> void: play("zap", where.call()))
combat.struck.connect(func(p: Vector3, type: int) -> void: play("hit_crow" if type == EnemySystem.TYPE_CROW else "hit", p))
combat.threw.connect(func(_to: Vector3) -> void: play("throw", where.call()))

View file

@ -155,7 +155,7 @@ extends Resource
"potato_cannon": {"name": "Potato cannon", "text": "A slow heavy potato shot that hits hard from afar", "track": "Weapon", "shop": "shed"},
"shurikens": {"name": "Shurikens", "text": "Fast, cheap throws for a quick hit", "track": "Weapon", "shop": "shed"},
"propane_torch": {"name": "Propane torch", "text": "A jet of flame that burns everything in a band ahead of you while held", "track": "Weapon", "shop": "shed"},
"alien_ray": {"name": "Alien ray", "text": "A salvaged alien weapon: a fast, powerful beam", "track": "Weapon", "shop": "shed", "hidden": true},
"alien_ray": {"name": "Alien ray", "text": "A salvaged alien weapon: a long beam that pierces everything in its line while held", "track": "Weapon", "shop": "shed", "hidden": true},
"radar": {"name": "Radar", "text": "A minimap showing nearby enemy positions", "track": "Item", "shop": "shed", "hidden": true},
"wide_fear": {"name": "Wide fear", "text": "Fear reaches 30% farther", "track": "Fear", "stat": "fear_radius", "mult": 1.3},
"quick_fear": {"name": "Quick fear", "text": "Fear recharges 20% faster", "track": "Fear", "stat": "fear_cooldown", "mult": 0.8},
@ -298,13 +298,18 @@ extends Resource
@export_range(1, 20) var torch_damage: int = 1
@export_range(1, 20) var torch_targets: int = 5
@export var torch_tick_interval: float = 0.2
## Alien Ray (the Alien ray upgrade, hidden until hidden_reveal_goop Alien Goop is collected): one
## heavy shot every alien_ray_cooldown s, alien_ray_damage each, flying fast (alien_ray_speed m/s)
## through FarmProjectiles.
@export var alien_ray_cooldown: float = 0.9
@export_range(1, 80) var alien_ray_damage: int = 9
@export var alien_ray_speed: float = 50.0
@export var alien_ray_lifetime: float = 2.0
## Alien Ray (the Alien ray upgrade, hidden until hidden_reveal_goop Alien Goop is collected): a
## beam while held (#18), a tick every alien_ray_tick_interval s, alien_ray_damage each to every
## enemy within alien_ray_width / 2 (plus its hit radius) of the beam, flyers too (the nearest
## alien_ray_pierce), from the scarecrow through the muzzle and on alien_ray_range m past it, cut
## short at the first wall (ScarecrowCombat.beam_path, EnemySystem.path_hits). It hits at once
## (no projectile). 1 every 0.15 s is about 6.7 damage a second to each enemy on the beam: the
## shed's guns do 4 to 6 to one, the torch 5 to each in its short band.
@export var alien_ray_range: float = 20.0
@export var alien_ray_width: float = 0.5
@export var alien_ray_tick_interval: float = 0.15
@export_range(1, 80) var alien_ray_damage: int = 1
@export_range(1, 20) var alien_ray_pierce: int = 4
@export_group("Radar")
## Radar (the Radar item, bought at the supply shed, hidden until hidden_reveal_goop Alien Goop is

View file

@ -40,13 +40,17 @@ extends Node3D
## gun's line, from the scarecrow out to torch_range past the muzzle (the
## nearest torch_targets), with a clear line (_band_hit), and its flame
## (TorchFlame) lit while fire is held
## alien ray one fast, powerful alien_ray_damage shot every alien_ray_cooldown, through
## FarmProjectiles at alien_ray_speed
## alien ray a beam while held (#18): an alien_ray_damage tick every
## alien_ray_tick_interval to every enemy along it (the nearest
## alien_ray_pierce), alien_ray_width wide, from the scarecrow through the
## muzzle and on alien_ray_range past it, cut short at the first wall
## (beam_path, EnemySystem.path_hits); no projectile, so it hits at once, and
## its beam (AlienBeam) shows while fire is held
## * Every weapon's model on the scarecrow (WeaponModels), an aim marker, and while a pumpkin
## bomb is ready a ring on the ground where one would land, as wide as its blast. A held
## weapon (the torch) lights its effect on each attack instead of replaying a motion; the
## effect stays lit for HOLD_TICKS of its ticks after the last one (WeaponModels.add_held_effect)
## and goes out at once when fire is let go.
## weapon (the torch, the alien ray) lights its effect on each attack instead of replaying a
## motion; the effect stays lit for HOLD_TICKS of its ticks after the last one
## (WeaponModels.add_held_effect) and goes out at once when fire is let go.
## While attacking, the model faces the aim.
## Co-op: the partner's weapons on the host read its RemoteControls (aim, fire and offhand, and
## its pick of main weapon come from the partner's game); on the partner's machine its own only
@ -61,10 +65,11 @@ enum Weapon { PITCHFORK, CORN_SHOOTER, PUMPKIN_BOMB, POTATO_CANNON, SHURIKENS, P
## A corn shot left the gun (for its sound).
signal fired
## A pitchfork stab (how many it hit), a Propane Torch tick (how many it burned), and each enemy
## either struck (for the sounds).
## A pitchfork stab (how many it hit), a Propane Torch tick (how many it burned), an Alien Ray
## tick (how many it zapped), and each enemy any of them struck (for the sounds).
signal stabbed(hits: int)
signal burned(hits: int)
signal zapped(hits: int)
signal struck(at: Vector3, enemy_type: int)
## A pumpkin bomb thrown (where it will land).
signal threw(at: Vector3)
@ -89,7 +94,7 @@ const OFFHAND_WEAPONS: Array[int] = [Weapon.PUMPKIN_BOMB]
const SWITCH_ACTIONS: Array[StringName] = [&"weapon_next", &"weapon_1", &"weapon_2"]
## Main weapons that fire from the muzzle (SIDE_OFFSET/muzzle_distance), so aiming at a target
## needs the same muzzle correction as the corn shooter's (attack_toward, the mouse in _update_aim).
## The Propane Torch's band runs along the gun's line too (#17).
## The Propane Torch's band runs along the gun's line too (#17), and the Alien Ray's beam (#18).
const MUZZLE_WEAPONS: Array[int] = [Weapon.CORN_SHOOTER, Weapon.POTATO_CANNON, Weapon.SHURIKENS, Weapon.PROPANE_TORCH,
Weapon.ALIEN_RAY]
## A held weapon's effect stays lit this many of its tick intervals after its last tick, so it
@ -116,8 +121,10 @@ var ground_point := Vector3.ZERO
var shots_fired: int = 0
var stabs: int = 0
var bombs_thrown: int = 0
## Propane Torch ticks applied (its own count, like stabs/shots_fired/bombs_thrown).
## Propane Torch ticks applied (its own count, like stabs/shots_fired/bombs_thrown), and Alien Ray
## ticks (#18: a beam, not shots).
var torch_ticks: int = 0
var beam_ticks: int = 0
## Seconds until the next pumpkin bomb is in hand (0 = ready).
var bomb_left: float = 0.0
var remote: RemoteControls
@ -161,6 +168,8 @@ func setup(cfg: GameConfig, player: PlayerCharacter, camera: Camera3D, shots: Fa
models.setup(player.model, Vector3(SIDE_OFFSET, cfg.combat_height, -cfg.muzzle_distance))
models.add_held_effect(Weapon.PROPANE_TORCH, TorchFlame.new(cfg.torch_range, cfg.torch_width),
cfg.torch_tick_interval * HOLD_TICKS, TorchFlame.LIFETIME)
models.add_held_effect(Weapon.ALIEN_RAY, AlienBeam.new(cfg.alien_ray_range, cfg.alien_ray_width),
cfg.alien_ray_tick_interval * HOLD_TICKS)
_build_marker()
@ -287,7 +296,7 @@ func step(_dt: float) -> void:
_offhand_needs_release = true # couldn't attack last tick (a menu, the partner's build mode)
_stepped = _ticks
if not held:
models.douse() # the torch's flame goes out as soon as fire is let go
models.douse() # the torch's flame and the ray's beam go out as soon as fire is let go
if replica:
if held:
_player.face_aim(aim, 0.35)
@ -331,7 +340,7 @@ func offhand_toward(target: Vector2) -> bool:
## Attacks so far, with any weapon.
func attacks() -> int:
return stabs + shots_fired + bombs_thrown + torch_ticks
return stabs + shots_fired + bombs_thrown + torch_ticks + beam_ticks
## Ticks between shots, and a shot's damage, with upgrades.
@ -350,7 +359,7 @@ func stab_ticks() -> int:
## Ticks between Potato Cannon shots, Shurikens throws, Propane Torch DoT ticks, and Alien Ray
## shots (each its own cooldown, GameConfig-tunable, no ammo).
## beam ticks (each its own cooldown, GameConfig-tunable, no ammo).
func potato_ticks() -> int:
return maxi(1, roundi(_cfg.potato_cannon_cooldown * Engine.physics_ticks_per_second))
@ -364,7 +373,7 @@ func torch_interval_ticks() -> int:
func alien_ray_ticks() -> int:
return maxi(1, roundi(_cfg.alien_ray_cooldown * Engine.physics_ticks_per_second))
return maxi(1, roundi(_cfg.alien_ray_tick_interval * Engine.physics_ticks_per_second))
## Where a bomb thrown now lands: the ground point aimed at (GAMEPAD_THROW ahead with the stick),
@ -402,7 +411,7 @@ func _use(w: int) -> bool:
_torch_tick()
Weapon.ALIEN_RAY:
_cooldown[w] = alien_ray_ticks()
_shoot_alien_ray()
_beam_tick()
_:
_cooldown[w] = stab_ticks()
_stab()
@ -460,17 +469,39 @@ func _shoot_potato() -> void:
fired.emit()
## The Alien Ray: a fast, powerful shot through FarmProjectiles (hidden until enough Alien Goop is
## collected, Upgrades.revealed).
func _shoot_alien_ray() -> void:
## The Alien Ray's beam now (#18), world space at combat height: from the scarecrow's center
## through the muzzle, then on along the aim for alien_ray_range m, cut short at the first wall
## (AlienBeam.trace, which its beam drawn shares): [center, muzzle, end], or [center, the wall]
## when the barrel pokes through one.
func beam_path() -> PackedVector3Array:
var origin := Vector3(_player.global_position.x, _cfg.combat_height, _player.global_position.z)
var dir := Vector3(aim.x, 0.0, aim.y)
var right := Vector3(-aim.y, 0.0, aim.x)
var muzzle := origin + dir * _cfg.muzzle_distance + right * SIDE_OFFSET
shots_fired += 1
_shots.fire(origin, muzzle, dir, _cfg.alien_ray_damage, _cfg.alien_ray_speed, _cfg.alien_ray_lifetime)
var space := get_world_3d().direct_space_state if is_inside_tree() else null
return AlienBeam.trace(space, _ray, origin, muzzle, dir, _cfg.alien_ray_range)
## The Alien Ray (hidden until enough Alien Goop is collected, Upgrades.revealed): a beam, applied
## every alien_ray_tick_interval s while held (it stops the moment fire is released). Each tick
## hits every enemy along beam_path within alien_ray_width / 2 (plus its hit radius), flyers too,
## the nearest alien_ray_pierce of them, for alien_ray_damage; nothing past the wall that ends it.
## Its beam is lit (WeaponModels' held effect). Inside step(), so FarmSim's enemies.attacker
## credits the kills to this scarecrow.
func _beam_tick() -> int:
beam_ticks += 1
models.attack(Weapon.ALIEN_RAY)
fired.emit()
var hits := 0
if enemies != null:
var path := PackedVector2Array()
for p in beam_path():
path.append(Vector2(p.x, p.z))
var found: Array = [] # [order along the beam, slot]
for d in enemies.path_hits(path, _cfg.alien_ray_width * 0.5, _cfg.alien_ray_pierce):
found.append([found.size(), d])
hits = _hit_nearest(found, _cfg.alien_ray_pierce, _cfg.alien_ray_damage)
zapped.emit(hits)
return hits
## Shurikens: shuriken_count fast, cheap projectiles through FarmProjectiles, on a short cooldown.
@ -546,8 +577,8 @@ func _band_hit(length: float, width: float, max_targets: int, damage: int) -> in
return _hit_nearest(found, max_targets, damage)
## Damages the first max_targets of found ([distance, slot] pairs), nearest first. Returns how many
## it hit.
## Damages the first max_targets of found ([distance, slot] pairs), nearest first (the pitchfork,
## the torch, and the ray's beam). Returns how many it hit.
func _hit_nearest(found: Array, max_targets: int, damage: int) -> int:
var hits := 0
var es := enemies

View file

@ -15,11 +15,12 @@ extends Node3D
## yet (visuals stay out of scope): each is a placeholder pivot (_add_placeholder) at the corn
## shooter's gun spot, the corn shooter's mesh tinted a different color so they're still tellable
## apart in play; it kicks back like a gun on each attack, unless it's a held weapon.
## Held weapons (add_held_effect; the Propane Torch's TorchFlame, #17) attack every short tick
## while fire is held, so each attack lights their effect instead of replaying a motion. The
## effect sits at the muzzle facing the model's way and stays lit for its hold s after each
## attack: lit while fire is held, out hold s after the last attack (or at once with douse(),
## when fire is let go). Then it fades for fade s (shown, no longer lit) before it's hidden. The
## Held weapons (add_held_effect; the Propane Torch's TorchFlame, #17, and the Alien Ray's
## AlienBeam, #18) attack every short tick while fire is held, so each attack lights their effect
## instead of replaying a motion. The effect sits at the muzzle facing the model's way and stays
## lit for its hold s after each attack: lit while fire is held, out hold s after the last attack
## (or at once with douse(), when fire is let go). Then it fades for fade s (shown, no longer lit;
## the torch's fire in the air dying away, none for the beam) before it's hidden. The
## timers run on the simulation's clock, advance() from ScarecrowCombat.tick() (hand-stepped tests
## drive it too), or on the physics frames when nothing advances them: in co-op, the other
## scarecrow on the partner's farm is lit by its attack events and stepped by nothing there (and

View file

@ -10,8 +10,8 @@ extends RefCounted
## weapon in hand, both at once, held, not with the right click that leaves build mode); a bomb's
## throw (at the aim, its range clamped), flight, and burst (everything in its radius, crows too,
## nothing beyond, not the scarecrow), its recharge and the morning refill; the models on the
## scarecrow; the HUD's weapon panel; the shed's other weapons; and the Propane Torch's band of
## fire and its flame (#17).
## scarecrow; the HUD's weapon panel; the shed's other weapons; the Propane Torch's band of
## fire and its flame (#17); and the Alien Ray's beam (#18).
const DT := 1.0 / 60.0
const AT := Vector2(0.0, 6.0) # open ground south-west of the pen
@ -41,6 +41,7 @@ func run(r: GameTestRunner) -> void:
_hud(r, farm, sim)
_shed_weapons(r, farm, sim)
await _torch(r, farm, sim)
await _alien_ray(r, farm, sim)
sim.enemies.behavior = keep
farm.queue_free()
await r.process_frame
@ -334,7 +335,8 @@ func _hud(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
## Task #7's four shed weapons (Potato Cannon, Shurikens, Propane Torch, Alien Ray): each
## purchasable at the supply shed, equippable, and deals damage. The Alien Ray stays hidden until
## enough Alien Goop is collected (Upgrades.revealed), then buys and works like the others.
## enough Alien Goop is collected (Upgrades.revealed), then buys like the others (_alien_ray: its
## beam, #18; _torch: the torch's band, #17).
func _shed_weapons(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
var c := sim.combat
var cfg := sim.config
@ -355,7 +357,6 @@ func _shed_weapons(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
r.check(Upgrades.revealed(s, cfg, "alien_ray"), "revealed once hidden_reveal_goop is collected")
_buy_equip_hit(r, farm, sim, "potato_cannon", W.POTATO_CANNON, cfg.potato_cannon_speed)
_buy_equip_hit(r, farm, sim, "shurikens", W.SHURIKENS, cfg.shuriken_speed)
_buy_equip_hit(r, farm, sim, "alien_ray", W.ALIEN_RAY, cfg.alien_ray_speed)
c.equip(W.PITCHFORK)
@ -486,6 +487,203 @@ func _torch(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
_clear(sim)
## The Alien Ray (#18), revealed in _shed_weapons: bought at the supply shed, a beam from the
## scarecrow through the muzzle and on alien_ray_range past it. A tick hits at once, however far
## along the beam, every enemy on it (crows too, the nearest alien_ray_pierce); nothing beside,
## behind, or beyond it; nothing past a wall, which cuts it short. Held, it ticks every
## alien_ray_tick_interval and stops on release. Its beam shows only while fire is held, follows
## the model's yaw, and ends where the damage does: its own wall test, as on the partner's
## machine, where attack events light it and it goes out by itself.
func _alien_ray(r: GameTestRunner, farm: Node3D, sim: FarmSim) -> void:
var c := sim.combat
var cfg := sim.config
var s := sim.campaign.state
var es := sim.enemies
var panel := farm.get_node("Hud/ShedPanel") as UpgradePanel
var model := sim.player.model
var at := Vector2(sim.player.global_position.x, sim.player.global_position.z) # (AT, give or take; east is open)
s.resources.shed = {"wood": 999, "scrap": 999, "straw": 999, "alien_goop": 999}
r.check(Upgrades.revealed(s, cfg, "alien_ray") and not c.owns(W.ALIEN_RAY), "the alien ray (revealed) isn't owned yet")
panel._buy("alien_ray")
r.check(Upgrades.owned(s, "alien_ray") and c.owns(W.ALIEN_RAY), "it's purchasable at the supply shed")
r.check(c.equip(W.ALIEN_RAY) and c.weapon == W.ALIEN_RAY, "and equippable")
var beam := c.models.held_effect(W.ALIEN_RAY) as AlienBeam
r.check(beam != null and not beam.visible and not c.models.lit(W.ALIEN_RAY), "its beam is off until it fires")
r.check(is_equal_approx(beam.length, cfg.alien_ray_range) and is_equal_approx(beam.width, cfg.alien_ray_width),
"the beam is sized to the ray (%.0f m long, %.1f m wide)" % [beam.length, beam.width])
var full := es.t_hp[THIEF]
var reach := cfg.muzzle_distance + cfg.alien_ray_range # from the scarecrow's center
var east := at + Vector2(16.0, 0.0)
# One tick aimed east, spawned and zapped on the same step: no shot to wait for. The gun's line
# runs SIDE_OFFSET south of the scarecrow's, bent onto the aim point.
var far := es.spawn(THIEF, at.x + reach - 1.0, at.y, Vector2.LEFT)
var beside := es.spawn(THIEF, at.x + 7.0, at.y + 1.4, Vector2.LEFT)
var beside2 := es.spawn(THIEF, at.x + 11.0, at.y - 1.3, Vector2.LEFT)
var behind := es.spawn(THIEF, at.x - 1.5, at.y, Vector2.RIGHT)
var beyond := es.spawn(THIEF, at.x + reach + 1.5, at.y, Vector2.LEFT)
c.reset()
var ticks := c.beam_ticks
var shots := c.shots_fired
var attacks := c.attacks()
var played := sim.audio.played if sim.audio != null else {}
var zaps := int(played.get("zap", 0))
var pops := int(played.get("shot", 0))
r.check(c.attack_toward(east) and c.beam_ticks == ticks + 1 and c.shots_fired == shots and c.attacks() == attacks + 1,
"it fires a beam tick (counted as one, not as a shot)")
r.check(sim.audio == null or (int(played.get("zap", 0)) == zaps + 1 and int(played.get("shot", 0)) == pops),
"with a hum (its own sound, not the gun's pop)")
r.check(_hp(es, far) == full - cfg.alien_ray_damage,
"a thief %.0f m off, near the beam's end, is hit for %d on the same step" % [reach - 1.0, cfg.alien_ray_damage])
r.check(_hp(es, beside) == full and _hp(es, beside2) == full, "one beside the beam, either side, isn't")
r.check(_hp(es, behind) == full and _hp(es, beyond) == full, "nor one behind the scarecrow, nor one past the beam's end")
r.check(c.models._attack_t < 0.0 and c.models.lit(W.ALIEN_RAY) and beam.visible,
"a tick lights the beam instead of replaying the gun's kick")
# The beam drawn, on the model turned to the aim (all the partner's machine knows of it), runs
# from the muzzle to the end of the damage's path.
var yaw := model.rotation.y
model.rotation.y = atan2(-c.aim.x, -c.aim.y)
var path := c.beam_path()
var drawn := beam.rebuild(beam.global_transform)
r.check(path.size() == 3 and _flat(beam.start).distance_to(_flat(path[1])) < 0.02 and _flat(beam.end).distance_to(_flat(path[2])) < 0.02
and absf(drawn - cfg.alien_ray_range) < 0.02 and not beam.blocked and beam._core.visible,
"the beam runs from the muzzle the full %.0f m, where the damage does (drawn %.2f m)" % [cfg.alien_ray_range, drawn])
_clear(sim)
# Two in line (and a crow over the same line) are all hit: it pierces.
var first := es.spawn(THIEF, at.x + 4.0, at.y, Vector2.LEFT)
var second := es.spawn(THIEF, at.x + 8.0, at.y, Vector2.LEFT)
var crow := es.spawn(EnemySystem.TYPE_CROW, at.x + 12.0, at.y, Vector2.LEFT)
c.reset()
c.attack_toward(east)
r.check(_hp(es, first) == full - cfg.alien_ray_damage and _hp(es, second) == full - cfg.alien_ray_damage,
"two thieves in line are both hit (the beam pierces)")
r.check(_hp(es, crow) < es.t_hp[EnemySystem.TYPE_CROW], "a crow over the beam is hit too")
_clear(sim)
# A whole line: the nearest alien_ray_pierce only.
var line: Array[int] = []
for k in cfg.alien_ray_pierce + 2:
line.append(es.spawn(THIEF, at.x + 3.0 + k * 1.5, at.y, Vector2.LEFT))
c.reset()
c.attack_toward(east)
var hit := line.map(func(h: int) -> bool: return _hp(es, h) < full)
var nearest := true
for k in line.size():
nearest = nearest and hit[k] == (k < cfg.alien_ray_pierce)
r.check(nearest, "a line of %d: the nearest %d are hit (%s)" % [line.size(), cfg.alien_ray_pierce, hit])
_clear(sim)
# A wall cuts it short: what's in front is hit, what's behind isn't, and the beam drawn ends there.
var wall := StaticBody3D.new()
var shape := CollisionShape3D.new()
var box := BoxShape3D.new()
box.size = Vector3(0.2, 3.0, 4.0)
shape.shape = box
wall.add_child(shape)
farm.add_child(wall)
wall.global_position = Vector3(at.x + 6.0, 1.5, at.y)
await r.physics_frame # it joins the physics space on the next physics frame
var front := es.spawn(THIEF, at.x + 4.0, at.y, Vector2.LEFT)
var walled := es.spawn(THIEF, at.x + 8.0, at.y, Vector2.LEFT)
var walled_far := es.spawn(THIEF, at.x + 15.0, at.y, Vector2.LEFT)
c.reset()
c.attack_toward(east)
r.check(_hp(es, front) == full - cfg.alien_ray_damage and _hp(es, walled) == full and _hp(es, walled_far) == full,
"a wall stops it: the thief in front is hit, the ones behind the wall aren't")
path = c.beam_path()
model.rotation.y = atan2(-c.aim.x, -c.aim.y)
drawn = beam.rebuild(beam.global_transform)
var face := at.x + 6.0 - 0.1
r.check(path.size() == 3 and absf(path[2].x - face) < 0.05, "the beam's path ends at the wall's face (x %.2f, wall at %.2f)" % [path[2].x, face])
r.check(beam.blocked and _flat(beam.end).distance_to(_flat(path[2])) < 0.05 and absf(drawn - _flat(path[1]).distance_to(_flat(path[2]))) < 0.05
and beam._flare.visible, "the beam drawn ends there too (%.2f m from the muzzle), with a flare" % drawn)
_clear(sim)
# A barrel poking through a wall (the scarecrow pressed against it) fires nothing past it.
wall.global_position = Vector3(at.x + 0.75, 1.5, at.y)
await r.physics_frame
var past := es.spawn(THIEF, at.x + 3.0, at.y, Vector2.LEFT)
c.reset()
c.attack_toward(east)
path = c.beam_path()
drawn = beam.rebuild(beam.global_transform)
r.check(_hp(es, past) == full and path.size() == 2 and drawn == 0.0 and not beam._core.visible,
"a barrel poking through a wall hits nothing past it (and no beam shows beyond)")
wall.queue_free()
await r.physics_frame
_clear(sim)
model.rotation.y = yaw
# Held: a tick every alien_ray_tick_interval, the beam lit throughout; let go, both stop.
var tough := es.spawn(THIEF, at.x + 10.0, at.y, Vector2.LEFT)
es.health[es.resolve_handle(tough)] = 99
c.device = ScarecrowCombat.Device.GAMEPAD # keeps the aim it's given
c.aim = Vector2(1.0, 0.0)
c.reset()
_step(sim, 1) # fire not held: the reset's release is seen
r.check(not c.models.lit(W.ALIEN_RAY) and not beam.visible, "(the beam went out: fire isn't held)")
ticks = c.beam_ticks
shots = c.shots_fired
var zapped: Array[int] = []
var on_zap := func(n: int) -> void: zapped.append(n)
c.zapped.connect(on_zap)
var intervals := 5
var lit_throughout := true
Input.action_press("fire")
for i in c.alien_ray_ticks() * intervals:
_step(sim, 1)
lit_throughout = lit_throughout and c.models.lit(W.ALIEN_RAY) and beam.lit and beam.visible
var held_ticks := c.beam_ticks - ticks
var damage := 99 - _hp(es, tough)
Input.action_release("fire")
_step(sim, 1)
var out_at_once := not c.models.lit(W.ALIEN_RAY) and not beam.lit and not beam.visible
var after := c.beam_ticks
_step(sim, c.alien_ray_ticks() * 3)
r.check(held_ticks == intervals and damage == intervals * cfg.alien_ray_damage and zapped.size() == intervals and c.shots_fired == shots,
"holding fire zaps every %.2f s: %d ticks in %.2f s, %d damage" % [cfg.alien_ray_tick_interval, held_ticks, intervals * cfg.alien_ray_tick_interval, damage])
r.check(c.beam_ticks == after and 99 - _hp(es, tough) == damage, "letting go stops it")
r.check(lit_throughout, "the beam stays lit the whole time fire is held, between ticks too")
r.check(out_at_once, "and goes out the moment fire is let go")
c.zapped.disconnect(on_zap)
# The beam follows the model's yaw.
model.rotation.y = 1.0
c.models.attack(W.ALIEN_RAY)
beam.rebuild(beam.global_transform)
var dir := _flat(beam.end - beam.start).normalized()
r.check(dir.dot(Vector2(-sin(1.0), -cos(1.0))) > 0.999, "the beam points the way the model faces")
model.rotation.y = yaw
# The partner's own scarecrow on its machine (a replica: the host zaps for it) shows the beam
# while fire is held there.
c.replica = true
Input.action_press("fire")
_step(sim, c.alien_ray_ticks() * 2)
var replica_lit := c.models.lit(W.ALIEN_RAY) and beam.visible and c.beam_ticks == after
Input.action_release("fire")
_step(sim, 1)
c.replica = false
r.check(replica_lit and not c.models.lit(W.ALIEN_RAY), "a replica's beam is lit while fire is held there, and zaps nothing")
# The other scarecrow on the partner's machine: lit by its attack events (one per tick) and
# stepped by nothing there, so its beam times out on the physics frames (and lays itself out
# every frame meanwhile).
var events_lit := true
for k in 3:
c.show_weapon(W.ALIEN_RAY)
c.models.attack(W.ALIEN_RAY)
for i in c.alien_ray_ticks():
await r.physics_frame
events_lit = events_lit and c.models.lit(W.ALIEN_RAY) and beam.visible
var hold := cfg.alien_ray_tick_interval * ScarecrowCombat.HOLD_TICKS
for i in ceili(hold * Engine.physics_ticks_per_second) + 6:
await r.physics_frame
r.check(events_lit and not c.models.lit(W.ALIEN_RAY) and not beam.visible,
"on the partner's machine, attack events keep the beam lit, and it goes out by itself once they stop")
c.models.attack(W.ALIEN_RAY)
c.equip(W.PITCHFORK)
r.check(not beam.visible and not c.models.lit(W.ALIEN_RAY), "switching weapons puts it out at once")
c.device = ScarecrowCombat.Device.MOUSE
_clear(sim)
func _flat(v: Vector3) -> Vector2:
return Vector2(v.x, v.z)
## Buys id at the supply shed, equips w, and checks that a shot fired at a thief some meters off
## damages it once it arrives (speed m/s: how long to wait).
func _buy_equip_hit(r: GameTestRunner, farm: Node3D, sim: FarmSim, id: String, w: int, speed: float) -> void:

View file

@ -10,6 +10,8 @@ extends SceneTree
## pumpkin_boom.wav a deep thump, a burst of noise, and a wet splat (a pumpkin bomb)
## torch_roar.wav a gas jet's flickering roar and hiss with a few crackles (a propane
## torch tick; back-to-back plays blend into one roar)
## alien_beam.wav a buzzing, warbling ray hum over a high whine and a fizz (an alien ray
## tick; back-to-back plays blend into one hum)
## Loops carry a WAV 'smpl' loop point, so the importer's "Detect From WAV" loops them; every
## periodic part of a loop has a whole number of cycles in it and filtered noise is warmed up
## on the loop's own tail, so the seam is silent. Run with the editor closed, then let the
@ -40,6 +42,8 @@ func _initialize() -> void:
_write("pumpkin_boom.wav", _boom(0.9), false)
_rng.seed = 17 # its own seed, so adding it changed none of the sounds above
_write("torch_roar.wav", _roar(0.42), false)
_rng.seed = 19 # its own seed too
_write("alien_beam.wav", _beam(0.34), false)
quit(0)
@ -274,6 +278,30 @@ func _roar(length: float) -> PackedFloat32Array:
return _normalize(buf, 0.7)
## An alien ray: a buzzy low tone (odd harmonics) warbling fast, a high whine sliding down, and a
## fizz of bright noise. It swells in fast and fades slowly, so plays one ray tick apart (shorter
## than it) overlap into one steady hum while the ray is held.
func _beam(length: float) -> PackedFloat32Array:
var n := int(length * RATE)
var fizz := _noise_lowpass(n, 7000.0)
var fizz_low := _noise_lowpass(n, 2500.0)
var buf := PackedFloat32Array()
buf.resize(n)
var phase := 0.0
var whine := 0.0
for i in n:
var t := float(i) / RATE
var u := float(i) / n
var env := minf(u / 0.08, 1.0) * minf((1.0 - u) / 0.5, 1.0)
phase += 196.0 * (1.0 + 0.06 * sin(TAU * 31.0 * t)) / RATE
whine += lerpf(1900.0, 1500.0, u) * (1.0 + 0.01 * sin(TAU * 13.0 * t)) / RATE
var buzz := 0.0
for h in [1, 3, 5, 7, 9]:
buzz += sin(TAU * phase * h) / h
buf[i] = env * (0.8 * buzz + 0.18 * sin(TAU * whine) + 0.3 * (fizz[i] - fizz_low[i]))
return _normalize(buf, 0.7)
func _horn() -> PackedFloat32Array:
var n := int(0.9 * RATE)
var buf := PackedFloat32Array()