Added camera transition between levels.
This commit is contained in:
parent
1a7a43ab52
commit
e7a773e2f4
7 changed files with 119 additions and 1 deletions
|
|
@ -1182,6 +1182,17 @@ func _update_tube(delta: float, moveInput: Vector2) -> void:
|
|||
_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:
|
||||
isInTube = false
|
||||
tubeReentryCooldown = TUBE_REENTRY_DELAY
|
||||
|
|
|
|||
|
|
@ -244,5 +244,13 @@ func _point_on_path(distance: float, lane: float) -> Vector2:
|
|||
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:
|
||||
return _pathDistances[_pathDistances.size() - 1]
|
||||
|
|
|
|||
|
|
@ -156,6 +156,14 @@ func steer(input: Vector2, delta: float) -> void:
|
|||
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:
|
||||
_time += delta
|
||||
queue_redraw()
|
||||
|
|
|
|||
|
|
@ -228,6 +228,13 @@ func steer(input: Vector2, delta: float) -> void:
|
|||
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:
|
||||
_time += delta
|
||||
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