One-way tube exits blow the slime away; validator models blow zones
- Air blows out of one-way exits: orange motes stream out (TubeAirflow, renamed from TubeVacuum, now draws intake and blow) and TubeBlower pushes the slime within 2 tiles of the mouth via player.blow_away(): knocked off walls/ceilings, lifted off the floor. - Generator: at most one one-way tube comes out in each chamber; no other mouth, Start or End inside a blow zone. - Validator (from tiles, via OneWayTube.find_exits/blow_zone): checks the same rules, so each chamber's crawlable boundary stays connected. - maze_check: also checks Start in a blow zone is rejected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e7ae22b8cd
commit
88c4920fde
15 changed files with 380 additions and 120 deletions
|
|
@ -1168,6 +1168,26 @@ func get_camera_focus() -> Vector2:
|
|||
return global_position
|
||||
|
||||
|
||||
# Air blowing out of a one-way tube's exit (TubeBlower) knocks us off whatever
|
||||
# we're stuck to and pushes us at `push` (px/s, at least: we keep any speed we
|
||||
# already have that way). Called every physics frame we're in the air stream.
|
||||
func blow_away(push: Vector2) -> void:
|
||||
if isInTube or isWrapping or isBridging:
|
||||
return
|
||||
isStickingToWall = false
|
||||
isStickingToCeiling = false
|
||||
isHoppingAcross = false
|
||||
timeSpentUnstickingWall = 0.0
|
||||
timeSpentUnstickingCeiling = 0.0
|
||||
timeSpentHoldingEdge = 0.0
|
||||
timeSpentHoldingUpOnFloor = 0.0
|
||||
timeSpentSqueezingIntoTube = 0.0
|
||||
if push.x != 0.0 and velocity.x * signf(push.x) < absf(push.x):
|
||||
velocity.x = push.x
|
||||
if push.y != 0.0 and velocity.y * signf(push.y) < absf(push.y):
|
||||
velocity.y = push.y
|
||||
|
||||
|
||||
func _exit_tube(pose: Dictionary, delta: float) -> void:
|
||||
isInTube = false
|
||||
tubeReentryCooldown = TUBE_REENTRY_DELAY
|
||||
|
|
|
|||
|
|
@ -5,10 +5,12 @@ extends RefCounted
|
|||
# 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.
|
||||
# is an exit only, and air blows out of it, knocking the slime away (TubeBlower).
|
||||
# TubeAirflow shows both: motes drawn into entrances and blown out of exits.
|
||||
|
||||
const ONE_WAY_LAYER = "tube_one_way"
|
||||
const ENTRY_LAYER = "tube_one_way_entry"
|
||||
const BLOW_RANGE = 2 # How many tiles out of an exit mouth the air blows.
|
||||
|
||||
|
||||
# Whether the tile at `cell` is part of a one-way tube.
|
||||
|
|
@ -35,15 +37,44 @@ static func can_enter(layer: TileMapLayer, cell: Vector2i, direction: Vector2i)
|
|||
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}].
|
||||
# Every entrance mouth in the layer that opens onto an empty tile (see _find_mouths).
|
||||
static func find_entrances(layer: TileMapLayer) -> Array[Dictionary]:
|
||||
var entrances: Array[Dictionary] = []
|
||||
return _find_mouths(layer, true)
|
||||
|
||||
|
||||
# Every exit mouth in the layer that opens onto an empty tile (see _find_mouths).
|
||||
# Air blows out of these: see blow_zone() and TubeBlower.
|
||||
static func find_exits(layer: TileMapLayer) -> Array[Dictionary]:
|
||||
return _find_mouths(layer, false)
|
||||
|
||||
|
||||
# The empty tiles the air out of an exit mouth reaches: up to BLOW_RANGE tiles
|
||||
# straight out from the tube tile `cell`'s side `outward`, stopping at anything
|
||||
# solid. MazeCarver uses this before the tube's tiles are down, so it only
|
||||
# looks at the tiles in front.
|
||||
static func blow_zone(layer: TileMapLayer, cell: Vector2i, outward: Vector2i) -> Array[Vector2i]:
|
||||
var zone: Array[Vector2i] = []
|
||||
for step in range(1, BLOW_RANGE + 1):
|
||||
var zoneCell := cell + outward * step
|
||||
if layer.get_cell_source_id(zoneCell) != -1:
|
||||
break
|
||||
zone.append(zoneCell)
|
||||
return zone
|
||||
|
||||
|
||||
# One-way mouths opening onto an empty tile, entrances or exits:
|
||||
# [{cell, mouth: global point, outward: Vector2i}].
|
||||
static func _find_mouths(layer: TileMapLayer, isEntrance: bool) -> Array[Dictionary]:
|
||||
var mouths: 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):
|
||||
if not is_one_way(layer, cell):
|
||||
continue
|
||||
var openings := TubeSteer.get_openings(layer, cell)
|
||||
var entrySide := get_entry_side(layer, cell)
|
||||
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
|
||||
var side := TubeSteer.side_bit(direction)
|
||||
if openings & side == 0 or layer.get_cell_source_id(cell + direction) != -1:
|
||||
continue
|
||||
if (side == entrySide) == isEntrance:
|
||||
mouths.append({cell = cell, mouth = TubeSteer.cell_point(layer, cell, direction), outward = direction})
|
||||
return mouths
|
||||
|
|
|
|||
79
Effects/tube_airflow.gd
Normal file
79
Effects/tube_airflow.gd
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
class_name TubeAirflow
|
||||
extends Node2D
|
||||
|
||||
# Orange motes showing the air through every one-way tube (OneWayTube) in
|
||||
# `layer`. At an entrance they drift in like dust sucked into a vacuum: they
|
||||
# start spread in a fan in front of the mouth, speed up and funnel into it. At
|
||||
# an exit they're blown out: fast at first, slowing and spreading as they go,
|
||||
# fading out at the end of the blow zone (where TubeBlower stops pushing).
|
||||
# Call refresh() after changing the layer's tiles.
|
||||
|
||||
const MOTES_PER_MOUTH = 18
|
||||
const INTAKE_REACH = 40.0 # How far out from an entrance motes start, in px.
|
||||
const INTAKE_SPREAD = 22.0 # How far to the side of an entrance motes can start, in px.
|
||||
const BLOW_SPREAD = 14.0 # How far to the side blown motes drift by the end, in px.
|
||||
const TRIP_TIME = 1.1 # Seconds per mote trip.
|
||||
const BLOW_TRIP_TIME = 0.6 # Blown motes are quicker.
|
||||
const FADE = 0.2 # The share of a trip spent fading in (intake) or out (blown).
|
||||
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
|
||||
|
||||
# Per mouth: {mouth, outward: Vector2, isIntake, reach: px, spread: px, tripTime}.
|
||||
var _mouths: Array[Dictionary] = []
|
||||
var _time := 0.0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
top_level = true # Mouths are in global coordinates.
|
||||
z_index = 1 # In front of the tiles.
|
||||
refresh()
|
||||
|
||||
|
||||
func refresh() -> void:
|
||||
_mouths.clear()
|
||||
if layer == null:
|
||||
return
|
||||
for entrance in OneWayTube.find_entrances(layer):
|
||||
_mouths.append({mouth = entrance.mouth, outward = Vector2(entrance.outward), isIntake = true,
|
||||
reach = INTAKE_REACH, spread = INTAKE_SPREAD, tripTime = TRIP_TIME})
|
||||
var tileLength := float(layer.tile_set.tile_size.x)
|
||||
for exit in OneWayTube.find_exits(layer):
|
||||
var zoneLength := OneWayTube.blow_zone(layer, exit.cell, exit.outward).size()
|
||||
_mouths.append({mouth = exit.mouth, outward = Vector2(exit.outward), isIntake = false,
|
||||
reach = zoneLength * tileLength, spread = BLOW_SPREAD, tripTime = BLOW_TRIP_TIME})
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if _mouths.is_empty():
|
||||
return
|
||||
_time += delta
|
||||
queue_redraw()
|
||||
|
||||
|
||||
func _draw() -> void:
|
||||
for mouthIndex in _mouths.size():
|
||||
var mouth: Dictionary = _mouths[mouthIndex]
|
||||
var across: Vector2 = mouth.outward.orthogonal()
|
||||
for moteIndex in MOTES_PER_MOUTH:
|
||||
# Each mote loops on its own offset, and gets a fresh random path
|
||||
# each trip.
|
||||
var tripClock: float = _time / mouth.tripTime + 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: float = random.randf_range(-1.0, 1.0) * mouth.spread
|
||||
var lighten := random.randf() * MOTE_LIGHTEN
|
||||
var moteSize := Vector2.ONE * (2.0 if random.randf() < BIG_MOTE_SHARE else 1.0)
|
||||
# How far out the mote is, from 0 (at the mouth) to 1 (at its reach).
|
||||
# Drawn in: slow at first, then faster. Blown out: fast, then slower.
|
||||
var out := 1.0 - progress * progress if mouth.isIntake else 1.0 - (1.0 - progress) * (1.0 - progress)
|
||||
var at: Vector2 = mouth.mouth + mouth.outward * (mouth.reach * out) + across * (side * out)
|
||||
var color := MOTE_COLOR.lightened(lighten)
|
||||
var fade := progress if mouth.isIntake else 1.0 - progress
|
||||
color.a = clampf(fade / FADE, 0.0, 1.0)
|
||||
draw_rect(Rect2(at.floor(), moteSize), color)
|
||||
51
Effects/tube_blower.gd
Normal file
51
Effects/tube_blower.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
class_name TubeBlower
|
||||
extends Node2D
|
||||
|
||||
# Air blowing out of every one-way tube's exit (OneWayTube.blow_zone) in
|
||||
# `layer`. While `target`'s middle is in a blow zone, it's knocked away from
|
||||
# the mouth: off a wall or ceiling it's stuck to, or lifted off the floor
|
||||
# (the target's blow_away(), see player.gd). Sideways blowers also lift a
|
||||
# little, so they knock the slime off the floor too, not just slide it.
|
||||
# Outside the zone there's no push, so the slime can always get away (it can
|
||||
# steer in the air, and the zone is never as wide as the chamber).
|
||||
# Call refresh() after changing the layer's tiles.
|
||||
|
||||
const BLOW_SPEED = 240.0 # px/s, away from the mouth.
|
||||
const SIDEWAYS_LIFT = 120.0 # px/s up, for mouths blowing sideways.
|
||||
|
||||
@export var layer: TileMapLayer
|
||||
@export var target: Node2D
|
||||
|
||||
var _zones: Array[Dictionary] = [] # {rect: global Rect2, push: Vector2 px/s}.
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
process_physics_priority = -1 # Before the player moves this frame.
|
||||
refresh()
|
||||
|
||||
|
||||
func refresh() -> void:
|
||||
_zones.clear()
|
||||
if layer == null:
|
||||
return
|
||||
var tileSize := Vector2(layer.tile_set.tile_size)
|
||||
for exit in OneWayTube.find_exits(layer):
|
||||
var zone := OneWayTube.blow_zone(layer, exit.cell, exit.outward)
|
||||
if zone.is_empty():
|
||||
continue
|
||||
var push := Vector2(exit.outward) * BLOW_SPEED
|
||||
if exit.outward.y == 0:
|
||||
push.y = -SIDEWAYS_LIFT
|
||||
var rect := Rect2(layer.to_global(layer.map_to_local(zone[0])) - tileSize / 2.0, tileSize)
|
||||
for zoneCell in zone:
|
||||
rect = rect.merge(Rect2(layer.to_global(layer.map_to_local(zoneCell)) - tileSize / 2.0, tileSize))
|
||||
_zones.append({rect = rect, push = push})
|
||||
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if target == null or not target.has_method(&"blow_away"):
|
||||
return
|
||||
for zone in _zones:
|
||||
if zone.rect.has_point(target.global_position):
|
||||
target.blow_away(zone.push)
|
||||
return
|
||||
1
Effects/tube_blower.gd.uid
Normal file
1
Effects/tube_blower.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dk3hpd05c3lnr
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
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)
|
||||
|
|
@ -9,6 +9,11 @@ extends RefCounted
|
|||
# tile of rock all round, so chambers never touch and never cross a screen
|
||||
# border. Tubes are routed with AStarGrid2D over the rock, with random weights
|
||||
# so they wander; tubes never share a tile, so they can't join by accident.
|
||||
#
|
||||
# Air blows out of one-way tubes' exits (OneWayTube.blow_zone). No other mouth
|
||||
# opens into a blow zone, and Start and End aren't in one, so the slime is never
|
||||
# blown away from something it needs. (MazeGraph keeps it to one blower per
|
||||
# chamber; MazeValidator checks all of this again.)
|
||||
|
||||
const MIN_CHAMBER_SIZE = 3 # Tiles of air across and down, at least.
|
||||
const MIN_ROCK = 3 # Rock left in a region beside its chamber, across and down, at least (when there's room).
|
||||
|
|
@ -27,6 +32,8 @@ var _tiles: MazeTiles
|
|||
var _random: RandomNumberGenerator
|
||||
var _pathfinder := AStarGrid2D.new()
|
||||
var _winding := 0.0
|
||||
var _mouthFronts := {} # Air tile in front of a mouth -> true.
|
||||
var _blowCells := {} # Air tile in a blow zone -> true.
|
||||
|
||||
|
||||
func _init(graph: MazeGraph, screens: Vector2i, layer: TileMapLayer, random: RandomNumberGenerator, winding: float) -> void:
|
||||
|
|
@ -94,9 +101,14 @@ func _random_size(regionSize: int) -> int:
|
|||
return mini(_random.randi_range(MIN_CHAMBER_SIZE, largest), regionSize - 2)
|
||||
|
||||
|
||||
# A random tile along the bottom row of a chamber.
|
||||
# A random tile along the bottom row of a chamber, out of any blow zone (one
|
||||
# blower can't cover a whole row: chambers are wider than its reach).
|
||||
func _floor_cell(rect: Rect2i) -> Vector2i:
|
||||
return Vector2i(_random.randi_range(rect.position.x, rect.end.x - 1), rect.end.y - 1)
|
||||
var cells: Array[Vector2i] = []
|
||||
for x in range(rect.position.x, rect.end.x):
|
||||
if not _blowCells.has(Vector2i(x, rect.end.y - 1)):
|
||||
cells.append(Vector2i(x, rect.end.y - 1))
|
||||
return cells[_random.randi_range(0, cells.size() - 1)]
|
||||
|
||||
|
||||
# ---- Tubes ----
|
||||
|
|
@ -119,8 +131,8 @@ func _carve_tube(tube: Dictionary) -> bool:
|
|||
var fromRect := chamberRects[tube.from]
|
||||
var toRect := chamberRects[tube.to]
|
||||
_randomize_weights()
|
||||
var fromMouths := _mouth_spots(fromRect, toRect)
|
||||
var toMouths := _mouth_spots(toRect, fromRect)
|
||||
var fromMouths := _mouth_spots(fromRect, toRect, false)
|
||||
var toMouths := _mouth_spots(toRect, fromRect, tube.kind == MazeGraph.ONE_WAY)
|
||||
for attempt in ROUTE_TRIES:
|
||||
if fromMouths.is_empty() or toMouths.is_empty():
|
||||
return false
|
||||
|
|
@ -130,6 +142,11 @@ func _carve_tube(tube: Dictionary) -> bool:
|
|||
if path.is_empty():
|
||||
continue
|
||||
_put_tube_tiles(path, fromRect, toRect, tube.kind)
|
||||
_mouthFronts[fromMouth + _side_towards(fromMouth, fromRect)] = true
|
||||
_mouthFronts[toMouth + _side_towards(toMouth, toRect)] = true
|
||||
if tube.kind == MazeGraph.ONE_WAY:
|
||||
for zoneCell in OneWayTube.blow_zone(_layer, toMouth, _side_towards(toMouth, toRect)):
|
||||
_blowCells[zoneCell] = true
|
||||
return true
|
||||
return false
|
||||
|
||||
|
|
@ -143,8 +160,9 @@ func _randomize_weights() -> void:
|
|||
|
||||
|
||||
# Free rock tiles touching `rect`'s sides, where a mouth into it can go: the
|
||||
# MOUTH_CHOICES nearest `towards`.
|
||||
func _mouth_spots(rect: Rect2i, towards: Rect2i) -> Array[Vector2i]:
|
||||
# MOUTH_CHOICES nearest `towards`. None open into a blow zone, and if the mouth
|
||||
# `isBlowing` (a one-way exit), its blow zone has no other mouth in it.
|
||||
func _mouth_spots(rect: Rect2i, towards: Rect2i, isBlowing: bool) -> Array[Vector2i]:
|
||||
var spots: Array[Vector2i] = []
|
||||
for x in range(rect.position.x, rect.end.x):
|
||||
spots.append(Vector2i(x, rect.position.y - 1))
|
||||
|
|
@ -152,13 +170,26 @@ func _mouth_spots(rect: Rect2i, towards: Rect2i) -> Array[Vector2i]:
|
|||
for y in range(rect.position.y, rect.end.y):
|
||||
spots.append(Vector2i(rect.position.x - 1, y))
|
||||
spots.append(Vector2i(rect.end.x, y))
|
||||
spots = spots.filter(func(spot: Vector2i) -> bool: return not _pathfinder.is_point_solid(spot))
|
||||
spots = spots.filter(func(spot: Vector2i) -> bool: return _is_mouth_spot_free(spot, rect, isBlowing))
|
||||
var target := Vector2(towards.get_center())
|
||||
spots.sort_custom(func(a: Vector2i, b: Vector2i) -> bool:
|
||||
return Vector2(a).distance_squared_to(target) < Vector2(b).distance_squared_to(target))
|
||||
return spots.slice(0, MOUTH_CHOICES)
|
||||
|
||||
|
||||
func _is_mouth_spot_free(spot: Vector2i, rect: Rect2i, isBlowing: bool) -> bool:
|
||||
if _pathfinder.is_point_solid(spot):
|
||||
return false
|
||||
var outward := _side_towards(spot, rect)
|
||||
if _blowCells.has(spot + outward):
|
||||
return false
|
||||
if isBlowing:
|
||||
for zoneCell in OneWayTube.blow_zone(_layer, spot, outward):
|
||||
if _mouthFronts.has(zoneCell):
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
# Lays tube tiles along `path`, from a mouth into `fromRect` to one into `toRect`.
|
||||
func _put_tube_tiles(path: Array[Vector2i], fromRect: Rect2i, toRect: Rect2i, kind: StringName) -> void:
|
||||
var last := path.size() - 1
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ extends RefCounted
|
|||
# tubes only add ways, so they can't take that away. And every chamber is
|
||||
# reachable from Start: the route's one-way tubes point away from Start, and
|
||||
# everything off the route hangs off it by two-way tubes.
|
||||
#
|
||||
# At most one one-way tube comes out in each chamber: air blows out of its exit
|
||||
# (TubeBlower), and one blow zone can't cut a chamber in two (see docs/MAZE.md).
|
||||
# MazeValidator checks the finished tiles anyway.
|
||||
|
||||
const AUTO = &"auto"
|
||||
|
|
@ -158,6 +161,13 @@ func _route() -> Array[int]:
|
|||
return route
|
||||
|
||||
|
||||
func _has_one_way_into(chamber: int) -> bool:
|
||||
for tube in tubes:
|
||||
if tube.kind == ONE_WAY and tube.to == chamber:
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _tube_between(chamberA: int, chamberB: int) -> int:
|
||||
for i in tubes.size():
|
||||
var tube := tubes[i]
|
||||
|
|
@ -173,7 +183,7 @@ func _add_extra_tubes(count: int) -> void:
|
|||
var to := _random_nearby(from)
|
||||
if to == -1 or _tube_between(from, to) != -1:
|
||||
continue
|
||||
var kind := ONE_WAY if _random.randf() < 0.5 else _two_way_kind()
|
||||
var kind := ONE_WAY if _random.randf() < 0.5 and not _has_one_way_into(to) else _two_way_kind()
|
||||
tubes.append({from = from, to = to, kind = kind, isRequired = false})
|
||||
break
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ const MENU_SCENE = "res://UI/main_menu.tscn"
|
|||
|
||||
@onready var layer: TileMapLayer = $TileMapLayer
|
||||
@onready var player: CharacterBody2D = $Player
|
||||
@onready var vacuum: TubeVacuum = $TubeVacuum
|
||||
@onready var airflow: TubeAirflow = $TubeAirflow
|
||||
@onready var blower: TubeBlower = $TubeBlower
|
||||
@onready var startMarker: MazeMarker = $StartMarker
|
||||
@onready var endMarker: MazeMarker = $EndMarker
|
||||
@onready var pauseMenu: CanvasLayer = $PauseMenu
|
||||
|
|
@ -28,7 +29,8 @@ func _ready() -> void:
|
|||
endMarker.position = layer.map_to_local(builder.carver.endCell)
|
||||
player.global_position = startMarker.global_position
|
||||
player.reset_physics_interpolation()
|
||||
vacuum.refresh()
|
||||
airflow.refresh()
|
||||
blower.refresh()
|
||||
endMarker.reached.connect(_on_end_reached)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
[ext_resource type="Script" path="res://Levels/room_camera.gd" id="4_camera"]
|
||||
[ext_resource type="PackedScene" path="res://UI/pause_menu.tscn" id="5_pause"]
|
||||
[ext_resource type="AudioStream" path="res://Assets/Sounds/Itty Bitty 8 Bit.mp3" id="6_music"]
|
||||
[ext_resource type="Script" path="res://Effects/tube_vacuum.gd" id="7_vacuum"]
|
||||
[ext_resource type="Script" path="res://Effects/tube_airflow.gd" id="7_airflow"]
|
||||
[ext_resource type="Script" path="res://Effects/tube_blower.gd" id="10_blower"]
|
||||
[ext_resource type="Script" path="res://Levels/Maze/maze_marker.gd" id="8_marker"]
|
||||
[ext_resource type="PackedScene" path="res://Levels/Maze/maze_win_menu.tscn" id="9_win"]
|
||||
|
||||
|
|
@ -27,10 +28,15 @@ isGoal = true
|
|||
|
||||
[node name="Player" parent="." instance=ExtResource("2_player")]
|
||||
|
||||
[node name="TubeVacuum" type="Node2D" parent="." node_paths=PackedStringArray("layer")]
|
||||
script = ExtResource("7_vacuum")
|
||||
[node name="TubeAirflow" type="Node2D" parent="." node_paths=PackedStringArray("layer")]
|
||||
script = ExtResource("7_airflow")
|
||||
layer = NodePath("../TileMapLayer")
|
||||
|
||||
[node name="TubeBlower" type="Node2D" parent="." node_paths=PackedStringArray("layer", "target")]
|
||||
script = ExtResource("10_blower")
|
||||
layer = NodePath("../TileMapLayer")
|
||||
target = NodePath("../Player")
|
||||
|
||||
[node name="RoomCamera" type="Camera2D" parent="." node_paths=PackedStringArray("target")]
|
||||
script = ExtResource("4_camera")
|
||||
target = NodePath("../Player")
|
||||
|
|
|
|||
|
|
@ -14,6 +14,17 @@ extends RefCounted
|
|||
# - Manual and goo tubes: in at any mouth, out at any mouth of the same network.
|
||||
# A mouth only leads somewhere if there's air in front of it.
|
||||
#
|
||||
# Air blows out of one-way exits (OneWayTube.blow_zone, TubeBlower) and knocks
|
||||
# the slime away, so it can't stay in a blow zone. A blow zone is a strip of
|
||||
# air tiles straight out from a wall. If it's shorter than the chamber is deep
|
||||
# that way, it cuts the chamber's boundary (the loop of tile sides the slime
|
||||
# crawls round) in one place only, so every tile side outside it can still be
|
||||
# reached the other way round. Two zones could cut the loop twice and split the
|
||||
# chamber, so each chamber may have one at most. No other mouth may open into a
|
||||
# zone, and Start and End can't be in one. Then the model above still holds.
|
||||
# The slime can't be pinned: outside the zone there's no push, it's always
|
||||
# pushed out of the zone, and it can steer in the air.
|
||||
#
|
||||
# The maze passes if End can be reached from Start, and End can still be
|
||||
# reached from every chamber that can be reached from Start.
|
||||
|
||||
|
|
@ -26,6 +37,7 @@ var mouthCount := 0
|
|||
var _layer: TileMapLayer
|
||||
var _bounds: Rect2i
|
||||
var _chamberAt := {} # Air tile -> chamber index.
|
||||
var _chamberSizes: Array[Vector2i] = [] # Per chamber: its size in tiles.
|
||||
var _links: Array[Dictionary] = [] # Per chamber: chamber -> true for each one a tube leads to.
|
||||
|
||||
|
||||
|
|
@ -37,6 +49,8 @@ func _init(layer: TileMapLayer, bounds: Rect2i, startCell: Vector2i, endCell: Ve
|
|||
if not _chamberAt.has(startCell) or not _chamberAt.has(endCell):
|
||||
problem = "Start or End is not in the air"
|
||||
return
|
||||
if not _check_blowers(startCell, endCell):
|
||||
return
|
||||
_find_links()
|
||||
var reachable := _search(_chamberAt[startCell], false)
|
||||
var canFinish := _search(_chamberAt[endCell], true)
|
||||
|
|
@ -86,6 +100,7 @@ func _flood_chamber(first: Vector2i, chamber: int) -> bool:
|
|||
_chamberAt[next] = chamber
|
||||
cells.append(next)
|
||||
var size := high - low + Vector2i.ONE
|
||||
_chamberSizes.append(size)
|
||||
if size.x * size.y != cells.size():
|
||||
problem = "Chamber %d is not a rectangle" % chamber
|
||||
return false
|
||||
|
|
@ -96,20 +111,53 @@ func _is_air(cell: Vector2i) -> bool:
|
|||
return _layer.get_cell_source_id(cell) == -1
|
||||
|
||||
|
||||
# Every tube mouth (a tube tile side open onto air) and where going in there
|
||||
# can take the slime.
|
||||
func _find_links() -> void:
|
||||
# Checks the blow zones of one-way exits keep the movement model true (see the
|
||||
# top of this file).
|
||||
func _check_blowers(startCell: Vector2i, endCell: Vector2i) -> bool:
|
||||
var blownChambers := {}
|
||||
var blowCellOwners := {} # Air tile in a blow zone -> the exit tube tile blowing there.
|
||||
for exit in OneWayTube.find_exits(_layer):
|
||||
var zone := OneWayTube.blow_zone(_layer, exit.cell, exit.outward)
|
||||
var chamber: int = _chamberAt[zone[0]]
|
||||
if blownChambers.has(chamber):
|
||||
problem = "Chamber %d has more than one blow zone" % chamber
|
||||
return false
|
||||
blownChambers[chamber] = true
|
||||
var depth := _chamberSizes[chamber].x if exit.outward.x != 0 else _chamberSizes[chamber].y
|
||||
if zone.size() >= depth:
|
||||
problem = "A blow zone spans chamber %d" % chamber
|
||||
return false
|
||||
for zoneCell in zone:
|
||||
blowCellOwners[zoneCell] = exit.cell
|
||||
if blowCellOwners.has(startCell) or blowCellOwners.has(endCell):
|
||||
problem = "Start or End is in a blow zone"
|
||||
return false
|
||||
for mouth in _mouths():
|
||||
var front: Vector2i = mouth.cell + mouth.outward
|
||||
if blowCellOwners.has(front) and blowCellOwners[front] != mouth.cell:
|
||||
problem = "A mouth at %s opens into a blow zone" % mouth.cell
|
||||
return false
|
||||
return true
|
||||
|
||||
|
||||
# Every tube mouth: a tube tile side open onto air. [{cell, outward}].
|
||||
func _mouths() -> Array[Dictionary]:
|
||||
var mouths: Array[Dictionary] = []
|
||||
for cell: Vector2i in _layer.get_used_cells():
|
||||
var openings := TubeSteer.get_openings(_layer, cell)
|
||||
if openings == 0:
|
||||
continue
|
||||
for outward in TubeSteer.DIRECTIONS:
|
||||
if openings & TubeSteer.side_bit(outward) == 0 or not _chamberAt.has(cell + outward):
|
||||
continue
|
||||
mouthCount += 1
|
||||
var from: int = _chamberAt[cell + outward]
|
||||
for to in _exits(cell, -outward):
|
||||
_links[from][to] = true
|
||||
if openings & TubeSteer.side_bit(outward) and _chamberAt.has(cell + outward):
|
||||
mouths.append({cell = cell, outward = outward})
|
||||
return mouths
|
||||
|
||||
|
||||
# Where going into each mouth can take the slime.
|
||||
func _find_links() -> void:
|
||||
for mouth in _mouths():
|
||||
mouthCount += 1
|
||||
var from: int = _chamberAt[mouth.cell + mouth.outward]
|
||||
for to in _exits(mouth.cell, -mouth.outward):
|
||||
_links[from][to] = true
|
||||
|
||||
|
||||
# The chambers the slime can come out in after going into `cell` heading `direction`.
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
- Player (`Characters/player.gd`): the slime: crawling on any surface, hops, bridges, edge wraps, going into tubes.
|
||||
- Tubes (`Effects/`): tiles the slime squeezes through. Kinds: auto (`PixelStream`), manual (`TubeSteer`), goo (`TubeGoo`), one-way (`OneWayTube`, an auto tube with one entrance).
|
||||
- Tube effects (`Effects/tube_vacuum.gd`): visual effects tied to tube tiles, such as motes drifting into one-way entrances.
|
||||
- Tube air (`Effects/tube_airflow.gd`, `Effects/tube_blower.gd`): air through one-way tubes: motes in and out, and the blow that knocks the slime away from exits.
|
||||
- Room camera (`Levels/room_camera.gd`): screen-by-screen camera that cuts between 640x480 rooms.
|
||||
- Maze generation (`Levels/Maze/`): builds, validates and plays random tube mazes (see `docs/MAZE.md`).
|
||||
- Screens and transitions (`Autoloads/pixel_screen.gd`, `Autoloads/transition.gd`): the 640x480 pixel screen and the dissolve between scenes.
|
||||
|
|
|
|||
38
docs/MAZE.md
38
docs/MAZE.md
|
|
@ -18,6 +18,10 @@ generates a level of rock chambers joined by tubes, with a Start and an End.
|
|||
5. One-way tubes: orange tiles; only their entrance mouth lets the slime in;
|
||||
orange motes drift into the entrance like a vacuum. Built by extending the
|
||||
existing tube code (the auto tube's `PixelStream`), not by copying it.
|
||||
5b. Air blows out of a one-way tube's **exit**: orange motes stream out of it,
|
||||
and within 2 tiles straight out of the mouth (the "blow zone") the slime is
|
||||
knocked off a wall or ceiling, or lifted off the floor (240 px/s away from
|
||||
the mouth; sideways blowers also lift at 120 px/s). It can never be pinned.
|
||||
6. Start and End are clearly visible (a green START pad, a gold END pad).
|
||||
Touching End shows a win panel with **New maze** and **Main menu**.
|
||||
7. **No soft-locks.** For every chamber the slime can reach from Start, End is
|
||||
|
|
@ -41,8 +45,9 @@ Extra tubes are about half one-way (traps/shortcuts), half two-way (loops).
|
|||
## Non-goals
|
||||
|
||||
- No change to player movement, existing levels or other menus (besides the
|
||||
one button). The player only gains the "one-way tubes only let you in at
|
||||
their entrance" rule, which is part of the new tube kind.
|
||||
one button). The player only gains what the new tube kind needs: one-way
|
||||
tubes only let it in at their entrance, and `blow_away()` for the air out
|
||||
of their exits.
|
||||
- No tube crossings or branching tube networks in mazes.
|
||||
- No ledges, hazards, items or enemies inside chambers: chambers are plain
|
||||
rectangles (this is what keeps the movement model below exact).
|
||||
|
|
@ -66,6 +71,25 @@ ways between them are tubes:
|
|||
- A mouth only counts as an exit if the tile in front of it is air (room for
|
||||
the slime to reform).
|
||||
|
||||
### Blow zones
|
||||
|
||||
The slime can't stay in a blow zone, so the zone's tiles are taken out of the
|
||||
chamber. A zone is a strip straight out from one wall, shorter than the
|
||||
chamber is deep that way. It cuts the chamber's boundary loop (the tile sides
|
||||
the slime crawls round) in one place only, so every other part of the loop is
|
||||
still reachable the other way round. Two zones could cut the loop twice and
|
||||
split the chamber, so the model holds only if:
|
||||
|
||||
- each chamber has at most one blow zone (the generator lets at most one
|
||||
one-way tube come out in each chamber);
|
||||
- a zone is shorter than its chamber in its direction (chambers are at least
|
||||
3 tiles; zones at most 2);
|
||||
- no other tube mouth opens into a zone, and Start and End are not in one.
|
||||
|
||||
Not pinned: outside the zone there is no push, the push always points out of
|
||||
the zone, and the slime can steer in the air. A floor blower lifts it up to the
|
||||
ceiling or out of the zone; it can then crawl or fall away.
|
||||
|
||||
## The soft-lock check (`MazeValidator`)
|
||||
|
||||
Works only from the TileMapLayer:
|
||||
|
|
@ -73,6 +97,8 @@ Works only from the TileMapLayer:
|
|||
1. Flood-fill the air cells inside the maze into chambers. Fail if air leaks
|
||||
out of the maze bounds or a chamber is not a full rectangle (the movement
|
||||
model above would not hold).
|
||||
1b. Check the blow zone rules above (rebuilt from the tiles with
|
||||
`OneWayTube.find_exits` and `blow_zone`, the same functions the game uses).
|
||||
2. Find every tube mouth (a tube tile side that is open onto air).
|
||||
3. Build a directed chamber graph from the tube rules above.
|
||||
4. **Forward** search from the Start chamber gives `reachable`. **Backward**
|
||||
|
|
@ -127,12 +153,16 @@ screens naturally, and safety does not depend on luck.
|
|||
- `Assets/level_tiles.tres` - orange alternatives 3-5 on the six two-sided
|
||||
tube tiles (3 = body/exit, 4 and 5 = entrance on each side), and the
|
||||
`tube_one_way` / `tube_one_way_entry` custom data layers.
|
||||
- `Effects/tube_vacuum.gd` - the orange motes drifting into entrances.
|
||||
- `Effects/tube_airflow.gd` - orange motes drifting into entrances and
|
||||
blown out of exits.
|
||||
- `Effects/tube_blower.gd` - pushes the slime in blow zones (calls the
|
||||
player's `blow_away()`).
|
||||
- `tests/maze_check.gd` - the headless batch check.
|
||||
|
||||
Run the check:
|
||||
`godot --headless --audio-driver Dummy --script res://tests/maze_check.gd`
|
||||
|
||||
The check also builds one known soft-lock (a chamber whose tubes are all
|
||||
The check also checks the validator rejects Start inside a blow zone, and
|
||||
builds one known soft-lock (a chamber whose tubes are all
|
||||
turned into one-way tubes leading in, while Start still reaches End another
|
||||
way) and makes sure the validator rejects it.
|
||||
|
|
|
|||
|
|
@ -37,13 +37,30 @@ func _initialize() -> void:
|
|||
|
||||
var caught := _check_trap_is_caught(layer)
|
||||
print("Validator catches a one-way trap: %s" % ("yes" if caught else "NO"))
|
||||
quit(0 if validCount == mazeCount and caught else 1)
|
||||
var blowCaught := _check_blow_zone_is_caught(layer)
|
||||
print("Validator catches Start in a blow zone: %s" % ("yes" if blowCaught else "NO"))
|
||||
quit(0 if validCount == mazeCount and caught and blowCaught else 1)
|
||||
|
||||
|
||||
# A good maze, checked again as if Start stood in a one-way exit's blow zone
|
||||
# (the slime would be blown off it). The validator must reject it.
|
||||
func _check_blow_zone_is_caught(layer: TileMapLayer) -> bool:
|
||||
for blowSeed in range(4242, 4282):
|
||||
var builder := MazeBuilder.new(layer, Vector2i(2, 2), 4, blowSeed)
|
||||
var exits := OneWayTube.find_exits(layer)
|
||||
if not builder.isValid or exits.is_empty():
|
||||
continue
|
||||
var zone := OneWayTube.blow_zone(layer, exits[0].cell, exits[0].outward)
|
||||
var validator := MazeValidator.new(layer, builder.carver.bounds, zone[0], builder.carver.endCell)
|
||||
print(" blow zone test (seed %d): %s" % [blowSeed, validator.problem])
|
||||
return not validator.isValid
|
||||
return false
|
||||
|
||||
|
||||
# A real soft-lock: in a good maze, take a tube from Start's chamber to some
|
||||
# chamber X (not End's), and turn every tube with a mouth in X into a one-way
|
||||
# tube that only leads into X. X is then reachable from Start but has no way
|
||||
# out. Tries mazes until Start can still reach End some other way, so a plain
|
||||
# chamber X (not End's) and make it one-way into X, and block every other
|
||||
# mouth in X with rock. X is then reachable from Start but has no way out.
|
||||
# Tries mazes until Start can still reach End some other way, so a plain
|
||||
# "Start reaches End" check would pass. The validator must reject it as a
|
||||
# soft-lock.
|
||||
func _check_trap_is_caught(layer: TileMapLayer) -> bool:
|
||||
|
|
@ -64,25 +81,22 @@ func _check_trap_is_caught(layer: TileMapLayer) -> bool:
|
|||
func _set_trap(layer: TileMapLayer, carver: MazeCarver) -> bool:
|
||||
var startRect := _rect_with(carver, carver.startCell)
|
||||
var endRect := _rect_with(carver, carver.endCell)
|
||||
var trapRect := Rect2i()
|
||||
for mouth in _mouths_of(layer, startRect):
|
||||
var tube := _follow_tube(layer, mouth.cell, mouth.outward)
|
||||
var farRect := _rect_with(carver, tube.cells.back() + tube.farOutward)
|
||||
if farRect != endRect and farRect != startRect:
|
||||
trapRect = farRect
|
||||
break
|
||||
if trapRect.size == Vector2i.ZERO:
|
||||
return false
|
||||
var tiles := MazeTiles.new(layer.tile_set)
|
||||
for mouth in _mouths_of(layer, trapRect):
|
||||
var tube := _follow_tube(layer, mouth.cell, mouth.outward)
|
||||
var trapMouth: Vector2i = tube.cells.back()
|
||||
var trapRect := _rect_with(carver, trapMouth + tube.farOutward)
|
||||
if trapRect == endRect or trapRect == startRect:
|
||||
continue
|
||||
var tiles := MazeTiles.new(layer.tile_set)
|
||||
for other in _mouths_of(layer, trapRect):
|
||||
if other.cell != trapMouth:
|
||||
tiles.set_tile(layer, other.cell, 0, MazeTiles.ROCK)
|
||||
var cells: Array[Vector2i] = tube.cells
|
||||
for i in cells.size():
|
||||
var cell := cells[i]
|
||||
var isEntrance := i == cells.size() - 1
|
||||
var entrySide := TubeSteer.side_bit(tube.farOutward) if isEntrance else 0
|
||||
tiles.set_tile(layer, cell, TubeSteer.get_openings(layer, cell), MazeGraph.ONE_WAY, entrySide)
|
||||
return true
|
||||
var entrySide := TubeSteer.side_bit(mouth.outward) if i == 0 else 0
|
||||
tiles.set_tile(layer, cells[i], TubeSteer.get_openings(layer, cells[i]), MazeGraph.ONE_WAY, entrySide)
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
func _rect_with(carver: MazeCarver, cell: Vector2i) -> Rect2i:
|
||||
|
|
|
|||
Loading…
Reference in a new issue