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:
parent
287b6ac6cc
commit
a0aee34e3c
13 changed files with 554 additions and 44 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue