SlimePlatformer/Effects/tube_blower.gd
tachyonwolf 88c4920fde 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>
2026-11-16 15:52:58 -06:00

51 lines
1.8 KiB
GDScript

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