SlimePlatformer/Effects/one_way_tube.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

49 lines
2 KiB
GDScript

class_name OneWayTube
extends RefCounted
# One-way tubes are ordinary tubes (the slime streams through as a PixelStream)
# that only let it in at one end. Their tiles are tagged "tube_one_way", and
# the tile at the entrance also says which of its sides is the way in
# ("tube_one_way_entry": a TUBE_OPEN_... bit, see player.gd). Every other mouth
# is an exit only. TubeVacuum shows where the entrances are.
const ONE_WAY_LAYER = "tube_one_way"
const ENTRY_LAYER = "tube_one_way_entry"
# Whether the tile at `cell` is part of a one-way tube.
static func is_one_way(layer: TileMapLayer, cell: Vector2i) -> bool:
var data := layer.get_cell_tile_data(cell)
if data == null or not data.has_custom_data(ONE_WAY_LAYER):
return false
return data.get_custom_data(ONE_WAY_LAYER)
# The side bit of `cell`'s entrance mouth, or 0 if it has none.
static func get_entry_side(layer: TileMapLayer, cell: Vector2i) -> int:
var data := layer.get_cell_tile_data(cell)
if data == null or not data.has_custom_data(ENTRY_LAYER):
return 0
return data.get_custom_data(ENTRY_LAYER)
# Whether the slime may go into the tube at `cell` heading `direction`. Always
# true for other kinds of tube.
static func can_enter(layer: TileMapLayer, cell: Vector2i, direction: Vector2i) -> bool:
if not is_one_way(layer, cell):
return true
return get_entry_side(layer, cell) & TubeSteer.side_bit(-direction) != 0
# Every entrance mouth in the layer that opens onto an empty tile:
# [{mouth: global point, outward: Vector2}].
static func find_entrances(layer: TileMapLayer) -> Array[Dictionary]:
var entrances: Array[Dictionary] = []
for cell in layer.get_used_cells():
var entrySide := get_entry_side(layer, cell)
if entrySide == 0 or not is_one_way(layer, cell):
continue
for direction in TubeSteer.DIRECTIONS:
if TubeSteer.side_bit(direction) == entrySide and layer.get_cell_source_id(cell + direction) == -1:
entrances.append({mouth = TubeSteer.cell_point(layer, cell, direction), outward = Vector2(direction)})
return entrances