Same pixel effects for auto pipe as manual pipe.
This commit is contained in:
parent
e7c2ae657f
commit
25ff06f642
2 changed files with 52 additions and 9 deletions
|
|
@ -10,6 +10,10 @@ extends Node2D
|
|||
# Pixels keep their colours on the way, and blend into the colour of the spot
|
||||
# they land on, so the sprite reforms exactly.
|
||||
# Watch isFinished to know when every pixel is back in place.
|
||||
# Like TubeSteer, only the coloured pixels go in. A black outline is drawn fresh
|
||||
# round the stream in the tube, and round pixels still (or back) at their spot
|
||||
# in the sprite. Pixels flying between the two don't get one: it would speckle
|
||||
# them all in black.
|
||||
|
||||
# Where the slime's pixels draw while in a tube (this and TubeSteer and TubeGoo):
|
||||
# behind the tiles (z 0), which only show them through the tube's see-through
|
||||
|
|
@ -20,6 +24,7 @@ const SPEED = 240.0 # How fast pixels flow along the path, in px/s.
|
|||
const ROW_SPACING = 1.0 # Gap between rows of pixels in the stream, unless that would make it too long.
|
||||
const GATHER_TIME = 0.12 # How long the nearest pixels take to reach the entry mouth.
|
||||
const LAND_TIME = 0.15 # How long the last pixels out take to reach their spot.
|
||||
const SETTLED_DISTANCE = 1.0 # Pixels within this of their spot in the sprite get an outline.
|
||||
|
||||
var isFinished := false
|
||||
|
||||
|
|
@ -31,6 +36,7 @@ var _lanes := PackedFloat32Array() # How far left of the path's middle it flows.
|
|||
var _rows := PackedInt32Array() # Its place in the stream: row 0 goes in first.
|
||||
var _rowCount := 0
|
||||
var _rowSpacing := ROW_SPACING # Closer if needed to keep the stream within maxLength.
|
||||
var _footprint := {} # Vector2i -> true, for every spot in the sprite we took apart or put back.
|
||||
|
||||
var _path := PackedVector2Array()
|
||||
var _pathDistances := PackedFloat32Array() # How far along the path each point is.
|
||||
|
|
@ -38,7 +44,7 @@ var _time := 0.0
|
|||
|
||||
|
||||
# path: global points from the entry mouth to the exit mouth.
|
||||
# width: how wide the tube is. The stream is this many pixels across.
|
||||
# width: how wide the tube is. The stream is 2 pixels narrower, to leave room for its outline.
|
||||
# maxLength: the longest the stream can be. Rows bunch up (overlapping) to fit.
|
||||
# endTransform: the sprite's global transform once it's back together.
|
||||
# endFrame: the frame it reforms as, so it matches what the sprite shows next.
|
||||
|
|
@ -56,12 +62,14 @@ func start(sprite: Sprite2D, path: PackedVector2Array, width: float, maxLength:
|
|||
# Where the sprite is drawn now: snapped to whole pixels like the renderer does.
|
||||
var startTransform := sprite.get_global_transform()
|
||||
startTransform.origin = startTransform.origin.round()
|
||||
var from := get_frame_pixels(sprite, sprite.frame, startTransform)
|
||||
var to := get_frame_pixels(sprite, endFrame, endTransform)
|
||||
var from := TubeSteer.without_outline(get_frame_pixels(sprite, sprite.frame, startTransform))
|
||||
var to := TubeSteer.without_outline(get_frame_pixels(sprite, endFrame, endTransform))
|
||||
if from.colors.is_empty() or to.colors.is_empty():
|
||||
isFinished = true
|
||||
return
|
||||
_pair_pixels(from, to, maxi(int(width), 1))
|
||||
_pair_pixels(from, to, maxi(int(width) - 2, 1))
|
||||
for spot in from.positions + to.positions:
|
||||
_footprint[Vector2i(spot.floor())] = true
|
||||
_rowSpacing = minf(ROW_SPACING, maxLength / _rowCount)
|
||||
|
||||
|
||||
|
|
@ -165,16 +173,24 @@ func _duration() -> float:
|
|||
func _draw() -> void:
|
||||
var tubeLength := _tube_length()
|
||||
var duration := _duration()
|
||||
# Work out where every pixel goes first, so the outline can go round them.
|
||||
var pixels := {} # Vector2i -> Color, for pixels in the tube or at their spot.
|
||||
var movingPixels := {} # The same, for pixels on their way.
|
||||
var inTube := {} # Vector2i -> true, for pixels in the tube.
|
||||
for i in _starts.size():
|
||||
var row := _rows[i]
|
||||
var enterTime := _enter_time(row)
|
||||
var exitTime := _exit_time(row)
|
||||
var spot: Vector2
|
||||
var color := _startColors[i]
|
||||
var settled := false
|
||||
if _time < enterTime:
|
||||
# Drawn in, speeding up towards the mouth.
|
||||
var progress := _time / enterTime
|
||||
spot = _starts[i].lerp(_point_on_path(0.0, _lanes[i]), progress * progress)
|
||||
if spot.distance_to(_starts[i]) <= SETTLED_DISTANCE:
|
||||
settled = true
|
||||
spot = _starts[i] # Held in place, so the sprite's shape stays crisp.
|
||||
elif _time < exitTime:
|
||||
spot = _point_on_path((_time - enterTime) * SPEED, _lanes[i])
|
||||
else:
|
||||
|
|
@ -183,7 +199,34 @@ func _draw() -> void:
|
|||
var eased := 1.0 - (1.0 - progress) * (1.0 - progress)
|
||||
spot = _point_on_path(tubeLength, _lanes[i]).lerp(_ends[i], eased)
|
||||
color = _startColors[i].lerp(_endColors[i], eased)
|
||||
draw_rect(Rect2(spot.floor(), Vector2.ONE), color)
|
||||
if spot.distance_to(_ends[i]) <= SETTLED_DISTANCE:
|
||||
settled = true
|
||||
spot = _ends[i]
|
||||
var at := Vector2i(spot.floor())
|
||||
if _time >= enterTime and _time < exitTime:
|
||||
pixels[at] = color
|
||||
inTube[at] = true
|
||||
elif settled:
|
||||
pixels[at] = color
|
||||
else:
|
||||
movingPixels[at] = color
|
||||
|
||||
# The outline: every empty pixel touching the settled pixels. At their spot,
|
||||
# corners count, like the slime's own outline. In the tube they don't, so
|
||||
# the stream's outline hugs it. Spots inside the sprite's shape that pixels
|
||||
# have left (or not reached yet) don't get one: they'd speckle it in black.
|
||||
var outlined := {}
|
||||
for at: Vector2i in pixels:
|
||||
for offset in (TubeSteer.NEIGHBORS_4 if inTube.has(at) else TubeSteer.NEIGHBORS_8):
|
||||
var spot: Vector2i = at + offset
|
||||
if pixels.has(spot) or outlined.has(spot) or _footprint.has(spot):
|
||||
continue
|
||||
outlined[spot] = true
|
||||
draw_rect(Rect2(Vector2(spot), Vector2.ONE), TubeSteer.OUTLINE_COLOR)
|
||||
for at: Vector2i in pixels:
|
||||
draw_rect(Rect2(Vector2(at), Vector2.ONE), pixels[at])
|
||||
for at: Vector2i in movingPixels:
|
||||
draw_rect(Rect2(Vector2(at), Vector2.ONE), movingPixels[at])
|
||||
|
||||
|
||||
# The point `distance` along the path, moved `lane` to the left of travel.
|
||||
|
|
|
|||
|
|
@ -148,8 +148,8 @@ func start(sprite: Sprite2D, layer: TileMapLayer, entryCell: Vector2i, entryDire
|
|||
add_child(_indicatorCanvas)
|
||||
|
||||
_laneCount = maxi(int(width) - 2, 1)
|
||||
var from := _without_outline(PixelStream.get_frame_pixels(sprite, sprite.frame, entryPose.get("startTransform", entryPose.spriteTransform)))
|
||||
_endFrame = _without_outline(PixelStream.get_frame_pixels(sprite, endFrame, Transform2D.IDENTITY))
|
||||
var from := without_outline(PixelStream.get_frame_pixels(sprite, sprite.frame, entryPose.get("startTransform", entryPose.spriteTransform)))
|
||||
_endFrame = without_outline(PixelStream.get_frame_pixels(sprite, endFrame, Transform2D.IDENTITY))
|
||||
if from.colors.is_empty() or _endFrame.colors.is_empty():
|
||||
exitPose = entryPose
|
||||
isFinished = true
|
||||
|
|
@ -241,8 +241,8 @@ func _process(delta: float) -> void:
|
|||
|
||||
# ---- Setup ----
|
||||
|
||||
# The frame's pixels without its dark outline and eyes.
|
||||
static func _without_outline(frame: Dictionary) -> Dictionary:
|
||||
# The frame's pixels without its dark outline and eyes. PixelStream uses this too.
|
||||
static func without_outline(frame: Dictionary) -> Dictionary:
|
||||
var positions := PackedVector2Array()
|
||||
var colors := PackedColorArray()
|
||||
for i in frame.colors.size():
|
||||
|
|
|
|||
Loading…
Reference in a new issue