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
|
|
@ -4,7 +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,
|
||||
## a pumpkin bomb's toss and burst), hurt, fall, fear and fear ready, patching and patched
|
||||
## the propane torch's roar, a pumpkin bomb's toss and burst), hurt, fall, fear and fear
|
||||
## ready, patching and patched
|
||||
## * enemies: crow caws and thieves' / fence breakers' arrivals (from where they come in), hits
|
||||
## and deaths by type
|
||||
## * theft: grabbed, dropped, recovered, carried off (with an alarm tone), animals following
|
||||
|
|
@ -41,6 +42,8 @@ const CUES := {
|
|||
"step": {"files": ["kenney/impact/footstep_grass_00*.ogg"], "db": -15.0, "pitch": 0.08},
|
||||
"shot": {"files": ["kenney/interface/pluck_00*.ogg"], "db": -9.0, "pitch": 0.12, "max": 3},
|
||||
"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},
|
||||
"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},
|
||||
|
|
@ -298,6 +301,7 @@ func _wire_weapons(combat: ScarecrowCombat, at: Callable) -> void:
|
|||
var where := func() -> Vector3: return at.call() if at.is_valid() else Vector3.INF
|
||||
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.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()))
|
||||
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ extends Resource
|
|||
"pumpkin_bomb": {"name": "Pumpkin bombs", "text": "Throw a pumpkin that bursts, hurting everything within 3 m (one every 4 s)", "track": "Weapon", "shop": "shed"},
|
||||
"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 short-range jet of flame that burns everything in its cone while held", "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},
|
||||
"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},
|
||||
|
|
@ -286,12 +286,13 @@ extends Resource
|
|||
@export var shuriken_speed: float = 34.0
|
||||
@export var shuriken_lifetime: float = 1.0
|
||||
@export_range(1, 6) var shuriken_count: int = 1
|
||||
## Propane Torch (the Propane torch upgrade, bought at the supply shed): a sustained cone while
|
||||
## held, a tick every torch_tick_interval s, torch_damage each to every enemy within torch_range m
|
||||
## and torch_arc degrees of the aim (the nearest torch_targets), with a clear line (ScarecrowCombat,
|
||||
## the same cone test as the pitchfork's).
|
||||
@export var torch_range: float = 3.5
|
||||
@export var torch_arc: float = 55.0
|
||||
## Propane Torch (the Propane torch upgrade, bought at the supply shed): a band of fire while held
|
||||
## (#17), a tick every torch_tick_interval s, torch_damage each to the enemies in a torch_width m
|
||||
## wide band along the gun's line, from the scarecrow out to torch_range m past the muzzle (the
|
||||
## nearest torch_targets), with a clear line (ScarecrowCombat._band_hit). Its flame (TorchFlame)
|
||||
## is sized to the band.
|
||||
@export var torch_range: float = 4.5
|
||||
@export var torch_width: float = 1.6
|
||||
@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
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
138
game/scripts/torch_flame.gd
Normal file
138
game/scripts/torch_flame.gd
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
class_name TorchFlame
|
||||
extends Node3D
|
||||
## The Propane Torch's flame (#17): a jet of fire particles from the gun's muzzle, sized to the
|
||||
## band ScarecrowCombat burns (length m past the muzzle, width m across), and a flickering orange
|
||||
## light. 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() starts and stops the jet; the fire already out keeps flying
|
||||
## for LIFETIME s after, so the effect fades rather than vanishing.
|
||||
|
||||
## Seconds a puff of fire flies: it covers the band's length in that time.
|
||||
const LIFETIME := 0.35
|
||||
const PUFFS := 72
|
||||
## The jet dips this far below level over its length (radians), so the fire washes over the
|
||||
## enemies in the band rather than flying over their heads from the gun's height.
|
||||
const DIP := 0.17
|
||||
## Fire is brighter than white (HDR, which the filmic tonemap rolls off), so it still burns
|
||||
## through the night look's dimmed, desaturated picture (DayNight's adjustments).
|
||||
const BRIGHTNESS := 1.4
|
||||
const LIGHT_ENERGY := 2.4
|
||||
const LIGHT_COLOR := Color(1.0, 0.55, 0.2)
|
||||
|
||||
## The band it was built for (m).
|
||||
var length: float
|
||||
var width: float
|
||||
var lit := false
|
||||
var _jet: CPUParticles3D
|
||||
var _light: OmniLight3D
|
||||
## The light's flicker draws from its own generator, leaving the global one's sequence alone.
|
||||
var _flicker := RandomNumberGenerator.new()
|
||||
|
||||
|
||||
func _init(p_length: float = 4.5, p_width: float = 1.6) -> void:
|
||||
length = p_length
|
||||
width = p_width
|
||||
name = "TorchFlame"
|
||||
_jet = _build_jet()
|
||||
add_child(_jet)
|
||||
_light = OmniLight3D.new()
|
||||
_light.name = "Glow"
|
||||
_light.light_color = LIGHT_COLOR
|
||||
_light.light_energy = LIGHT_ENERGY
|
||||
_light.omni_range = length
|
||||
_light.shadow_enabled = false
|
||||
_light.position = Vector3(0.0, -0.2, -length * 0.35)
|
||||
add_child(_light)
|
||||
set_lit(false)
|
||||
|
||||
|
||||
## Starts the jet (and its light), or stops it: the puffs in the air fly on and fade.
|
||||
func set_lit(on: bool) -> void:
|
||||
lit = on
|
||||
_jet.emitting = on
|
||||
_light.visible = on
|
||||
|
||||
|
||||
## The jet's direction (unit, world space): forward from the muzzle, dipping.
|
||||
func direction() -> Vector3:
|
||||
return (global_basis * _jet.direction).normalized()
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if lit:
|
||||
_light.light_energy = LIGHT_ENERGY * _flicker.randf_range(0.75, 1.15)
|
||||
|
||||
|
||||
func _build_jet() -> CPUParticles3D:
|
||||
var p := CPUParticles3D.new()
|
||||
p.name = "Jet"
|
||||
p.amount = PUFFS
|
||||
p.lifetime = LIFETIME
|
||||
p.local_coords = false # puffs already out don't swing with the scarecrow
|
||||
p.draw_order = CPUParticles3D.DRAW_ORDER_VIEW_DEPTH # blended back to front
|
||||
p.emission_shape = CPUParticles3D.EMISSION_SHAPE_SPHERE
|
||||
p.emission_sphere_radius = 0.08
|
||||
p.direction = Vector3(0.0, -sin(DIP), -cos(DIP))
|
||||
# Wide enough to fill the band's width at its far end; flattened into a horizontal fan.
|
||||
p.spread = rad_to_deg(atan2(width * 0.5, length)) * 0.8
|
||||
p.flatness = 0.7
|
||||
var speed := length / LIFETIME
|
||||
p.initial_velocity_min = speed * 0.85
|
||||
p.initial_velocity_max = speed * 1.08
|
||||
p.gravity = Vector3(0.0, 1.5, 0.0) # flames rise a little
|
||||
p.angle_min = -180.0
|
||||
p.angle_max = 180.0
|
||||
p.angular_velocity_min = -120.0
|
||||
p.angular_velocity_max = 120.0
|
||||
p.scale_amount_min = 0.8
|
||||
p.scale_amount_max = 1.1
|
||||
var grow := Curve.new()
|
||||
grow.add_point(Vector2(0.0, 0.22))
|
||||
grow.add_point(Vector2(0.45, 0.75))
|
||||
grow.add_point(Vector2(1.0, 1.0))
|
||||
p.scale_amount_curve = grow
|
||||
var ramp := Gradient.new()
|
||||
ramp.set_offset(0, 0.0)
|
||||
ramp.set_color(0, Color(1.0, 0.8, 0.3, 0.95)) # yellow-hot at the nozzle
|
||||
ramp.set_offset(1, 1.0)
|
||||
ramp.set_color(1, Color(0.3, 0.08, 0.04, 0.0)) # smoke, gone
|
||||
ramp.add_point(0.18, Color(1.0, 0.48, 0.06, 0.95))
|
||||
ramp.add_point(0.55, Color(0.95, 0.22, 0.02, 0.85))
|
||||
ramp.add_point(0.8, Color(0.55, 0.08, 0.02, 0.5))
|
||||
p.color_ramp = ramp
|
||||
p.hue_variation_min = -0.02
|
||||
p.hue_variation_max = 0.03
|
||||
var quad := QuadMesh.new()
|
||||
quad.size = Vector2.ONE * width * 0.75
|
||||
quad.material = _puff_material()
|
||||
p.mesh = quad
|
||||
p.cast_shadow = GeometryInstance3D.SHADOW_CASTING_SETTING_OFF
|
||||
return p
|
||||
|
||||
|
||||
## A soft round puff, colored by the particle (vertex color) and always facing the camera. Plain
|
||||
## alpha blending, unlit and unfogged, keeps it fire-colored on bright grass by day and through
|
||||
## the night's fog (additive blending washed it out to white on the grass).
|
||||
static func _puff_material() -> StandardMaterial3D:
|
||||
var dot := Gradient.new()
|
||||
dot.set_color(0, Color(1.0, 1.0, 1.0, 1.0))
|
||||
dot.set_color(1, Color(1.0, 1.0, 1.0, 0.0))
|
||||
dot.add_point(0.45, Color(1.0, 1.0, 1.0, 0.6))
|
||||
var tex := GradientTexture2D.new()
|
||||
tex.gradient = dot
|
||||
tex.fill = GradientTexture2D.FILL_RADIAL
|
||||
tex.fill_from = Vector2(0.5, 0.5)
|
||||
tex.fill_to = Vector2(1.0, 0.5)
|
||||
tex.width = 64
|
||||
tex.height = 64
|
||||
var mat := StandardMaterial3D.new()
|
||||
mat.shading_mode = BaseMaterial3D.SHADING_MODE_UNSHADED
|
||||
mat.transparency = BaseMaterial3D.TRANSPARENCY_ALPHA
|
||||
mat.disable_fog = true
|
||||
mat.billboard_mode = BaseMaterial3D.BILLBOARD_PARTICLES
|
||||
mat.billboard_keep_scale = true
|
||||
mat.vertex_color_use_as_albedo = true
|
||||
mat.albedo_color = Color(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS)
|
||||
mat.albedo_texture = tex
|
||||
mat.cull_mode = BaseMaterial3D.CULL_DISABLED
|
||||
return mat
|
||||
1
game/scripts/torch_flame.gd.uid
Normal file
1
game/scripts/torch_flame.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://kiux8igtayou
|
||||
|
|
@ -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