29 lines
1.1 KiB
GDScript
29 lines
1.1 KiB
GDScript
extends Camera2D
|
|
|
|
onready var player = get_tree().get_nodes_in_group("player").front()
|
|
onready var last_sector = Game.get_sector(player.global_position + Vector2(0.0, -5.0))
|
|
#Scroll direction
|
|
export var scroll_h = true
|
|
export var scroll_v = false
|
|
export var respawn_h = true
|
|
|
|
func _ready():
|
|
set_as_toplevel(true)
|
|
Game.current_sector = last_sector
|
|
|
|
func _process(delta):
|
|
# use pop_front() instead of [0] so that will not crash without player
|
|
if not is_instance_valid(player):
|
|
player = get_tree().get_nodes_in_group("player").pop_front()
|
|
else:
|
|
var current_sector = Game.get_sector(player.global_position + Vector2(0.0, 1.0))
|
|
if scroll_h && current_sector.x != last_sector.x:
|
|
position.x = current_sector.x * Game.RESOLUTION.x
|
|
if respawn_h:
|
|
var offset = Vector2(8.0 * sign(current_sector.x - last_sector.x), 0.0)
|
|
Game.respawn_point = player.global_position
|
|
last_sector.x = current_sector.x
|
|
if scroll_v && current_sector.y != last_sector.y:
|
|
position.y = current_sector.y * Game.RESOLUTION.y
|
|
last_sector.y = current_sector.y
|
|
Game.current_sector = last_sector
|