Replace placeholder rendering with real sprites and audio

Terrain, actors, boss and bullets are sprites now, and four sounds play off
server events. 548KB total across seven files, out of 3.9GB of source packs.

- src/view/art.gd holds every atlas rect and sound path in one table, copied
  from the 0x72 pack's own tile_list. Scattering coordinates through draw calls
  would make re-cutting the atlas a hunt, and a wrong rect invisible.
- Bullets get one MultiMesh per kind rather than one overall: a
  MultiMeshInstance2D carries a single texture and each kind needs a different
  region of the sheet. Four draw calls, no custom shader passing UVs through
  per-instance data.
- src/view/sfx.gd is a 16-voice round-robin pool. Bullet-hell fire rates mean
  sounds overlap constantly, and identical sounds landing within two frames are
  collapsed so a ring hitting eight bullets is a bang rather than clipping.
  Every sound is triggered by a server event, never a local guess, so what you
  hear matches what happened.

Audio was converted, not copied: the pack ships 24-bit/96kHz masters averaging
2MB. Downsampled to 16-bit/44.1kHz mono, silence-trimmed, and the shoot sound
hard-capped to 0.30s -- it came out at 2.03s, against a fire cooldown of 0.12s,
which would have smeared held fire into noise.

tests/unit/test_art.gd checks what cannot be eyeballed here: every atlas rect
lands inside its texture, every animation frame of a strip fits (the last frame
is what runs off the sheet, not the first), there is a sprite per bullet kind
and per enemy visual, and no sound is long enough to stack badly. A wrong atlas
coordinate does not error -- it silently draws the wrong pixels.

Licence sources recorded in docs/ASSETS.md now that they are known. All four
are free versions and four rows still say "confirm at source": free itch packs
vary on credit and commercial use, and there is no credits screen yet.

155 tests (was 146). check.sh, test.sh and smoke.sh pass.
This commit is contained in:
claude committed 2026-09-03 23:43:13 +02:00
1 parent 7ee6c8e761
commit 9fa2e260f2
23 files changed
+563 -113

No files matched your search

+62 -43
View File
@@ -1,60 +1,79 @@
extends MultiMeshInstance2D
## Draws the whole bullet field in one draw call.
extends Node2D
## Draws the whole bullet field.
##
## A bullet hell routinely has a thousand bullets on screen. One Node2D each
## A bullet hell routinely has hundreds of bullets on screen. One Node2D each
## would cost more than the simulation does, so the renderer reads the client's
## [BulletPool] arrays directly and pushes them into a MultiMesh. The sprite is
## generated at runtime, so the project needs no art to run.
## [BulletPool] arrays directly and pushes them into MultiMeshes.
##
## One MultiMesh per bullet kind rather than one overall: a MultiMeshInstance2D
## carries a single texture, and each kind needs a different region of the sprite
## sheet. Four kinds means four draw calls, which is nothing, and it avoids a
## custom shader passing UV offsets through per-instance custom data.
const TEXTURE_SIZE := 32
var _colors := {
SimConfig.KIND_PLAYER_SHOT: Color(0.45, 0.95, 1.0),
SimConfig.KIND_ORB: Color(1.0, 0.35, 0.75),
SimConfig.KIND_NEEDLE: Color(1.0, 0.85, 0.3),
SimConfig.KIND_HEAVY: Color(1.0, 0.45, 0.2),
}
var _layers: Array[MultiMeshInstance2D] = []
## Advances the bullets' own animation, independent of the simulation.
var _anim_tick: int = 0
func _ready() -> void:
texture = _make_dot_texture()
var mm := MultiMesh.new()
mm.transform_format = MultiMesh.TRANSFORM_2D
mm.use_colors = true
var quad := QuadMesh.new()
quad.size = Vector2.ONE
mm.mesh = quad
mm.instance_count = SimConfig.MAX_BULLETS
mm.visible_instance_count = 0
multimesh = mm
for kind in SimConfig.KIND_HEAVY + 1:
var layer := MultiMeshInstance2D.new()
layer.texture = Art.BULLETS
var mm := MultiMesh.new()
mm.transform_format = MultiMesh.TRANSFORM_2D
mm.use_colors = true
mm.mesh = quad
mm.instance_count = SimConfig.MAX_BULLETS
mm.visible_instance_count = 0
layer.multimesh = mm
add_child(layer)
_layers.append(layer)
## A soft-edged disc with a bright core, so overlapping bullets stay readable.
func _make_dot_texture() -> ImageTexture:
var img := Image.create(TEXTURE_SIZE, TEXTURE_SIZE, false, Image.FORMAT_RGBA8)
var centre := Vector2(TEXTURE_SIZE, TEXTURE_SIZE) * 0.5
for y in TEXTURE_SIZE:
for x in TEXTURE_SIZE:
var d := Vector2(x + 0.5, y + 0.5).distance_to(centre) / (TEXTURE_SIZE * 0.5)
var alpha := clampf(1.0 - d, 0.0, 1.0)
alpha = pow(alpha, 0.6)
var core := clampf(1.0 - d * 1.9, 0.0, 1.0)
img.set_pixel(x, y, Color(1.0, 1.0, 1.0, alpha).lerp(Color.WHITE, core * 0.8))
return ImageTexture.create_from_image(img)
func _process(_delta: float) -> void:
_anim_tick += 1
_apply_frame()
## Point each layer's texture at this frame's cell in the sheet. Every bullet in
## a layer shares the frame, which is why this is one region assignment rather
## than per-instance work.
func _apply_frame() -> void:
var frame := (_anim_tick / 6) % Art.BULLET_FRAMES
for kind in _layers.size():
var cell: Vector2i = Art.BULLET_CELLS[kind]
var region := Rect2(
Vector2(float(cell.x + frame), float(cell.y)) * Art.BULLET_CELL,
Vector2(Art.BULLET_CELL, Art.BULLET_CELL))
var atlas := _layers[kind].texture as AtlasTexture
if atlas == null:
atlas = AtlasTexture.new()
atlas.atlas = Art.BULLETS
_layers[kind].texture = atlas
atlas.region = region
func render_pool(pool: BulletPool) -> void:
var mm := multimesh
var n := 0
var counts := PackedInt32Array()
counts.resize(_layers.size())
counts.fill(0)
for i in pool.high_water:
if pool.alive[i] == 0:
continue
var kind := clampi(pool.kind[i], 0, _layers.size() - 1)
var n := counts[kind]
if n >= SimConfig.MAX_BULLETS:
break
# The texture's visible disc is about 80% of the quad, so scale up a
# little to make the drawn radius match the radius used for hits.
var d: float = pool.radius[i] * 2.5
mm.set_instance_transform_2d(n, Transform2D(0.0, Vector2(d, d), 0.0, pool.pos[i]))
mm.set_instance_color(n, _colors.get(pool.kind[i], Color.WHITE))
n += 1
mm.visible_instance_count = n
continue
# The art fills its 16px cell, while the radius is the hitbox. Draw a
# little larger so a bullet looks like the threat it is -- the same
# "prefer a visible near-miss" trade the ship sprite makes.
var d: float = pool.radius[i] * 3.0
var angle: float = (pool.vel[i] as Vector2).angle()
_layers[kind].multimesh.set_instance_transform_2d(
n, Transform2D(angle, Vector2(d, d), 0.0, pool.pos[i]))
_layers[kind].multimesh.set_instance_color(n, Color.WHITE)
counts[kind] = n + 1
for kind in _layers.size():
_layers[kind].multimesh.visible_instance_count = counts[kind]