Task #18: Alien Ray fires a beam

The Alien Ray is now a held beam instead of a copy of the potato shot.
While fire is held it ticks every alien_ray_tick_interval (0.15 s). Each
tick traces a path from the scarecrow's center through the muzzle and on
alien_ray_range (20 m) past it, cut short at the first wall
(AlienBeam.trace on the world layer). It damages every enemy within
alien_ray_width / 2 (0.25 m) plus its hit radius of that path, flyers
included as with shots, nearest first, up to alien_ray_pierce (4), for
alien_ray_damage (1). That is about 6.7 damage a second per enemy on the
beam. Hits stay inside combat.step, so enemies.attacker credits kills.

- EnemySystem.path_hits: every enemy along a polyline, ordered along it,
  with flat ends (nothing behind the scarecrow or past the wall).
  sweep_hit is unchanged.
- AlienBeam: a WeaponModels held effect (hold 1.5 ticks, no fade). It is
  an unshaded HDR green core and glow, a muzzle light, and a flare where a
  wall stops it. Each frame it lays itself out from the muzzle along the
  model's -Z, with the same trace, so the partner's machine recomputes the
  wall clip locally. No protocol change.
- Counters: a beam_ticks counter joins attacks(), and ray ticks no
  longer count as shots_fired.
- Config: alien_ray_speed, alien_ray_lifetime and alien_ray_cooldown are
  removed. alien_ray_range, _width, _tick_interval and _pierce are added.
  The shop text says what it does now. Cost and hidden/reveal are
  unchanged.
- Sound: a zapped signal and a "zap" cue (synth alien_beam.wav, its own
  seed). The other synth files regenerate byte-identical.

Tests (test_weapons) replace the projectile-travel ray check and keep
buy/equip:
- a far target is hit on the same step;
- nothing beside, behind or past the end is hit;
- two in line and a crow are all hit;
- a line is capped at pierce;
- a wall stops it, including a barrel poking through one;
- held ticks repeat and stop on release;
- the beam is lit only while held, ends at the wall clip, follows the
  model's yaw, and the replica and attack-event paths work.

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

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