let camera follow player according to room config
This commit is contained in:
parent
29909a5371
commit
fc81f396e0
3 changed files with 13 additions and 4 deletions
|
|
@ -1,14 +1,18 @@
|
|||
class_name Room extends Node2D
|
||||
|
||||
|
||||
@export var room_config: RoomConfig
|
||||
@export var config: RoomConfig
|
||||
|
||||
@onready var camera: RoomCamera = $RoomCamera
|
||||
@onready var director: StateMachine = $RoomDirector
|
||||
|
||||
# TODO: better alternatice to preloading as i add functionality?
|
||||
# TODO: better alternative to preloading as i add functionality?
|
||||
# https://theduriel.github.io/Godot/Do-not-use---Preload
|
||||
var player_scene: PackedScene = preload("uid://cqm5besqgsb7x")
|
||||
var initial_spawn: Vector2i = Vector2i(16,16)
|
||||
|
||||
var player: Player
|
||||
var initial_spawn: Vector2i = Vector2i(16,16)
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
assert(config != null, "room config is null")
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
|||
room.player = room.player_scene.instantiate()
|
||||
room.add_child(room.player)
|
||||
room.player.global_position = room.initial_spawn
|
||||
room.camera.global_position = room.config.camera_position
|
||||
|
||||
finished.emit(PLAYING)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,9 +1,13 @@
|
|||
extends RoomState
|
||||
|
||||
|
||||
var follow: bool
|
||||
|
||||
|
||||
func _enter(_previous_state_path: String, _data: Dictionary = {}) -> void:
|
||||
print("entering room gameplay")
|
||||
get_tree().paused = false
|
||||
follow = room.config.follow_player
|
||||
|
||||
|
||||
func _handle_input(event: InputEvent) -> void:
|
||||
|
|
@ -12,4 +16,4 @@ func _handle_input(event: InputEvent) -> void:
|
|||
|
||||
|
||||
func _state_physics_update(delta: float) -> void:
|
||||
room.camera.follow_player(delta)
|
||||
if follow: room.camera.follow_player(delta)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue