#90: give the laser an ignition instead of a blink

The shot was one flat line that appeared at full length and faded. Nothing
happened at the ship, nothing moved, and a hit looked exactly like a miss.

The blade now runs out of the hull over the first 30% of the flash on a
cubic ease-out, holds white-hot, then falls away, with a hum in its width,
a bright cap at the leading end, a flare at the emitter, and sparks off the
hull that fired it. MuzzleSparkVFX takes an optional colour so the laser
throws cyan where the ordinary gun (#87) keeps its gold.

The extra light is a white-hot rod down the middle at 42% of the width,
deliberately not a wider halo: the note at BEAM_WIDTH_SCALE records that the
drawn beam spans exactly what the beam hits, and a halo past that would put
the "it visibly missed" complaint back the other way round.

The damage is untouched - dealt in full, along the whole beam, on the frame
of the shot. A beam that had to arrive would change how the weapon plays,
which the ticket did not ask for, so the test pins it down: a target at the
far end of the range must be hit before the drawn blade has visibly reached
it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Loïc Wisniewski 2026-08-22 23:29:55 +02:00
commit c8d4731232
4 changed files with 249 additions and 8 deletions

View file

@ -10,8 +10,29 @@ const BEAM_HALF_WIDTH := 38.0
# so it killed things it visibly missed. NeonDraw's widest layer is 18px at
# scale 1, so this makes the glow span exactly what the beam hits.
const BEAM_WIDTH_SCALE := BEAM_HALF_WIDTH * 2.0 / 18.0
const FLASH_DURATION := 0.22
# #90: the beam was one flat line that blinked on at full length and faded.
# It now IGNITES - it runs out of the ship over the first slice of its life,
# holds white-hot, and falls away - which is the sabre look the report asked
# for and also the only part of the shot the eye can follow.
#
# Long enough for the extension to read as movement rather than as a
# stutter, still short enough to be gone before the 4s cooldown is up.
const FLASH_DURATION := 0.34
# The fraction of that life spent extending. The rest holds and decays.
const IGNITE_FRACTION := 0.3
# The white-hot rod down the middle of the coloured glow. Drawn INSIDE the
# beam's own width, never wider: the drawn beam is deliberately the same
# span as the hit test (see BEAM_WIDTH_SCALE above), and a halo painted past
# that would put the "it visibly missed" complaint back the other way round.
const CORE_SCALE := 0.42
const CORE_COLOR := Color(0.85, 0.99, 1.0)
# The leading cap, and the flare left at the emitter. Both are radii, both
# stay within the beam's half width so nothing suggests a wider reach.
const TIP_RADIUS := BEAM_HALF_WIDTH * 0.55
const MUZZLE_RADIUS := BEAM_HALF_WIDTH * 0.8
const ENERGY_PER_SHOT: int = 8
# By path, not by class name - see the note at the top of MuzzleSparkVFX.
const MUZZLE_SPARK = preload("res://vfx/MuzzleSparkVFX.gd")
var beams: Array = []
var last_hit_count: int = 0
@ -55,6 +76,11 @@ func _perform_shot(ship: Node2D, component: Node) -> void:
direction = direction.normalized() if direction.length() > 0.001 else Vector2.UP
var beam_to: Vector2 = ship.global_position + direction * component.beam_range
_strike(ship.global_position, beam_to, direction, int(component.damage))
# #90: something happens at the hull, not just out in space. The ordinary
# gun already does this (#87); the laser fired in complete silence at its
# own end, which is most of why a shot read as a line appearing rather
# than as a vessel firing.
MUZZLE_SPARK.spawn(get_tree().root, ship.global_position, direction, BEAM_COLOR)
func _next_ready_laser_ship() -> Node2D:
@ -70,7 +96,15 @@ func _advance_effects(delta: float) -> void:
func _strike(from: Vector2, to: Vector2, direction: Vector2, damage: int) -> void:
beams.append({"from": from, "to": to, "time": FLASH_DURATION})
# The damage below is dealt HERE, in full, along the whole beam, at the
# instant of the shot. The extension in _draw is the picture of that, not
# a travelling projectile - a beam that had to arrive would be a change
# to how the weapon plays, which #90 did not ask for.
beams.append({
"from": from, "to": to, "time": FLASH_DURATION,
# Per beam, so two lasers firing together do not flicker in lockstep.
"phase": randf() * TAU,
})
last_hit_count = 0
var range_along: float = from.distance_to(to)
# Asteroids share the enemies' take_damage() contract, so the beam sweeps
@ -90,12 +124,49 @@ func _strike(from: Vector2, to: Vector2, direction: Vector2, damage: int) -> voi
last_hit_count += 1
# How far along its length a beam is currently drawn. Cubic ease-out, so it
# leaves the ship fast and settles into full reach rather than crawling.
# Public because it is the whole of #90's "it comes out of the ship" and is
# worth asserting on directly.
func beam_extension(beam: Dictionary) -> float:
var progress: float = 1.0 - float(beam.time) / FLASH_DURATION
var out: float = clampf(progress / IGNITE_FRACTION, 0.0, 1.0)
return 1.0 - pow(1.0 - out, 3.0)
func beam_tip(beam: Dictionary) -> Vector2:
return Vector2(beam.from).lerp(Vector2(beam.to), beam_extension(beam))
func _draw() -> void:
if aiming:
NeonDraw.draw_glowing_line(self, _aim_origin(), aim_target,
TARGET_COLOR, 0.7, 0.6)
for beam in beams:
var progress: float = 1.0 - float(beam.time) / FLASH_DURATION
var alpha: float = 1.0 - progress
NeonDraw.draw_glowing_line(self, beam.from, beam.to,
BEAM_COLOR, alpha, BEAM_WIDTH_SCALE * (1.0 - progress * 0.45))
# Full brightness while it extends, then away. Squared so it holds
# its light and drops at the end, instead of dimming from the first
# frame the way a plain linear fade did.
var decay: float = clampf((progress - IGNITE_FRACTION) / (1.0 - IGNITE_FRACTION), 0.0, 1.0)
var alpha: float = 1.0 - decay * decay
# A live blade hums. Small enough to be texture rather than a blink.
var flicker: float = 1.0 + 0.09 * sin(float(beam.time) * 70.0 + float(beam.phase))
var tip: Vector2 = beam_tip(beam)
var from: Vector2 = beam.from
NeonDraw.draw_glowing_line(self, from, tip, BEAM_COLOR, alpha,
BEAM_WIDTH_SCALE * flicker * (1.0 - decay * 0.45))
# The white-hot rod, over the same span at a fraction of the width.
# This is where the extra light comes from: brighter through the
# middle, not broader across.
NeonDraw.draw_glowing_line(self, from, tip, CORE_COLOR, alpha,
BEAM_WIDTH_SCALE * CORE_SCALE * flicker)
# The leading cap, brightest while the blade is still running out.
var cap: float = TIP_RADIUS * (0.7 + 0.3 * (1.0 - decay)) * flicker
NeonDraw.draw_glowing_circle(self, tip, cap, CORE_COLOR, alpha)
# And the flare left at the emitter, which fades faster than the
# beam so the hull does not keep glowing after the shot is over.
var muzzle: float = MUZZLE_RADIUS * (1.0 - progress)
if muzzle > 1.0:
NeonDraw.draw_glowing_circle(self, from, muzzle, CORE_COLOR,
alpha * (1.0 - progress))