SlimePlatformer/Effects/tube_vacuum.gd
tachyonwolf e7ae22b8cd Add Maze mode with one-way tubes and a soft-lock check
- Main menu "Maze" button opens a setup panel (width, height in screens;
  complexity 1-5) and generates a maze of rock chambers joined by tubes,
  with Start and End pads and a win panel.
- New one-way tube kind: orange tiles that only let the slime in at their
  entrance, with motes drifting into it (OneWayTube, TubeVacuum). The
  auto-tube trace moved to PixelStream.trace_tube so the player and the
  maze validator share it.
- Generation: chamber graph (spanning tree rooted at End, one-way tubes
  only towards End on the route, extra tubes), carved with AStarGrid2D.
  MazeValidator re-derives the chamber graph from the tiles and checks
  that End is reachable from every chamber reachable from Start.
- tests/maze_check.gd: headless batch check (360 mazes) plus a known
  soft-lock the validator must reject. See docs/MAZE.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 15:45:46 -06:00

63 lines
2.3 KiB
GDScript

class_name TubeVacuum
extends Node2D
# Orange motes drifting into the entrance of every one-way tube (OneWayTube) in
# `layer`, like dust sucked into a vacuum: they start out spread in a fan in
# front of the mouth, speed up as they get close, and funnel into it.
# Call refresh() after changing the layer's tiles.
const MOTES_PER_MOUTH = 18
const REACH = 40.0 # How far out from the mouth motes start, in px.
const SPREAD = 22.0 # How far to the side of the mouth motes can start, in px.
const TRIP_TIME = 1.1 # Seconds from appearing to vanishing into the mouth.
const FADE_IN = 0.2 # The share of the trip spent fading in.
const MOTE_COLOR = Color(1.0, 0.6, 0.2)
const MOTE_LIGHTEN = 0.5 # Motes are up to this much lighter than MOTE_COLOR.
const BIG_MOTE_SHARE = 0.3 # This share of motes are 2x2 pixels; the rest are single pixels.
@export var layer: TileMapLayer
var _entrances: Array[Dictionary] = []
var _time := 0.0
func _ready() -> void:
top_level = true # Entrances are in global coordinates.
z_index = 1 # In front of the tiles.
refresh()
func refresh() -> void:
_entrances = OneWayTube.find_entrances(layer) if layer != null else []
queue_redraw()
func _process(delta: float) -> void:
if _entrances.is_empty():
return
_time += delta
queue_redraw()
func _draw() -> void:
for mouthIndex in _entrances.size():
var entrance: Dictionary = _entrances[mouthIndex]
var outward: Vector2 = entrance.outward
var across := outward.orthogonal()
for moteIndex in MOTES_PER_MOUTH:
# Each mote loops on its own offset, and gets a fresh random start
# each trip.
var tripClock := _time / TRIP_TIME + float(moteIndex) / MOTES_PER_MOUTH
var trip := floori(tripClock)
var progress := tripClock - trip
var random := RandomNumberGenerator.new()
random.seed = hash(Vector3i(mouthIndex, moteIndex, trip))
var side := random.randf_range(-1.0, 1.0) * SPREAD
var lighten := random.randf() * MOTE_LIGHTEN
var moteSize := Vector2.ONE * (2.0 if random.randf() < BIG_MOTE_SHARE else 1.0)
# Slow at first, then faster and faster into the mouth.
var remaining := 1.0 - progress * progress
var at: Vector2 = entrance.mouth + outward * (REACH * remaining) + across * (side * remaining)
var color := MOTE_COLOR.lightened(lighten)
color.a = clampf(progress / FADE_IN, 0.0, 1.0)
draw_rect(Rect2(at.floor(), moteSize), color)