Compare commits
2 commits
902ed33ee4
...
e7a773e2f4
| Author | SHA1 | Date | |
|---|---|---|---|
| e7a773e2f4 | |||
| 1a7a43ab52 |
7 changed files with 153 additions and 2 deletions
|
|
@ -83,6 +83,7 @@ const BRIDGE_FRAME = 10 # Wall to wall. Drawn upright, so it's turned a quarter.
|
||||||
const BRIDGE_VERTICAL_FRAME = 11 # Floor to ceiling.
|
const BRIDGE_VERTICAL_FRAME = 11 # Floor to ceiling.
|
||||||
const BRIDGE_GAP = 32.0 # One tile.
|
const BRIDGE_GAP = 32.0 # One tile.
|
||||||
const BRIDGE_GAP_TOLERANCE = 1.5
|
const BRIDGE_GAP_TOLERANCE = 1.5
|
||||||
|
const IN_AIR_FRAME = 8 # The InAir animation's frame.
|
||||||
|
|
||||||
###############
|
###############
|
||||||
## Variables ##
|
## Variables ##
|
||||||
|
|
@ -152,6 +153,7 @@ var isBridging := false
|
||||||
var bridgeAxis := Vector2.RIGHT # RIGHT between walls, DOWN between floor and ceiling.
|
var bridgeAxis := Vector2.RIGHT # RIGHT between walls, DOWN between floor and ceiling.
|
||||||
var bridgeHoldSide := 0.0 # Which way along bridgeAxis we're holding (1, -1), or 0.
|
var bridgeHoldSide := 0.0 # Which way along bridgeAxis we're holding (1, -1), or 0.
|
||||||
var timeSpentLeavingBridge := 0.0
|
var timeSpentLeavingBridge := 0.0
|
||||||
|
var timeSpentDroppingFromBridge := 0.0
|
||||||
|
|
||||||
var carriedItem: CarryItem = null # The item riding in our center, or null. Tubes drop it.
|
var carriedItem: CarryItem = null # The item riding in our center, or null. Tubes drop it.
|
||||||
|
|
||||||
|
|
@ -630,6 +632,7 @@ func _begin_bridge(normal: Vector2, ownPoint: Vector2, otherPoint: Vector2) -> v
|
||||||
timeSpentHoldingUpOnFloor = 0.0
|
timeSpentHoldingUpOnFloor = 0.0
|
||||||
timeSpentHoldingEdge = 0.0
|
timeSpentHoldingEdge = 0.0
|
||||||
timeSpentLeavingBridge = 0.0
|
timeSpentLeavingBridge = 0.0
|
||||||
|
timeSpentDroppingFromBridge = 0.0
|
||||||
# We're still holding away from the surface we left, towards the one across.
|
# We're still holding away from the surface we left, towards the one across.
|
||||||
# Keep holding and we cross over to it after HOLD_TIME, like any other hold.
|
# Keep holding and we cross over to it after HOLD_TIME, like any other hold.
|
||||||
bridgeHoldSide = signf(normal.dot(bridgeAxis))
|
bridgeHoldSide = signf(normal.dot(bridgeAxis))
|
||||||
|
|
@ -652,24 +655,54 @@ func _begin_bridge(normal: Vector2, ownPoint: Vector2, otherPoint: Vector2) -> v
|
||||||
|
|
||||||
# Holding towards either surface for HOLD_TIME sticks us to it and lets go of
|
# Holding towards either surface for HOLD_TIME sticks us to it and lets go of
|
||||||
# the other: left or right between walls, up or down between floor and ceiling.
|
# the other: left or right between walls, up or down between floor and ceiling.
|
||||||
|
# Holding down between walls, or left or right between floor and ceiling, for
|
||||||
|
# HOLD_TIME lets go of both and drops us. Diagonals do neither.
|
||||||
func _update_bridge(delta: float, moveInput: Vector2) -> void:
|
func _update_bridge(delta: float, moveInput: Vector2) -> void:
|
||||||
velocity = Vector2.ZERO
|
velocity = Vector2.ZERO
|
||||||
var inputDirection := Vector2(moveInput.x, -moveInput.y) # Up is negative y.
|
var inputDirection := Vector2(moveInput.x, -moveInput.y) # Up is negative y.
|
||||||
var side := signf(inputDirection.dot(bridgeAxis))
|
var along := signf(inputDirection.dot(bridgeAxis))
|
||||||
|
var across := signf(inputDirection.dot(bridgeAxis.orthogonal()))
|
||||||
|
|
||||||
|
var side := along if across == 0.0 else 0.0
|
||||||
if side != 0.0 and side == bridgeHoldSide:
|
if side != 0.0 and side == bridgeHoldSide:
|
||||||
timeSpentLeavingBridge += delta
|
timeSpentLeavingBridge += delta
|
||||||
else:
|
else:
|
||||||
timeSpentLeavingBridge = 0.0
|
timeSpentLeavingBridge = 0.0
|
||||||
bridgeHoldSide = side
|
bridgeHoldSide = side
|
||||||
|
|
||||||
|
# Between walls only down drops us (bridgeAxis.orthogonal() is up there).
|
||||||
|
var holdingToDrop := along == 0.0 and across != 0.0
|
||||||
|
if bridgeAxis == Vector2.RIGHT:
|
||||||
|
holdingToDrop = holdingToDrop and inputDirection.y > 0.0
|
||||||
|
if holdingToDrop:
|
||||||
|
timeSpentDroppingFromBridge += delta
|
||||||
|
else:
|
||||||
|
timeSpentDroppingFromBridge = 0.0
|
||||||
|
|
||||||
if timeSpentLeavingBridge >= HOLD_TIME:
|
if timeSpentLeavingBridge >= HOLD_TIME:
|
||||||
_leave_bridge(bridgeAxis * side, delta)
|
_leave_bridge(bridgeAxis * side, delta)
|
||||||
|
elif timeSpentDroppingFromBridge >= HOLD_TIME:
|
||||||
|
_drop_from_bridge()
|
||||||
|
|
||||||
|
|
||||||
|
# Lets go of both surfaces and falls from where we are.
|
||||||
|
func _drop_from_bridge() -> void:
|
||||||
|
isBridging = false
|
||||||
|
timeSpentLeavingBridge = 0.0
|
||||||
|
timeSpentDroppingFromBridge = 0.0
|
||||||
|
velocity = Vector2.ZERO
|
||||||
|
# is_on_floor() and friends still describe where we bridged from. A move on
|
||||||
|
# the spot brings them up to date, so we don't count as on it.
|
||||||
|
move_and_slide()
|
||||||
|
_set_sprite_rotation(0.0)
|
||||||
|
_show_pose(&"InAir", IN_AIR_FRAME)
|
||||||
|
|
||||||
|
|
||||||
# Sticks to the surface in `direction` from us.
|
# Sticks to the surface in `direction` from us.
|
||||||
func _leave_bridge(direction: Vector2, delta: float) -> void:
|
func _leave_bridge(direction: Vector2, delta: float) -> void:
|
||||||
isBridging = false
|
isBridging = false
|
||||||
timeSpentLeavingBridge = 0.0
|
timeSpentLeavingBridge = 0.0
|
||||||
|
timeSpentDroppingFromBridge = 0.0
|
||||||
var normal := -direction
|
var normal := -direction
|
||||||
var gap := BRIDGE_GAP / 2.0 - _get_radius()
|
var gap := BRIDGE_GAP / 2.0 - _get_radius()
|
||||||
_set_sprite_rotation(_rotation_for(normal))
|
_set_sprite_rotation(_rotation_for(normal))
|
||||||
|
|
@ -1149,6 +1182,17 @@ func _update_tube(delta: float, moveInput: Vector2) -> void:
|
||||||
_exit_tube(tubeExitPose, delta)
|
_exit_tube(tubeExitPose, delta)
|
||||||
|
|
||||||
|
|
||||||
|
# The point the camera should keep on screen (see RoomCamera). In a tube we're
|
||||||
|
# hidden at the entrance, so it's the front of our goo instead.
|
||||||
|
func get_camera_focus() -> Vector2:
|
||||||
|
if isInTube:
|
||||||
|
if tubeSteer != null:
|
||||||
|
return tubeSteer.get_focus()
|
||||||
|
if tubePixels != null:
|
||||||
|
return tubePixels.get_focus()
|
||||||
|
return global_position
|
||||||
|
|
||||||
|
|
||||||
func _exit_tube(pose: Dictionary, delta: float) -> void:
|
func _exit_tube(pose: Dictionary, delta: float) -> void:
|
||||||
isInTube = false
|
isInTube = false
|
||||||
tubeReentryCooldown = TUBE_REENTRY_DELAY
|
tubeReentryCooldown = TUBE_REENTRY_DELAY
|
||||||
|
|
|
||||||
|
|
@ -244,5 +244,13 @@ func _point_on_path(distance: float, lane: float) -> Vector2:
|
||||||
return from.lerp(to, progress) + left * lane
|
return from.lerp(to, progress) + left * lane
|
||||||
|
|
||||||
|
|
||||||
|
# Where the front of the stream is, in global coordinates (for the camera).
|
||||||
|
func get_focus() -> Vector2:
|
||||||
|
if _path.is_empty():
|
||||||
|
return global_position
|
||||||
|
var distance := clampf((_time - _enter_time(0)) * SPEED, 0.0, _tube_length())
|
||||||
|
return _point_on_path(distance, 0.0)
|
||||||
|
|
||||||
|
|
||||||
func _tube_length() -> float:
|
func _tube_length() -> float:
|
||||||
return _pathDistances[_pathDistances.size() - 1]
|
return _pathDistances[_pathDistances.size() - 1]
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,14 @@ func steer(input: Vector2, delta: float) -> void:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
# Where the goo last grew, in global coordinates (for the camera). The goo has
|
||||||
|
# no head, so this is the end the player is pushing.
|
||||||
|
func get_focus() -> Vector2:
|
||||||
|
if _active == -1:
|
||||||
|
return global_position
|
||||||
|
return _positions[_active]
|
||||||
|
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
_time += delta
|
_time += delta
|
||||||
queue_redraw()
|
queue_redraw()
|
||||||
|
|
|
||||||
|
|
@ -228,6 +228,13 @@ func steer(input: Vector2, delta: float) -> void:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
# Where the leader is, in global coordinates (for the camera).
|
||||||
|
func get_focus() -> Vector2:
|
||||||
|
if _leader == -1:
|
||||||
|
return global_position
|
||||||
|
return _positions[_leader]
|
||||||
|
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
_time += delta
|
_time += delta
|
||||||
if _isTakingIn or _isPouring:
|
if _isTakingIn or _isPouring:
|
||||||
|
|
|
||||||
78
Levels/room_camera.gd
Normal file
78
Levels/room_camera.gd
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
extends Camera2D
|
||||||
|
class_name RoomCamera
|
||||||
|
|
||||||
|
# Splits the level into screen-sized rooms and snaps to whichever room the
|
||||||
|
# target is in, VVVVVV style: the camera never scrolls, it just cuts to the
|
||||||
|
# next screen when the target crosses a room border.
|
||||||
|
#
|
||||||
|
# Room (0, 0) has its top-left corner at the level's origin, room (1, 0) is the
|
||||||
|
# screen to its right, and so on. Rooms with negative coordinates work too.
|
||||||
|
# Our tiles are 32x32, so one room is exactly 20x15 tiles.
|
||||||
|
|
||||||
|
const ROOM_SIZE := Vector2(640, 480)
|
||||||
|
|
||||||
|
# How far (in pixels) the target must get past a border before we switch rooms,
|
||||||
|
# so standing right on a border doesn't flicker between the two screens.
|
||||||
|
const SWITCH_MARGIN := 4.0
|
||||||
|
|
||||||
|
# The node to follow, usually the Player.
|
||||||
|
@export var target: Node2D
|
||||||
|
|
||||||
|
var room := Vector2i.ZERO
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
# Our position is the room's top-left corner, so the room fills the screen.
|
||||||
|
anchor_mode = Camera2D.ANCHOR_MODE_FIXED_TOP_LEFT
|
||||||
|
position_smoothing_enabled = false
|
||||||
|
# Run after the player has moved this frame.
|
||||||
|
process_physics_priority = 100
|
||||||
|
make_current()
|
||||||
|
|
||||||
|
if target != null:
|
||||||
|
room = room_at(_focus())
|
||||||
|
_snap_to_room()
|
||||||
|
|
||||||
|
|
||||||
|
func _physics_process(_delta: float) -> void:
|
||||||
|
if target == null:
|
||||||
|
return
|
||||||
|
var newRoom := _room_with_margin(_focus())
|
||||||
|
if newRoom != room:
|
||||||
|
room = newRoom
|
||||||
|
_snap_to_room()
|
||||||
|
|
||||||
|
|
||||||
|
# The point to keep on screen. A target can say where that is with a
|
||||||
|
# get_camera_focus() method (the Player does, so we follow it through tubes).
|
||||||
|
func _focus() -> Vector2:
|
||||||
|
if target.has_method(&"get_camera_focus"):
|
||||||
|
return target.get_camera_focus()
|
||||||
|
return target.global_position
|
||||||
|
|
||||||
|
|
||||||
|
# Which room a point in the level is in.
|
||||||
|
static func room_at(point: Vector2) -> Vector2i:
|
||||||
|
return Vector2i((point / ROOM_SIZE).floor())
|
||||||
|
|
||||||
|
|
||||||
|
# The rectangle a room covers, in level coordinates.
|
||||||
|
static func room_rect(roomCoords: Vector2i) -> Rect2:
|
||||||
|
return Rect2(Vector2(roomCoords) * ROOM_SIZE, ROOM_SIZE)
|
||||||
|
|
||||||
|
|
||||||
|
# Like room_at(), but sticks with the current room until the point is
|
||||||
|
# SWITCH_MARGIN pixels past its border.
|
||||||
|
func _room_with_margin(point: Vector2) -> Vector2i:
|
||||||
|
var current := room_rect(room).grow(SWITCH_MARGIN)
|
||||||
|
if current.has_point(point):
|
||||||
|
return room
|
||||||
|
return room_at(point)
|
||||||
|
|
||||||
|
|
||||||
|
func _snap_to_room() -> void:
|
||||||
|
global_position = Vector2(room) * ROOM_SIZE
|
||||||
|
# Physics interpolation is on in this project, which would otherwise slide
|
||||||
|
# the camera between the two rooms for a frame. Make it a clean cut.
|
||||||
|
reset_physics_interpolation()
|
||||||
|
reset_smoothing()
|
||||||
1
Levels/room_camera.gd.uid
Normal file
1
Levels/room_camera.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://bhh8lm6fel8sx
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue