-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCamera.gd
39 lines (29 loc) · 1.3 KB
/
Camera.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
extends Camera2D
signal selected_wall_changed
export(float) var focus_speed := 0.2
onready var animation_player: AnimationPlayer = get_tree().root.get_node("World/AnimationPlayer")
var selected_wall: int = 0 setget set_selected_wall
func set_selected_wall(value: int) -> void:
selected_wall = fposmod(value, 4)
animation_player.play("Fade")
func _input(event: InputEvent) -> void:
if not Gamestate.focused_object: # Block movement if focused
if event.is_action_pressed("ui_right"):
self.selected_wall += 1
if event.is_action_pressed("ui_left"):
self.selected_wall -= 1
if event.is_action_pressed("ui_down"):
Gamestate.focused_object = ""
func _process(_delta: float) -> void:
var target_offset := Vector2.ZERO
var target_zoom := Vector2(1, 1)
if Gamestate.focused_object: # Focus on focused object, if any
var focused_node: Focusable = Gamestate.objects[Gamestate.focused_object]
target_offset = focused_node.focus_point.global_position - global_position
target_zoom /= focused_node.focus_zoom
# Interpolate towards target
offset = lerp(offset, target_offset, focus_speed)
zoom = lerp(zoom, target_zoom, focus_speed)
func on_wall_changed() -> void:
emit_signal("selected_wall_changed")
position = Vector2(selected_wall * Constants.wallsize.x, 0) + Constants.wallsize / 2 # Update position