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
|
|
@ -10,11 +10,20 @@ extends Node3D
|
|||
## pumpkin bomb in the left hand (the off-hand); after a throw the next one grows back in the
|
||||
## hand over the recharge (set_bomb_charge)
|
||||
## attack() plays the weapon's motion (the pumpkin just leaves the hand: the thrown one is
|
||||
## PumpkinBombs').
|
||||
## PumpkinBombs'), or lights a held weapon's effect (below).
|
||||
## Task #7's Potato Cannon, Shurikens, Propane Torch, and Alien Ray have no models of their own
|
||||
## 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 still kicks back like a gun on each attack.
|
||||
## 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
|
||||
## 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
|
||||
## after a Game Over nothing ticks).
|
||||
|
||||
const PATHS: Array[String] = ["res://assets/weapons/PitchFork.glb", "res://assets/weapons/CornShooter.glb",
|
||||
"res://assets/weapons/PumpkinBomb.glb"]
|
||||
|
|
@ -36,6 +45,14 @@ var _pivots: Array[Node3D] = []
|
|||
var _rest: Array[Transform3D] = []
|
||||
var _attack_t := -1.0
|
||||
var _bomb_charge := 1.0
|
||||
## The gameplay muzzle point on the model (setup), where held effects sit.
|
||||
var _muzzle := Vector3.ZERO
|
||||
## Held weapons' effects, by Weapon: {"node": a Node3D with set_lit(bool), "hold": s, "fade": s,
|
||||
## "left": s still lit (> 0), fading (-fade .. 0), or out and hidden (<= -fade)}.
|
||||
var _held := {}
|
||||
## Physics frames since advance() was last called (above 1: nothing steps this scarecrow's
|
||||
## weapons, so its held effects time out on the physics frames instead).
|
||||
var _undriven: int = 0
|
||||
|
||||
|
||||
## A model's mesh, re-centered (the scene's root node sits where it was in Blender).
|
||||
|
|
@ -52,6 +69,7 @@ static func mesh_of(index: int) -> Mesh:
|
|||
## gameplay muzzle point on the model (the corn shooter's tip goes there).
|
||||
func setup(model: Node3D, muzzle: Vector3) -> void:
|
||||
name = "Weapons"
|
||||
_muzzle = muzzle
|
||||
model.add_child(self)
|
||||
# Pitchfork: tines (the mesh's +Y) forward and a little down, the shaft past the right hip.
|
||||
_add(0, Transform3D(Basis.from_euler(Vector3(-1.75, 0.0, 0.0)), Vector3(0.32, 1.15, -0.95)))
|
||||
|
|
@ -102,13 +120,17 @@ func _add_placeholder(index: int, rest: Transform3D, tint: Color) -> void:
|
|||
_rest.append(rest)
|
||||
|
||||
|
||||
## Shows this main weapon (ScarecrowCombat.Weapon) in the right hand, and no other.
|
||||
## Shows this main weapon (ScarecrowCombat.Weapon) in the right hand, and no other (any other
|
||||
## weapon's held effect goes out and is hidden at once).
|
||||
func show_weapon(index: int) -> void:
|
||||
weapon = index
|
||||
_attack_t = -1.0
|
||||
for i in ScarecrowCombat.MAIN_WEAPONS:
|
||||
_pivots[i].visible = i == index
|
||||
_pivots[i].transform = _rest[i]
|
||||
for i: int in _held:
|
||||
if i != index:
|
||||
_set_held(i, -INF)
|
||||
|
||||
|
||||
## Shows this off-hand weapon in the left hand (-1: none).
|
||||
|
|
@ -118,12 +140,50 @@ func show_offhand(index: int) -> void:
|
|||
_pivots[i].visible = i == index
|
||||
|
||||
|
||||
## The main weapon's attack motion: a stab or a kick.
|
||||
## The main weapon's attack motion: a stab or a kick. A held weapon lights its effect instead.
|
||||
func attack(index: int) -> void:
|
||||
if index == weapon:
|
||||
if index != weapon:
|
||||
return
|
||||
if _held.has(index):
|
||||
_set_held(index, float(_held[index]["hold"]))
|
||||
else:
|
||||
_attack_t = 0.0
|
||||
|
||||
|
||||
## Adds a held weapon's effect (index: its ScarecrowCombat.Weapon): a Node3D with set_lit(on),
|
||||
## placed at the muzzle facing the model's way (-Z), out until an attack lights it. hold: s it
|
||||
## stays lit after each attack (longer than the weapon's tick, so it stays lit while fire is
|
||||
## held). fade: s it stays shown once out (fire already in the air dying away).
|
||||
func add_held_effect(index: int, effect: Node3D, hold: float, fade: float = 0.0) -> void:
|
||||
effect.position = _muzzle
|
||||
add_child(effect)
|
||||
_held[index] = {"node": effect, "hold": hold, "fade": fade, "left": 0.0}
|
||||
_set_held(index, -INF)
|
||||
|
||||
|
||||
## A held weapon's effect (null: none).
|
||||
func held_effect(index: int) -> Node3D:
|
||||
return _held[index]["node"] if _held.has(index) else null
|
||||
|
||||
|
||||
## Whether a held weapon's effect is lit: it attacked within its hold, and fire wasn't let go.
|
||||
func lit(index: int) -> bool:
|
||||
return _held.has(index) and float(_held[index]["left"]) > 0.0
|
||||
|
||||
|
||||
## Fire let go: the held weapons' effects go out now (then fade as usual), not hold s later.
|
||||
func douse() -> void:
|
||||
for i: int in _held:
|
||||
if float(_held[i]["left"]) > 0.0:
|
||||
_set_held(i, 0.0)
|
||||
|
||||
|
||||
## Runs the held effects' timers on the simulation's clock (ScarecrowCombat.tick()).
|
||||
func advance(dt: float) -> void:
|
||||
_undriven = 0
|
||||
_advance_held(dt)
|
||||
|
||||
|
||||
## Share of the pumpkin bomb's recharge done (1 = a pumpkin in the hand).
|
||||
func set_bomb_charge(charge: float) -> void:
|
||||
_bomb_charge = clampf(charge, 0.0, 1.0)
|
||||
|
|
@ -137,6 +197,31 @@ func _apply_charge() -> void:
|
|||
_pivots[2].get_child(0).visible = s > 0.05
|
||||
|
||||
|
||||
func _advance_held(dt: float) -> void:
|
||||
for i: int in _held:
|
||||
var left := float(_held[i]["left"])
|
||||
if left > -float(_held[i]["fade"]):
|
||||
_set_held(i, left - dt)
|
||||
|
||||
|
||||
## Sets a held effect's timer (s still lit; at or below 0 out, at or below -fade hidden) and shows
|
||||
## it so.
|
||||
func _set_held(index: int, left: float) -> void:
|
||||
var h: Dictionary = _held[index]
|
||||
var was_lit := float(h["left"]) > 0.0
|
||||
h["left"] = left
|
||||
var node := h["node"] as Node3D
|
||||
if (left > 0.0) != was_lit or left == -INF:
|
||||
node.call(&"set_lit", left > 0.0)
|
||||
node.visible = left > -float(h["fade"])
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
_undriven += 1
|
||||
if _undriven > 1 and not _held.is_empty():
|
||||
_advance_held(delta)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if _attack_t < 0.0 or _pivots.is_empty():
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue