Task #17: Propane Torch sprays a band of fire
Hit test: _band_hit replaces the torch's cone. It hits the enemies in a torch_width (1.6 m) wide band along the gun's line, from the scarecrow's center out to torch_range (4.5 m) past the muzzle, each enemy's hit radius added. The nearest torch_targets with a clear line are hit; _cone_hit and _band_hit share _hit_nearest. torch_arc is gone, and the torch joins MUZZLE_WEAPONS so scripted aim matches the mouse. Flame: TorchFlame (CPUParticles3D jet plus a flickering light) is sized to the band. WeaponModels gains a reusable held-effect pattern for #18: - add_held_effect / lit / douse / advance. - attack() lights the effect for HOLD_TICKS (1.5) tick intervals instead of replaying the kick. - douse() puts it out the moment fire is let go; it then fades for the particle lifetime. - Timers run on the sim clock (ScarecrowCombat.tick), or on physics frames when nothing advances them. That covers the other scarecrow on the partner's machine, which the existing "attack" events light, so there is no protocol change. Sound: a new burned signal and a "burn" cue (synth torch_roar.wav, generated by synth_audio.gd with its own seed) replace the pitchfork's stab sound. Tests (test_weapons): band in, beside, behind and beyond; a melee hugger is burned; held fire over 5 intervals ticks 5 times and stops on release; the flame is lit at every step while held and hidden after release; the replica and attack-event paths; the flame follows the model's yaw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
26b735d3e6
commit
ca8601029e
12 changed files with 483 additions and 37 deletions
|
|
@ -35,13 +35,18 @@ extends Node3D
|
|||
## through FarmProjectiles at potato_cannon_speed
|
||||
## shurikens shuriken_count shuriken_damage throws every shuriken_cooldown, fast
|
||||
## (shuriken_speed) and cheap
|
||||
## propane torch a torch_damage tick every torch_tick_interval to every enemy within
|
||||
## torch_range and torch_arc of the aim (up to torch_targets), with a clear
|
||||
## line: a sustained cone while held, like the pitchfork's stab
|
||||
## propane torch a band of fire while held (#17): a torch_damage tick every
|
||||
## torch_tick_interval to the enemies in a torch_width wide band along the
|
||||
## 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
|
||||
## * 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.
|
||||
## 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.
|
||||
## 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
|
||||
|
|
@ -56,8 +61,10 @@ 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), and each enemy it struck (for the sounds).
|
||||
## A pitchfork stab (how many it hit), a Propane Torch tick (how many it burned), and each enemy
|
||||
## either struck (for the sounds).
|
||||
signal stabbed(hits: int)
|
||||
signal burned(hits: int)
|
||||
signal struck(at: Vector3, enemy_type: int)
|
||||
## A pumpkin bomb thrown (where it will land).
|
||||
signal threw(at: Vector3)
|
||||
|
|
@ -82,7 +89,12 @@ 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).
|
||||
const MUZZLE_WEAPONS: Array[int] = [Weapon.CORN_SHOOTER, Weapon.POTATO_CANNON, Weapon.SHURIKENS, Weapon.ALIEN_RAY]
|
||||
## The Propane Torch's band runs along the gun's line too (#17).
|
||||
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
|
||||
## burns steadily while fire is held (on the partner's machine too, lit by the attack events).
|
||||
const HOLD_TICKS := 1.5
|
||||
## How far ahead a bomb lands when aiming with the stick, and how high it leaves the hand.
|
||||
const GAMEPAD_THROW := 7.0
|
||||
const THROW_HEIGHT := 1.6
|
||||
|
|
@ -147,6 +159,8 @@ func setup(cfg: GameConfig, player: PlayerCharacter, camera: Camera3D, shots: Fa
|
|||
_ray.exclude = [player.get_rid()]
|
||||
models = WeaponModels.new()
|
||||
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)
|
||||
_build_marker()
|
||||
|
||||
|
||||
|
|
@ -233,6 +247,7 @@ func _input(event: InputEvent) -> void:
|
|||
## mode, no menu open; the partner's pick comes from its game).
|
||||
func tick(dt: float, can_switch: bool) -> void:
|
||||
_ticks += 1
|
||||
models.advance(dt)
|
||||
bomb_left = maxf(bomb_left - dt, 0.0)
|
||||
models.set_bomb_charge(1.0 - bomb_left / _cfg.bomb_cooldown if _cfg.bomb_cooldown > 0.0 else 1.0)
|
||||
if not owns(weapon):
|
||||
|
|
@ -271,6 +286,8 @@ func step(_dt: float) -> void:
|
|||
if _ticks - _stepped > 1:
|
||||
_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
|
||||
if replica:
|
||||
if held:
|
||||
_player.face_aim(aim, 0.35)
|
||||
|
|
@ -469,22 +486,21 @@ func _throw_shurikens() -> void:
|
|||
threw.emit(muzzle)
|
||||
|
||||
|
||||
## The Propane Torch: a sustained cone, like the pitchfork's but its own reach/arc/targets/damage,
|
||||
## applied every torch_tick_interval s while held (DoT: it stops the moment fire is released).
|
||||
## The Propane Torch: a band of fire (_band_hit), applied every torch_tick_interval s while held
|
||||
## (DoT: it stops the moment fire is released), and its flame lit (WeaponModels' held effect).
|
||||
func _torch_tick() -> int:
|
||||
torch_ticks += 1
|
||||
models.attack(Weapon.PROPANE_TORCH)
|
||||
var hits := _cone_hit(_cfg.torch_range, _cfg.torch_arc, _cfg.torch_targets, _cfg.torch_damage)
|
||||
stabbed.emit(hits)
|
||||
var hits := _band_hit(_cfg.torch_range, _cfg.torch_width, _cfg.torch_targets, _cfg.torch_damage)
|
||||
burned.emit(hits)
|
||||
return hits
|
||||
|
||||
|
||||
## The nearest few enemies within reach of the aim, in arc, and in the clear take damage (the
|
||||
## pitchfork's stab and the Propane Torch's tick share this).
|
||||
## pitchfork's stab).
|
||||
func _cone_hit(reach: float, arc_deg: float, max_targets: int, damage: int) -> int:
|
||||
var hits := 0
|
||||
if enemies == null:
|
||||
return hits
|
||||
return 0
|
||||
var es := enemies
|
||||
var p := Vector2(_player.global_position.x, _player.global_position.z)
|
||||
var cos_half := cos(deg_to_rad(arc_deg) * 0.5)
|
||||
|
|
@ -500,6 +516,41 @@ func _cone_hit(reach: float, arc_deg: float, max_targets: int, damage: int) -> i
|
|||
continue
|
||||
if _clear_line(p, e):
|
||||
found.append([dist, d])
|
||||
return _hit_nearest(found, max_targets, damage)
|
||||
|
||||
|
||||
## The nearest few enemies in a band along the gun's line and in the clear take damage (the
|
||||
## Propane Torch's tick). The band is width m wide, centered on the line from the muzzle along
|
||||
## the aim, and runs from the scarecrow's center out to length m past the muzzle; each enemy's hit
|
||||
## radius widens it and lengthens its far end. It starts at the scarecrow rather than the muzzle
|
||||
## because an enemy hitting the scarecrow stands closer than the muzzle (melee reach
|
||||
## enemy_radius + SCARECROW_RADIUS + enemy_attack_reach is under muzzle_distance) and must burn.
|
||||
func _band_hit(length: float, width: float, max_targets: int, damage: int) -> int:
|
||||
if enemies == null:
|
||||
return 0
|
||||
var es := enemies
|
||||
var p := Vector2(_player.global_position.x, _player.global_position.z)
|
||||
var right := Vector2(-aim.y, aim.x)
|
||||
var muzzle := p + aim * _cfg.muzzle_distance + right * SIDE_OFFSET
|
||||
var found: Array = [] # [distance along the band, slot]
|
||||
for d in es.active_count:
|
||||
if es.alive[d] == 0:
|
||||
continue
|
||||
var e := Vector2(es.pos_x[d], es.pos_z[d])
|
||||
var r := es.t_hit_radius[es.type[d]]
|
||||
var along := (e - muzzle).dot(aim)
|
||||
if along < -_cfg.muzzle_distance or along > length + r or absf((e - muzzle).dot(right)) > width * 0.5 + r:
|
||||
continue
|
||||
if _clear_line(p, e):
|
||||
found.append([along, d])
|
||||
return _hit_nearest(found, max_targets, damage)
|
||||
|
||||
|
||||
## Damages the first max_targets of found ([distance, slot] pairs), nearest first. Returns how many
|
||||
## it hit.
|
||||
func _hit_nearest(found: Array, max_targets: int, damage: int) -> int:
|
||||
var hits := 0
|
||||
var es := enemies
|
||||
found.sort_custom(func(a: Array, b: Array) -> bool: return a[0] < b[0])
|
||||
for k in mini(found.size(), max_targets):
|
||||
var d: int = found[k][1]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue