spaceship/NeonDraw.gd
Loïc Wisniewski 85814ce88c Initial commit: SpaceshipTest, a top-down space RTS in Godot 4.7.1
A fleet of neon-outlined ships explores a procedurally generated, seeded
infinite world: tap/joystick steering, pinch zoom, formation pivoting,
planet landings, an ore economy with extractors and haulers, and player
built structures (mothership, ship crafter, command centre).

All art is hand-drawn with draw_* calls rather than textures, and the
backgrounds are camera-relative shaders so they stay precise at large
world coordinates.

Includes a 35-test headless suite (tests/run_tests.sh) plus screenshot
tooling that renders real frames through Xvfb and Mesa softpipe, since
--headless has no GPU.

Excluded from version control: .godot/ (import cache, and it holds
export credentials), builds/, android/build/ and packaged APKs - all
regenerable, and ~325 MB combined.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-10 18:41:58 +02:00

42 lines
2.3 KiB
GDScript

class_name NeonDraw
extends RefCounted
# Cheap "poor man's glow": layered translucent strokes of increasing width
# and decreasing opacity, topped with a bright core line. No solid fill -
# gives ships/enemies/shots a light-made, neon/laser-sabre look without
# needing an HDR bloom pipeline.
#
# The core colour is a parameter rather than always white: the effect is
# built for a dark background, and a near-white core all but disappears
# against a bright one (the lunar surface, whose colours are sampled from a
# real NASA photograph, is a light grey). Callers drawing onto a bright
# backdrop pass a dark core instead, which reads as an inked outline while
# keeping the same layered-glow construction.
const DEFAULT_CORE: Color = Color(1.0, 1.0, 1.0)
static func draw_glowing_polygon(item: CanvasItem, points: PackedVector2Array, glow_color: Color, pulse: float = 1.0, core_color: Color = DEFAULT_CORE) -> void:
var closed: PackedVector2Array = points.duplicate()
closed.append(points[0])
_draw_layers(item, closed, glow_color, pulse, 1.0, core_color)
static func draw_glowing_line(item: CanvasItem, from: Vector2, to: Vector2, glow_color: Color, pulse: float = 1.0, width_scale: float = 1.0, core_color: Color = DEFAULT_CORE) -> void:
_draw_layers(item, PackedVector2Array([from, to]), glow_color, pulse, width_scale, core_color)
# An open run of points - unlike draw_glowing_polygon, the ends are NOT
# joined. For arcs, cradle ribs and other shapes that are deliberately open.
static func draw_glowing_path(item: CanvasItem, points: PackedVector2Array, glow_color: Color, pulse: float = 1.0, width_scale: float = 1.0, core_color: Color = DEFAULT_CORE) -> void:
if points.size() < 2:
return
_draw_layers(item, points, glow_color, pulse, width_scale, core_color)
static func _draw_layers(item: CanvasItem, poly: PackedVector2Array, glow_color: Color, pulse: float, width_scale: float, core_color: Color) -> void:
var c: Color = glow_color
item.draw_polyline(poly, Color(c.r, c.g, c.b, 0.12 * pulse), 18.0 * width_scale, true)
item.draw_polyline(poly, Color(c.r, c.g, c.b, 0.28 * pulse), 10.0 * width_scale, true)
item.draw_polyline(poly, Color(c.r, c.g, c.b, 0.60 * pulse), 5.0 * width_scale, true)
item.draw_polyline(poly, Color(core_color.r, core_color.g, core_color.b, 0.95 * pulse), 1.8 * width_scale, true)