Compare commits
3 commits
32d82b4bd1
...
e7c2ae657f
| Author | SHA1 | Date | |
|---|---|---|---|
| e7c2ae657f | |||
| 7be4eb9e90 | |||
| beeebbf47e |
12 changed files with 425 additions and 36 deletions
Binary file not shown.
|
Before Width: | Height: | Size: 2.1 KiB After Width: | Height: | Size: 2.3 KiB |
BIN
Assets/Sounds/Itty Bitty 8 Bit.mp3
Executable file
BIN
Assets/Sounds/Itty Bitty 8 Bit.mp3
Executable file
Binary file not shown.
19
Assets/Sounds/Itty Bitty 8 Bit.mp3.import
Executable file
19
Assets/Sounds/Itty Bitty 8 Bit.mp3.import
Executable file
|
|
@ -0,0 +1,19 @@
|
|||
[remap]
|
||||
|
||||
importer="mp3"
|
||||
type="AudioStreamMP3"
|
||||
uid="uid://bow6wew1jbbk1"
|
||||
path="res://.godot/imported/Itty Bitty 8 Bit.mp3-e6bb5a702130d6c2c504874feadda2f1.mp3str"
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://Assets/Sounds/Itty Bitty 8 Bit.mp3"
|
||||
dest_files=["res://.godot/imported/Itty Bitty 8 Bit.mp3-e6bb5a702130d6c2c504874feadda2f1.mp3str"]
|
||||
|
||||
[params]
|
||||
|
||||
loop=false
|
||||
loop_offset=0
|
||||
bpm=0
|
||||
beat_count=0
|
||||
bar_beats=4
|
||||
|
|
@ -66,6 +66,13 @@ const TUBE_ENTER_HOLD_TIME = 0.35 # How long to press into a mouth before we squ
|
|||
# within about 25 degrees). Diagonals don't count, so they can climb walls instead.
|
||||
const TUBE_ENTER_MIN_ALIGNMENT = 0.9
|
||||
const REST_FRAME = 0 # The Idle animation's frame. We reform as it.
|
||||
# The PressWall animation's frame: squashed against a wall on its left. Its flat
|
||||
# side is further from our center than our radius, so it's drawn this much away
|
||||
# from the wall to sit flush against it (see _align_press_wall_sprite). It shows
|
||||
# while pushing into a wall from the floor or the ceiling (upside down), or into
|
||||
# a tube mouth in one.
|
||||
const PRESS_WALL_FRAME = 9
|
||||
const PRESS_WALL_SPRITE_SHIFT = 6.0
|
||||
|
||||
###############
|
||||
## Variables ##
|
||||
|
|
@ -108,8 +115,14 @@ var isOnSurface := false
|
|||
var isCrawling := false # Moving along the surface we're on.
|
||||
var isHoldingAtEdge := false
|
||||
var isPressingIntoSurface := false
|
||||
var isPressingWall := false # On the floor or ceiling, pushing sideways into a wall or a tube mouth in one.
|
||||
# On the ceiling in a corner, the wall there (its normal's x), or 0. We stay on
|
||||
# the ceiling pushing into it; holding down moves us onto it.
|
||||
var ceilingWallNormalX := 0.0
|
||||
var spriteBasePosition := Vector2.ZERO # The Sprite2D's position as set in the scene.
|
||||
var isReachingAway := false # Holding away from the surface, counting towards letting go/hopping.
|
||||
var isSqueezingIntoTube := false # Holding into a tube's mouth, about to go in.
|
||||
var tubeSqueezeDirection := Vector2.ZERO # Which way into that mouth.
|
||||
|
||||
var isInTube := false
|
||||
var tubePixels: PixelStream # Our pixels streaming through an ordinary tube, or null.
|
||||
|
|
@ -122,6 +135,8 @@ var timeSpentSqueezingIntoTube := 0.0
|
|||
var tubeLayers: Array[TileMapLayer] = [] # TileMapLayers whose tiles can be tubes.
|
||||
var hasFoundTubeLayers := false
|
||||
|
||||
var carriedItem: CarryItem = null # The item riding in our center, or null. Tubes drop it.
|
||||
|
||||
###########
|
||||
## Nodes ##
|
||||
###########
|
||||
|
|
@ -161,6 +176,24 @@ func _ready() -> void:
|
|||
leftEdgeSensor.add_exception(self)
|
||||
rightEdgeSensor.add_exception(self)
|
||||
|
||||
spriteBasePosition = sprite.position
|
||||
animationTree.mixer_applied.connect(_align_press_wall_sprite)
|
||||
|
||||
# Shifts the PressWall frame away from the wall. Done here rather than with a
|
||||
# track in the animation because which way depends on flip_h, and keyed off the
|
||||
# frame shown so it can't get out of step with the animation.
|
||||
# It moves the sprite rather than its offset: the tube effects build the slime
|
||||
# they reform as from the sprite's offset, and that must not carry the shift.
|
||||
func _align_press_wall_sprite() -> void:
|
||||
var targetPosition := spriteBasePosition
|
||||
if sprite.frame == PRESS_WALL_FRAME:
|
||||
# Towards the frame's right (away from its wall), turned with the sprite.
|
||||
var awayFromWall := Vector2(-1.0 if sprite.flip_h else 1.0, 0.0).rotated(sprite.rotation).round()
|
||||
targetPosition += awayFromWall * PRESS_WALL_SPRITE_SHIFT
|
||||
if sprite.position != targetPosition:
|
||||
sprite.position = targetPosition
|
||||
sprite.reset_physics_interpolation() # A different pose, not movement.
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Note: Up is positive y.
|
||||
var moveInput := Vector2(Input.get_axis("moveLeft", "moveRight"), Input.get_axis("moveDown", "moveUp"))
|
||||
|
|
@ -194,6 +227,7 @@ func _physics_process(delta: float) -> void:
|
|||
_hold_at_edge(delta)
|
||||
|
||||
var wasOnWall := (isStickingToWall and not is_on_floor())
|
||||
var wasOnCeiling := isStickingToCeiling
|
||||
var velocityBeforeMove := velocity
|
||||
|
||||
move_and_slide()
|
||||
|
|
@ -206,13 +240,7 @@ func _physics_process(delta: float) -> void:
|
|||
return
|
||||
|
||||
_update_ceiling_sticking()
|
||||
|
||||
# In a corner, stick to the ceiling if pressing up, otherwise the wall.
|
||||
if isStickingToWall and isStickingToCeiling:
|
||||
if moveInput.y > 0:
|
||||
isStickingToWall = false
|
||||
else:
|
||||
isStickingToCeiling = false
|
||||
_pick_corner_surface(moveInput, wasOnCeiling)
|
||||
|
||||
var normal := _get_surface_normal()
|
||||
var landedOnSomething := wasInAir and normal != Vector2.ZERO
|
||||
|
|
@ -228,7 +256,13 @@ func _physics_process(delta: float) -> void:
|
|||
func _update_facing(moveInput: Vector2) -> void:
|
||||
if moveInput == Vector2.ZERO:
|
||||
return
|
||||
if isStickingToCeiling:
|
||||
var pressedWallDirection := _get_pressed_wall_direction(moveInput)
|
||||
if pressedWallDirection != Vector2.ZERO:
|
||||
# The PressWall frame has its wall on the left: flip it to face the way we
|
||||
# press, however the sprite is turned for the surface we're on.
|
||||
var frameLeft := Vector2.LEFT.rotated(_rotation_for(_get_surface_normal()))
|
||||
sprite.flip_h = frameLeft.dot(pressedWallDirection) < 0
|
||||
elif isStickingToCeiling:
|
||||
sprite.flip_h = moveInput.x > 0 # Upside down, so flipped the other way.
|
||||
elif isStickingToWall:
|
||||
if wallNormalX < 0: sprite.flip_h = moveInput.y < 0
|
||||
|
|
@ -240,10 +274,11 @@ func _update_facing(moveInput: Vector2) -> void:
|
|||
# transitions' advance expressions in player.tscn).
|
||||
func _update_animation_conditions(moveInput: Vector2) -> void:
|
||||
isOnSurface = _get_surface_normal() != Vector2.ZERO
|
||||
isPressingWall = _get_pressed_wall_direction(moveInput) != Vector2.ZERO
|
||||
isCrawling = ((moveInput.x != 0.0 and (isStickingToCeiling or is_on_floor()))
|
||||
or (moveInput.y != 0.0 and isStickingToWall)) and not isSqueezingIntoTube
|
||||
or (moveInput.y != 0.0 and isStickingToWall)) and not isSqueezingIntoTube and not isPressingWall
|
||||
isHoldingAtEdge = timeSpentHoldingEdge > 0
|
||||
isPressingIntoSurface = _is_pressing_into_surface(moveInput) or isSqueezingIntoTube
|
||||
isPressingIntoSurface = (_is_pressing_into_surface(moveInput) or isSqueezingIntoTube) and not isPressingWall
|
||||
isReachingAway = ((is_on_floor() and timeSpentHoldingUpOnFloor > 0)
|
||||
or (isStickingToCeiling and timeSpentUnstickingCeiling > 0)
|
||||
or (isStickingToWall and timeSpentUnstickingWall > 0))
|
||||
|
|
@ -335,6 +370,33 @@ func _update_wall_sticking(wasOnWall: bool) -> void:
|
|||
if isStickingToWall:
|
||||
wallNormalX = get_wall_normal().x
|
||||
|
||||
# In a ceiling corner: holding up takes the ceiling and holding down the wall.
|
||||
# Otherwise we stay on the one we were on, so crawling along the ceiling into a
|
||||
# wall leaves us pressed against it (the PressWall pose), and climbing a wall
|
||||
# into the corner leaves us on the wall.
|
||||
func _pick_corner_surface(moveInput: Vector2, wasOnCeiling: bool) -> void:
|
||||
ceilingWallNormalX = 0.0
|
||||
# A down still held from steering out of a tube in the ceiling doesn't count
|
||||
# (see ignoreCeilingUnstickUntilRelease): we stay where the tube put us.
|
||||
var holdingDown := moveInput.y < 0 and not ignoreCeilingUnstickUntilRelease
|
||||
# Physics only reports a wall while we move into it, so holding straight down
|
||||
# beside one needs a look.
|
||||
if isStickingToCeiling and not isStickingToWall and holdingDown:
|
||||
var side := _get_touching_wall_side()
|
||||
if side != 0.0:
|
||||
isStickingToWall = true
|
||||
wallNormalX = -side
|
||||
if not (isStickingToWall and isStickingToCeiling):
|
||||
return
|
||||
if holdingDown:
|
||||
isStickingToCeiling = false
|
||||
timeSpentUnstickingCeiling = 0.0
|
||||
elif moveInput.y > 0 or wasOnCeiling:
|
||||
isStickingToWall = false
|
||||
ceilingWallNormalX = wallNormalX
|
||||
else:
|
||||
isStickingToCeiling = false
|
||||
|
||||
func _update_ceiling_sticking() -> void:
|
||||
var wasOnCeiling := isStickingToCeiling
|
||||
var driftedBackOn := false
|
||||
|
|
@ -409,6 +471,33 @@ func _is_pressing_into_surface(moveInput: Vector2) -> bool:
|
|||
var inputDir := Vector2(moveInput.x, -moveInput.y)
|
||||
return absf(inputDir.angle_to(-normal)) < deg_to_rad(2)
|
||||
|
||||
# Which way the surface we're pushing into is, when it's square to the one we're
|
||||
# on (the PressWall pose), or Vector2.ZERO:
|
||||
# - From the floor or ceiling, a wall, or a tube mouth in one. Holding up into a
|
||||
# wall from the floor climbs it instead.
|
||||
# - From a wall, a tube mouth in the floor or ceiling.
|
||||
func _get_pressed_wall_direction(moveInput: Vector2) -> Vector2:
|
||||
if isSqueezingIntoTube:
|
||||
# Not into a mouth in the surface we're on: that's the Crouch pose.
|
||||
var isSquare := absf(tubeSqueezeDirection.dot(_get_surface_normal())) < 0.5
|
||||
return tubeSqueezeDirection if isSquare else Vector2.ZERO
|
||||
if isStickingToCeiling:
|
||||
# Holding down into it moves us onto the wall instead (see _pick_corner_surface).
|
||||
if moveInput.x * ceilingWallNormalX < 0 and moveInput.y >= 0.0:
|
||||
return Vector2(-ceilingWallNormalX, 0.0)
|
||||
return Vector2.ZERO
|
||||
if is_on_floor() and isStickingToWall and moveInput.x * wallNormalX < 0 and moveInput.y <= 0.0:
|
||||
return Vector2(-wallNormalX, 0.0)
|
||||
return Vector2.ZERO
|
||||
|
||||
# Which side a wall is right up against us (1 right, -1 left), or 0.
|
||||
func _get_touching_wall_side() -> float:
|
||||
var collision := KinematicCollision2D.new()
|
||||
for side: float in [1.0, -1.0]:
|
||||
if test_move(global_transform, Vector2(side, 0), collision) and absf(collision.get_normal().x) > 0.7:
|
||||
return side
|
||||
return 0.0
|
||||
|
||||
func _get_facing() -> Vector2:
|
||||
if is_on_floor():
|
||||
if sprite.flip_h:
|
||||
|
|
@ -717,8 +806,9 @@ func _settle_onto_surface(normal: Vector2, gap: float, delta: float) -> void:
|
|||
func _update_tube_squeeze(delta: float, moveInput: Vector2) -> bool:
|
||||
var tube := {}
|
||||
if tubeReentryCooldown <= 0.0 and _get_surface_normal() != Vector2.ZERO:
|
||||
tube = _find_tube(moveInput)
|
||||
tube = _find_tube(moveInput, velocity * delta)
|
||||
isSqueezingIntoTube = not tube.is_empty()
|
||||
tubeSqueezeDirection = tube.direction if isSqueezingIntoTube else Vector2.ZERO
|
||||
if not isSqueezingIntoTube:
|
||||
timeSpentSqueezingIntoTube = 0.0
|
||||
return false
|
||||
|
|
@ -730,6 +820,11 @@ func _update_tube_squeeze(delta: float, moveInput: Vector2) -> bool:
|
|||
_enter_tube(tube)
|
||||
return true
|
||||
|
||||
# The mouth counts from a little way off (see _find_tube_towards), so close
|
||||
# any gap: hold still pressed right up against it, wherever we were when we
|
||||
# arrived. move_and_collide() leaves is_on_floor() and friends alone, so
|
||||
# climbing down a wall to a mouth in the floor leaves us on the wall.
|
||||
move_and_collide(tube.direction * (TUBE_ENTRY_REACH + maxf(velocity.dot(tube.direction) * delta, 0.0)))
|
||||
velocity = Vector2.ZERO
|
||||
_update_facing(moveInput)
|
||||
_update_animation_conditions(moveInput)
|
||||
|
|
@ -743,21 +838,24 @@ func _update_tube_squeeze(delta: float, moveInput: Vector2) -> bool:
|
|||
# mouth in it, up and towards the wall climbs the wall.
|
||||
# Ordinary tubes must lead somewhere we fit. Manual ones needn't: we can always
|
||||
# back out.
|
||||
func _find_tube(moveInput: Vector2) -> Dictionary:
|
||||
# `step`: how far we're about to move. Mouths that far ahead count too, so we
|
||||
# can't step straight past one: climbing down a wall onto the floor beside a
|
||||
# mouth in it, say, instead of squeezing in from the wall.
|
||||
func _find_tube(moveInput: Vector2, step := Vector2.ZERO) -> Dictionary:
|
||||
if moveInput == Vector2.ZERO:
|
||||
return {}
|
||||
var inputDirection := Vector2(moveInput.x, -moveInput.y).normalized() # Up is negative y.
|
||||
for direction: Vector2 in [Vector2.UP, Vector2.RIGHT, Vector2.DOWN, Vector2.LEFT]:
|
||||
if inputDirection.dot(direction) < TUBE_ENTER_MIN_ALIGNMENT:
|
||||
continue
|
||||
return _find_tube_towards(direction)
|
||||
return _find_tube_towards(direction, maxf(step.dot(direction), 0.0))
|
||||
return {}
|
||||
|
||||
|
||||
func _find_tube_towards(direction: Vector2) -> Dictionary:
|
||||
func _find_tube_towards(direction: Vector2, extraReach := 0.0) -> Dictionary:
|
||||
var radius := _get_radius()
|
||||
var across := direction.orthogonal()
|
||||
var reach := radius + TUBE_ENTRY_REACH
|
||||
var reach := radius + TUBE_ENTRY_REACH + extraReach
|
||||
for layer in _get_tube_layers():
|
||||
# Check the tile ahead of our middle and of each side, in case we're
|
||||
# between two rows of tiles.
|
||||
|
|
@ -836,6 +934,11 @@ func _tube_exit_pose(mouth: Vector2, outward: Vector2) -> Dictionary:
|
|||
|
||||
# Turns us into pixels in the tube _find_tube gave us.
|
||||
func _enter_tube(tube: Dictionary) -> void:
|
||||
# Items don't fit through tubes: leave it at the mouth.
|
||||
if carriedItem != null:
|
||||
carriedItem.drop()
|
||||
carriedItem = null
|
||||
|
||||
if tube.has("path"):
|
||||
tubeExitPose = _tube_exit_pose_for(tube.path)
|
||||
tubePixels = PixelStream.new()
|
||||
|
|
@ -847,6 +950,14 @@ func _enter_tube(tube: Dictionary) -> void:
|
|||
spriteTransform.origin = spriteTransform.origin.round() # Snapped like the renderer does.
|
||||
var entryPose := {spriteTransform = spriteTransform, normal = _get_surface_normal(),
|
||||
appearAt = global_position}
|
||||
# Except into a mouth in a wall from the floor or ceiling: we come back out
|
||||
# onto the wall, like out of any other mouth, not on the floor or ceiling.
|
||||
if tube.direction.x != 0.0 and _get_surface_normal().x == 0.0:
|
||||
var mouth := _tube_cell_point(tube.layer, tube.cell, -tube.direction)
|
||||
var wallPose := _tube_exit_pose(mouth, -tube.direction)
|
||||
if not wallPose.is_empty():
|
||||
wallPose.startTransform = spriteTransform # The goo still starts as we look now.
|
||||
entryPose = wallPose
|
||||
if TubeGoo.is_goo(tube.layer, tube.cell):
|
||||
tubeSteer = TubeGoo.new()
|
||||
else:
|
||||
|
|
@ -905,6 +1016,7 @@ func _exit_tube(pose: Dictionary, delta: float) -> void:
|
|||
# Show the frame our pixels just made, and let the AnimationTree carry on from
|
||||
# there. Without start() it would still be in whatever state we went in with.
|
||||
sprite.frame = REST_FRAME
|
||||
_align_press_wall_sprite() # Un-shift now, in case we went in pressing a wall.
|
||||
_update_animation_conditions(Vector2.ZERO)
|
||||
var playback: AnimationNodeStateMachinePlayback = animationTree.get("parameters/playback")
|
||||
playback.start(&"Idle")
|
||||
|
|
@ -943,6 +1055,22 @@ func _tube_cell_point(layer: TileMapLayer, cell: Vector2i, side: Vector2) -> Vec
|
|||
var halfTile := Vector2(layer.tile_set.tile_size) / 2.0
|
||||
return layer.to_global(layer.map_to_local(cell) + side * halfTile)
|
||||
|
||||
# ---- Items ----
|
||||
|
||||
# A CarryItem we touched asks to be carried. Returns whether we took it.
|
||||
func pick_up_item(item: CarryItem) -> bool:
|
||||
if carriedItem != null or isInTube:
|
||||
return false
|
||||
# Just out of a tube, physics still has our shape back where we went in for a
|
||||
# frame, so it can report us touching an item we left there. Check it's really
|
||||
# within reach of where we are.
|
||||
var reach := _get_radius() + item.PICKUP_SIZE.length() / 2.0
|
||||
if global_position.distance_to(item.global_position) > reach:
|
||||
return false
|
||||
carriedItem = item
|
||||
item.attach_to(self)
|
||||
return true
|
||||
|
||||
# ---- Effects ----
|
||||
|
||||
func _splat(normal: Vector2) -> void:
|
||||
|
|
|
|||
|
|
@ -127,12 +127,30 @@ tracks/0/keys = {
|
|||
"values": [4, 5]
|
||||
}
|
||||
|
||||
[sub_resource type="Animation" id="Animation_PressWall"]
|
||||
resource_name = "PressWall"
|
||||
length = 0.2
|
||||
loop_mode = 1
|
||||
tracks/0/type = "value"
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/path = NodePath("Sprite2D:frame")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/keys = {
|
||||
"times": PackedFloat32Array(0),
|
||||
"transitions": PackedFloat32Array(1),
|
||||
"update": 1,
|
||||
"values": [9]
|
||||
}
|
||||
|
||||
[sub_resource type="AnimationLibrary" id="AnimationLibrary_slime"]
|
||||
_data = {
|
||||
&"Crouch": SubResource("Animation_Crouch"),
|
||||
&"Idle": SubResource("Animation_Idle"),
|
||||
&"InAir": SubResource("Animation_InAir"),
|
||||
&"Moving": SubResource("Animation_Moving"),
|
||||
&"PressWall": SubResource("Animation_PressWall"),
|
||||
&"RESET": SubResource("Animation_4m0gv"),
|
||||
&"ReachX": SubResource("Animation_ReachX"),
|
||||
&"ReachY": SubResource("Animation_ReachY")
|
||||
|
|
@ -150,6 +168,9 @@ animation = &"InAir"
|
|||
[sub_resource type="AnimationNodeAnimation" id="AnimNode_Moving"]
|
||||
animation = &"Moving"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimNode_PressWall"]
|
||||
animation = &"PressWall"
|
||||
|
||||
[sub_resource type="AnimationNodeAnimation" id="AnimNode_ReachX"]
|
||||
animation = &"ReachX"
|
||||
|
||||
|
|
@ -181,7 +202,7 @@ advance_expression = "isPressingIntoSurface and not isCrawling and not isHolding
|
|||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_Moving_Idle"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway)"
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway or isPressingWall)"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_Moving_InAir"]
|
||||
advance_mode = 2
|
||||
|
|
@ -201,7 +222,7 @@ advance_expression = "isPressingIntoSurface and not isCrawling and not isHolding
|
|||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_InAir_Idle"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway)"
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway or isPressingWall)"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_InAir_Moving"]
|
||||
advance_mode = 2
|
||||
|
|
@ -221,7 +242,7 @@ advance_expression = "isPressingIntoSurface and not isCrawling and not isHolding
|
|||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_ReachX_Idle"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway)"
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway or isPressingWall)"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_ReachX_Moving"]
|
||||
advance_mode = 2
|
||||
|
|
@ -241,7 +262,7 @@ advance_expression = "isPressingIntoSurface and not isCrawling and not isHolding
|
|||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_ReachY_Idle"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway)"
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway or isPressingWall)"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_ReachY_Moving"]
|
||||
advance_mode = 2
|
||||
|
|
@ -261,7 +282,7 @@ advance_expression = "isPressingIntoSurface and not isCrawling and not isHolding
|
|||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_Crouch_Idle"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway)"
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway or isPressingWall)"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_Crouch_Moving"]
|
||||
advance_mode = 2
|
||||
|
|
@ -279,6 +300,54 @@ advance_expression = "isOnSurface and isHoldingAtEdge"
|
|||
advance_mode = 2
|
||||
advance_expression = "isReachingAway and not isCrawling and not isHoldingAtEdge and not isPressingIntoSurface"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_Idle_PressWall"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isPressingWall"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_Moving_PressWall"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isPressingWall"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_InAir_PressWall"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isPressingWall"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_ReachX_PressWall"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isPressingWall"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_ReachY_PressWall"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isPressingWall"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_Crouch_PressWall"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isPressingWall"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_PressWall_Idle"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isOnSurface and not (isCrawling or isHoldingAtEdge or isPressingIntoSurface or isReachingAway or isPressingWall)"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_PressWall_Moving"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isCrawling and not isHoldingAtEdge"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_PressWall_InAir"]
|
||||
advance_mode = 2
|
||||
advance_expression = "not isOnSurface"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_PressWall_ReachX"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isOnSurface and isHoldingAtEdge"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_PressWall_ReachY"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isReachingAway and not isCrawling and not isHoldingAtEdge and not isPressingIntoSurface"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachineTransition" id="Transition_PressWall_Crouch"]
|
||||
advance_mode = 2
|
||||
advance_expression = "isPressingIntoSurface and not isCrawling and not isHoldingAtEdge"
|
||||
|
||||
[sub_resource type="AnimationNodeStateMachine" id="AnimationNodeStateMachine_slime"]
|
||||
states/Crouch/node = SubResource("AnimNode_Crouch")
|
||||
states/Crouch/position = Vector2(150, 300)
|
||||
|
|
@ -288,12 +357,14 @@ states/InAir/node = SubResource("AnimNode_InAir")
|
|||
states/InAir/position = Vector2(400, -100)
|
||||
states/Moving/node = SubResource("AnimNode_Moving")
|
||||
states/Moving/position = Vector2(650, 100)
|
||||
states/PressWall/node = SubResource("AnimNode_PressWall")
|
||||
states/PressWall/position = Vector2(900, 100)
|
||||
states/ReachX/node = SubResource("AnimNode_ReachX")
|
||||
states/ReachX/position = Vector2(650, 300)
|
||||
states/ReachY/node = SubResource("AnimNode_ReachY")
|
||||
states/ReachY/position = Vector2(400, 300)
|
||||
states/Start/position = Vector2(150, 100)
|
||||
transitions = ["Start", "Idle", SubResource("Transition_Start"), "Idle", "Moving", SubResource("Transition_Idle_Moving"), "Idle", "InAir", SubResource("Transition_Idle_InAir"), "Idle", "ReachX", SubResource("Transition_Idle_ReachX"), "Idle", "ReachY", SubResource("Transition_Idle_ReachY"), "Idle", "Crouch", SubResource("Transition_Idle_Crouch"), "Moving", "Idle", SubResource("Transition_Moving_Idle"), "Moving", "InAir", SubResource("Transition_Moving_InAir"), "Moving", "ReachX", SubResource("Transition_Moving_ReachX"), "Moving", "ReachY", SubResource("Transition_Moving_ReachY"), "Moving", "Crouch", SubResource("Transition_Moving_Crouch"), "InAir", "Idle", SubResource("Transition_InAir_Idle"), "InAir", "Moving", SubResource("Transition_InAir_Moving"), "InAir", "ReachX", SubResource("Transition_InAir_ReachX"), "InAir", "ReachY", SubResource("Transition_InAir_ReachY"), "InAir", "Crouch", SubResource("Transition_InAir_Crouch"), "ReachX", "Idle", SubResource("Transition_ReachX_Idle"), "ReachX", "Moving", SubResource("Transition_ReachX_Moving"), "ReachX", "InAir", SubResource("Transition_ReachX_InAir"), "ReachX", "ReachY", SubResource("Transition_ReachX_ReachY"), "ReachX", "Crouch", SubResource("Transition_ReachX_Crouch"), "ReachY", "Idle", SubResource("Transition_ReachY_Idle"), "ReachY", "Moving", SubResource("Transition_ReachY_Moving"), "ReachY", "InAir", SubResource("Transition_ReachY_InAir"), "ReachY", "ReachX", SubResource("Transition_ReachY_ReachX"), "ReachY", "Crouch", SubResource("Transition_ReachY_Crouch"), "Crouch", "Idle", SubResource("Transition_Crouch_Idle"), "Crouch", "Moving", SubResource("Transition_Crouch_Moving"), "Crouch", "InAir", SubResource("Transition_Crouch_InAir"), "Crouch", "ReachX", SubResource("Transition_Crouch_ReachX"), "Crouch", "ReachY", SubResource("Transition_Crouch_ReachY")]
|
||||
transitions = ["Start", "Idle", SubResource("Transition_Start"), "Idle", "Moving", SubResource("Transition_Idle_Moving"), "Idle", "InAir", SubResource("Transition_Idle_InAir"), "Idle", "ReachX", SubResource("Transition_Idle_ReachX"), "Idle", "ReachY", SubResource("Transition_Idle_ReachY"), "Idle", "Crouch", SubResource("Transition_Idle_Crouch"), "Moving", "Idle", SubResource("Transition_Moving_Idle"), "Moving", "InAir", SubResource("Transition_Moving_InAir"), "Moving", "ReachX", SubResource("Transition_Moving_ReachX"), "Moving", "ReachY", SubResource("Transition_Moving_ReachY"), "Moving", "Crouch", SubResource("Transition_Moving_Crouch"), "InAir", "Idle", SubResource("Transition_InAir_Idle"), "InAir", "Moving", SubResource("Transition_InAir_Moving"), "InAir", "ReachX", SubResource("Transition_InAir_ReachX"), "InAir", "ReachY", SubResource("Transition_InAir_ReachY"), "InAir", "Crouch", SubResource("Transition_InAir_Crouch"), "ReachX", "Idle", SubResource("Transition_ReachX_Idle"), "ReachX", "Moving", SubResource("Transition_ReachX_Moving"), "ReachX", "InAir", SubResource("Transition_ReachX_InAir"), "ReachX", "ReachY", SubResource("Transition_ReachX_ReachY"), "ReachX", "Crouch", SubResource("Transition_ReachX_Crouch"), "ReachY", "Idle", SubResource("Transition_ReachY_Idle"), "ReachY", "Moving", SubResource("Transition_ReachY_Moving"), "ReachY", "InAir", SubResource("Transition_ReachY_InAir"), "ReachY", "ReachX", SubResource("Transition_ReachY_ReachX"), "ReachY", "Crouch", SubResource("Transition_ReachY_Crouch"), "Crouch", "Idle", SubResource("Transition_Crouch_Idle"), "Crouch", "Moving", SubResource("Transition_Crouch_Moving"), "Crouch", "InAir", SubResource("Transition_Crouch_InAir"), "Crouch", "ReachX", SubResource("Transition_Crouch_ReachX"), "Crouch", "ReachY", SubResource("Transition_Crouch_ReachY"), "Idle", "PressWall", SubResource("Transition_Idle_PressWall"), "Moving", "PressWall", SubResource("Transition_Moving_PressWall"), "InAir", "PressWall", SubResource("Transition_InAir_PressWall"), "ReachX", "PressWall", SubResource("Transition_ReachX_PressWall"), "ReachY", "PressWall", SubResource("Transition_ReachY_PressWall"), "Crouch", "PressWall", SubResource("Transition_Crouch_PressWall"), "PressWall", "Idle", SubResource("Transition_PressWall_Idle"), "PressWall", "Moving", SubResource("Transition_PressWall_Moving"), "PressWall", "InAir", SubResource("Transition_PressWall_InAir"), "PressWall", "ReachX", SubResource("Transition_PressWall_ReachX"), "PressWall", "ReachY", SubResource("Transition_PressWall_ReachY"), "PressWall", "Crouch", SubResource("Transition_PressWall_Crouch")]
|
||||
graph_offset = Vector2(0, -150)
|
||||
|
||||
[node name="Player" type="CharacterBody2D" unique_id=150873177]
|
||||
|
|
@ -303,7 +374,7 @@ landSounds = Array[AudioStream]([ExtResource("3_land1"), ExtResource("4_land2"),
|
|||
[node name="Sprite2D" type="Sprite2D" parent="." unique_id=402647784]
|
||||
texture = ExtResource("5_4m0gv")
|
||||
offset = Vector2(0, -6)
|
||||
hframes = 9
|
||||
hframes = 10
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1379572123]
|
||||
shape = SubResource("CircleShape2D_eovys")
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ extends Node2D
|
|||
# they land on, so the sprite reforms exactly.
|
||||
# Watch isFinished to know when every pixel is back in place.
|
||||
|
||||
# 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
|
||||
# channel. Goo going in or out of a mouth is hidden where it overlaps the tile.
|
||||
# A background must go lower than this, or on its own CanvasLayer.
|
||||
const GOO_Z_INDEX = -1
|
||||
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.
|
||||
|
|
@ -41,7 +46,7 @@ func start(sprite: Sprite2D, path: PackedVector2Array, width: float, maxLength:
|
|||
endTransform: Transform2D, endFrame: int) -> void:
|
||||
top_level = true
|
||||
global_position = Vector2.ZERO
|
||||
z_index = sprite.z_index + 1
|
||||
z_index = GOO_Z_INDEX
|
||||
|
||||
_path = path
|
||||
_pathDistances.append(0.0)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,8 @@ var _endFrame := {} # The frame we reform as, in the sprite's space.
|
|||
|
||||
# Squeezes into the tube at `entryCell` heading `entryDirection`.
|
||||
# Poses are {spriteTransform: Transform2D, ...plus whatever the caller wants
|
||||
# back in exitPose}. entryPose is the slime as it is now. findPose(mouth:
|
||||
# back in exitPose}. entryPose is the slime as it is now (or, if it has a
|
||||
# .startTransform, that's the slime as it is now and the rest is where backing out puts us). findPose(mouth:
|
||||
# Vector2, outward: Vector2) gives the pose for coming out of a mouth, or {} if
|
||||
# there's no room. endFrame: the frame we reform as. maxLength: the longest the
|
||||
# goo can be.
|
||||
|
|
@ -92,10 +93,10 @@ func start(sprite: Sprite2D, layer: TileMapLayer, entryCell: Vector2i, entryDire
|
|||
width: float, maxLength: float, entryPose: Dictionary, findPose: Callable, endFrame: int) -> void:
|
||||
top_level = true
|
||||
global_position = Vector2.ZERO
|
||||
z_index = sprite.z_index + 1
|
||||
z_index = PixelStream.GOO_Z_INDEX
|
||||
|
||||
_laneCount = maxi(int(width), 1)
|
||||
var from := PixelStream.get_frame_pixels(sprite, sprite.frame, entryPose.spriteTransform)
|
||||
var from := PixelStream.get_frame_pixels(sprite, sprite.frame, entryPose.get("startTransform", entryPose.spriteTransform))
|
||||
_endFrame = PixelStream.get_frame_pixels(sprite, endFrame, Transform2D.IDENTITY)
|
||||
if from.colors.is_empty() or _endFrame.colors.is_empty():
|
||||
exitPose = entryPose
|
||||
|
|
|
|||
|
|
@ -64,6 +64,10 @@ const INDICATOR_PULSE_SPEED = 2.5 # Radians per second (a pulse every 2.5s or so
|
|||
const INDICATOR_MIN_OPACITY = 0.4
|
||||
const INDICATOR_MAX_OPACITY = 0.6
|
||||
const INDICATOR_MAX_LIGHTEN = 0.2
|
||||
# The circle is hidden while the goo is going in or pouring out. It grows in
|
||||
# once the goo is all in, and shrinks away quickly when it starts to pour out.
|
||||
const INDICATOR_APPEAR_TIME = 0.25 # Seconds.
|
||||
const INDICATOR_DISAPPEAR_TIME = 0.1 # Seconds.
|
||||
|
||||
const DIRECTIONS: Array[Vector2i] = [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT]
|
||||
const NEIGHBORS_4: Array[Vector2i] = [Vector2i.UP, Vector2i.RIGHT, Vector2i.DOWN, Vector2i.LEFT]
|
||||
|
|
@ -105,6 +109,12 @@ var _isPouring := false # Once we're leaving: the leader carries on out by itsel
|
|||
var _stickOut := 0
|
||||
var _moveOwed := 0.0 # Time we're owed moving but haven't used, in seconds.
|
||||
var _time := 0.0
|
||||
var _indicatorShown := 0.0 # How far the circle has grown in, from 0 (hidden) to 1.
|
||||
# The circle is drawn on this, in front of the tiles: it's wider than the
|
||||
# tube's see-through channel, and the goo is behind them (see PixelStream.GOO_Z_INDEX).
|
||||
var _indicatorCanvas: Node2D
|
||||
var _indicatorCentre := Vector2.ZERO
|
||||
var _hasIndicator := false # Whether _draw found the leader for the circle.
|
||||
|
||||
# The pixels: row r holds pixels r * _pixelsPerRow up to the next row's, going
|
||||
# across its _laneCount lanes and round again.
|
||||
|
|
@ -120,7 +130,8 @@ var _endFrame := {} # The frame we reform as (no outline), in the sprite's space
|
|||
|
||||
# Squeezes into the tube at `entryCell` heading `entryDirection`.
|
||||
# Poses are {spriteTransform: Transform2D, ...plus whatever the caller wants
|
||||
# back in exitPose}. entryPose is the slime as it is now: backing out reforms us
|
||||
# back in exitPose}. entryPose is the slime as it is now (or, if it has a
|
||||
# .startTransform, that's the slime as it is now and the rest is where backing out puts us): backing out reforms us
|
||||
# there. findPose(mouth: Vector2, outward: Vector2) gives the pose for coming
|
||||
# out of a mouth, or {} if there's no room. endFrame: the frame we reform as.
|
||||
# width: the tube's channel. The goo is narrower, to leave room for its outline.
|
||||
|
|
@ -129,10 +140,15 @@ func start(sprite: Sprite2D, layer: TileMapLayer, entryCell: Vector2i, entryDire
|
|||
width: float, maxLength: float, entryPose: Dictionary, findPose: Callable, endFrame: int) -> void:
|
||||
top_level = true
|
||||
global_position = Vector2.ZERO
|
||||
z_index = sprite.z_index + 1
|
||||
z_index = PixelStream.GOO_Z_INDEX
|
||||
_indicatorCanvas = Node2D.new()
|
||||
_indicatorCanvas.z_as_relative = false
|
||||
_indicatorCanvas.z_index = sprite.z_index + 1
|
||||
_indicatorCanvas.draw.connect(_draw_indicator)
|
||||
add_child(_indicatorCanvas)
|
||||
|
||||
_laneCount = maxi(int(width) - 2, 1)
|
||||
var from := _without_outline(PixelStream.get_frame_pixels(sprite, sprite.frame, entryPose.spriteTransform))
|
||||
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
|
||||
|
|
@ -214,7 +230,13 @@ func steer(input: Vector2, delta: float) -> void:
|
|||
|
||||
func _process(delta: float) -> void:
|
||||
_time += delta
|
||||
if _isTakingIn or _isPouring:
|
||||
_indicatorShown = maxf(_indicatorShown - delta / INDICATOR_DISAPPEAR_TIME, 0.0)
|
||||
else:
|
||||
_indicatorShown = minf(_indicatorShown + delta / INDICATOR_APPEAR_TIME, 1.0)
|
||||
queue_redraw()
|
||||
if _indicatorCanvas:
|
||||
_indicatorCanvas.queue_redraw() # After ours: _draw finds where the circle goes.
|
||||
|
||||
|
||||
# ---- Setup ----
|
||||
|
|
@ -647,6 +669,7 @@ static func _sorted_by_distance(points: PackedVector2Array, target: Vector2) ->
|
|||
# ---- Drawing ----
|
||||
|
||||
func _draw() -> void:
|
||||
_hasIndicator = false
|
||||
if _leader == -1:
|
||||
return
|
||||
# Work out where every pixel goes first, so the outline can go round them.
|
||||
|
|
@ -704,21 +727,29 @@ func _draw() -> void:
|
|||
for at: Vector2i in movingPixels:
|
||||
draw_rect(Rect2(Vector2(at), Vector2.ONE), movingPixels[at])
|
||||
|
||||
if leaderPixelCount > 0:
|
||||
_draw_indicator(leaderCentre / leaderPixelCount)
|
||||
_hasIndicator = leaderPixelCount > 0 and _indicatorShown > 0.0
|
||||
if _hasIndicator:
|
||||
_indicatorCentre = leaderCentre / leaderPixelCount
|
||||
|
||||
|
||||
# The circle marking the leader, pulsing its opacity and brightness slowly.
|
||||
func _draw_indicator(centre: Vector2) -> void:
|
||||
# While it's appearing or disappearing, it's smaller and fainter. Drawn onto
|
||||
# _indicatorCanvas.
|
||||
func _draw_indicator() -> void:
|
||||
if not _hasIndicator:
|
||||
return
|
||||
var centre := _indicatorCentre
|
||||
var wave := 0.5 + 0.5 * sin(_time * INDICATOR_PULSE_SPEED)
|
||||
var opacity := lerpf(INDICATOR_MIN_OPACITY, INDICATOR_MAX_OPACITY, wave)
|
||||
var shown := ease(_indicatorShown, 0.5) # Quick to start growing, settling gently.
|
||||
var opacity := lerpf(INDICATOR_MIN_OPACITY, INDICATOR_MAX_OPACITY, wave) * shown
|
||||
var lighten := INDICATOR_MAX_LIGHTEN * wave
|
||||
var fill := indicatorColor.lightened(lighten)
|
||||
fill.a *= opacity
|
||||
var border := indicatorBorderColor.lightened(lighten)
|
||||
border.a *= opacity
|
||||
draw_circle(centre, indicatorRadius, fill)
|
||||
draw_circle(centre, indicatorRadius, border, false, 1.0)
|
||||
var radius := indicatorRadius * shown
|
||||
_indicatorCanvas.draw_circle(centre, radius, fill)
|
||||
_indicatorCanvas.draw_circle(centre, radius, border, false, 1.0)
|
||||
|
||||
|
||||
# Which way a row's lanes spread at `vertex`: across the tube there.
|
||||
|
|
|
|||
106
Items/carry_item.gd
Normal file
106
Items/carry_item.gd
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
class_name CarryItem
|
||||
extends CharacterBody2D
|
||||
|
||||
# Something the slime can carry inside its body. Touch it to pick it up; it rides
|
||||
# in the slime's center until the slime goes into a tube, which drops it.
|
||||
# On its own it just falls and slides to a stop.
|
||||
#
|
||||
# It's on no collision layer, so it never blocks the slime or its raycasts, but
|
||||
# it collides with the world (mask) like the slime does.
|
||||
#
|
||||
# It's always drawn in front of the slime, and of its goo in a tube. While
|
||||
# carried it's see-through, so it looks like it's inside the slime. Left behind,
|
||||
# it fades back to solid. (Behind the goo, bits of it would flicker through the
|
||||
# moving goo pixels as the slime poured into the tube.)
|
||||
|
||||
const MAX_FALL_SPEED = 400.0
|
||||
const GROUND_FRICTION = 600.0
|
||||
# After being dropped, how long before it can be picked up again. Stops a slime
|
||||
# backing straight out of a tube's mouth from grabbing it on the same frame.
|
||||
const PICKUP_COOLDOWN = 0.3
|
||||
# How big the touch zone is: a little bigger than the item, so brushing it counts.
|
||||
const PICKUP_SIZE = Vector2(14, 14)
|
||||
const DRAW_ORDER = 2 # z_index. The slime's sprite is 0 and tube goo is 1.
|
||||
|
||||
@export_range(0.0, 1.0, 0.05) var carriedOpacity := 0.5
|
||||
@export_range(0.0, 1.0, 0.05) var fadeTime := 0.15 # Seconds to fade between solid and see-through.
|
||||
|
||||
var carrier: Node2D = null # The slime carrying us, or null.
|
||||
var pickupCooldown := 0.0
|
||||
var pickupShape := RectangleShape2D.new()
|
||||
var fadeTween: Tween
|
||||
|
||||
@onready var collisionShape: CollisionShape2D = $CollisionShape2D
|
||||
@onready var sprite: Sprite2D = $Sprite2D
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
# Run after the slime has moved, so we sit in its center on the same frame
|
||||
# rather than one frame behind.
|
||||
process_physics_priority = 10
|
||||
pickupShape.size = PICKUP_SIZE
|
||||
z_index = DRAW_ORDER
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
if carrier != null:
|
||||
global_position = carrier.global_position
|
||||
return
|
||||
|
||||
pickupCooldown = maxf(pickupCooldown - delta, 0.0)
|
||||
if pickupCooldown == 0.0 and _try_pick_up():
|
||||
return
|
||||
|
||||
velocity.y = minf(velocity.y + get_gravity().y * delta, MAX_FALL_SPEED)
|
||||
if is_on_floor():
|
||||
velocity.x = move_toward(velocity.x, 0.0, GROUND_FRICTION * delta)
|
||||
move_and_slide()
|
||||
|
||||
|
||||
# Asks the physics world what's touching us. The slime double-checks it's really
|
||||
# in reach (see pick_up_item), as physics can be a frame behind after a tube.
|
||||
func _try_pick_up() -> bool:
|
||||
var query := PhysicsShapeQueryParameters2D.new()
|
||||
query.shape = pickupShape
|
||||
query.transform = Transform2D(0.0, global_position)
|
||||
query.collision_mask = collision_mask
|
||||
query.exclude = [get_rid()]
|
||||
for hit in get_world_2d().direct_space_state.intersect_shape(query):
|
||||
var body: Object = hit.collider
|
||||
if body != null and body.has_method("pick_up_item") and body.pick_up_item(self):
|
||||
return true
|
||||
return false
|
||||
|
||||
|
||||
# Called by the slime once it has decided to take us.
|
||||
func attach_to(newCarrier: Node2D) -> void:
|
||||
carrier = newCarrier
|
||||
# Never bump into the slime's body. It shares the world's layer, and coming out
|
||||
# of a tube, physics has its shape back where it went in for a frame: right on
|
||||
# top of us if we were left there, which shoved us out of it.
|
||||
add_collision_exception_with(carrier)
|
||||
velocity = Vector2.ZERO
|
||||
collisionShape.set_deferred("disabled", true)
|
||||
_fade_to(carriedOpacity)
|
||||
global_position = carrier.global_position
|
||||
reset_physics_interpolation() # Snap in, don't slide across.
|
||||
|
||||
|
||||
# Left behind where the slime is now, falling from there.
|
||||
func drop(dropVelocity := Vector2.ZERO) -> void:
|
||||
if carrier == null:
|
||||
return
|
||||
global_position = carrier.global_position
|
||||
carrier = null
|
||||
velocity = dropVelocity
|
||||
pickupCooldown = PICKUP_COOLDOWN
|
||||
collisionShape.set_deferred("disabled", false)
|
||||
_fade_to(1.0)
|
||||
reset_physics_interpolation()
|
||||
|
||||
|
||||
func _fade_to(opacity: float) -> void:
|
||||
if fadeTween:
|
||||
fadeTween.kill()
|
||||
fadeTween = create_tween()
|
||||
fadeTween.tween_property(sprite, "modulate:a", opacity, fadeTime)
|
||||
1
Items/carry_item.gd.uid
Normal file
1
Items/carry_item.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dqb51usb8erg1
|
||||
19
Items/carry_item.tscn
Normal file
19
Items/carry_item.tscn
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[gd_scene format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://Items/carry_item.gd" id="1_item"]
|
||||
[ext_resource type="Texture2D" uid="uid://bd60ddhri50de" path="res://icon.svg" id="2_icon"]
|
||||
|
||||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_body"]
|
||||
size = Vector2(12, 12)
|
||||
|
||||
[node name="CarryItem" type="CharacterBody2D"]
|
||||
collision_layer = 0
|
||||
collision_mask = 1
|
||||
script = ExtResource("1_item")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
scale = Vector2(0.09375, 0.09375)
|
||||
texture = ExtResource("2_icon")
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("RectangleShape2D_body")
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
[ext_resource type="PackedScene" uid="uid://uaxviwb40nn8" path="res://Characters/player.tscn" id="1_ormqy"]
|
||||
[ext_resource type="TileSet" uid="uid://tuiytikmuvdy" path="res://Assets/level_tiles.tres" id="2_4k50d"]
|
||||
[ext_resource type="PackedScene" path="res://UI/pause_menu.tscn" id="3_pause"]
|
||||
[ext_resource type="AudioStream" uid="uid://bow6wew1jbbk1" path="res://Assets/Sounds/Itty Bitty 8 Bit.mp3" id="4_i4ak4"]
|
||||
[ext_resource type="PackedScene" path="res://Items/carry_item.tscn" id="5_item"]
|
||||
|
||||
[node name="TestLevel" type="Node2D" unique_id=1824208737]
|
||||
|
||||
|
|
@ -10,11 +12,17 @@
|
|||
position = Vector2(329, 266)
|
||||
|
||||
[node name="TileMapLayer" type="TileMapLayer" parent="." un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kAAAACAAAAAAAFAAgAAAAAAAAAAAAGAAgAAAAAAAAAAAAGAAwAAAAAAAAAAAAFAAwAAAAAAAAAAAAIAAwAAAAAAAAAAAAIAAoAAAAAAAAAAAAGAAoAAAAAAAAAAAA=")
|
||||
tile_set = ExtResource("2_4k50d")
|
||||
|
||||
[node name="CarryItem" parent="." unique_id=1653302373 instance=ExtResource("5_item")]
|
||||
position = Vector2(380, 230)
|
||||
|
||||
[node name="PauseMenu" parent="." unique_id=904032161 instance=ExtResource("3_pause")]
|
||||
visible = false
|
||||
|
||||
[node name="MusicPlayer" type="AudioStreamPlayer" parent="." unique_id=1203733461]
|
||||
stream = ExtResource("4_i4ak4")
|
||||
volume_db = -20.0
|
||||
autoplay = true
|
||||
parameters/looping = true
|
||||
|
|
|
|||
Loading…
Reference in a new issue