This repository was archived by the owner on Jun 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.gd
More file actions
51 lines (41 loc) · 1.52 KB
/
ui.gd
File metadata and controls
51 lines (41 loc) · 1.52 KB
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
40
41
42
43
44
45
46
47
48
49
50
extends Node2D
export var width = 600
export var height = 1024
export var tween_speed = .35
onready var score_label = $score_panel/Label
onready var animation_player = score_label.get_node("player")
onready var moves_label = $Control/Moves/label_node/Label
onready var moves_node = $Control/Moves/label_node
onready var tween = $Control/tween
# sizes and positions the ui center of the screen
func size_and_position():
var screen_w = get_viewport().size.x
var screen_h = get_viewport().size.y
var scale_factor = 1
# if screen is smaller than the project minimum size
# set the scalefactor to scale the right amount
if screen_w < 600:
scale_factor = screen_w / 600
scale = Vector2(scale_factor, scale_factor)
position.x = screen_w/2 - (width*scale_factor)/2
position.y = screen_h/2 - (height*scale_factor)/2
func _update_score():
score_label.text = str(Globals.score)
animation_player.play("score_jump")
func _update_moves():
moves_label.text = str(Globals.moves)
moves_node.scale = Vector2(2,2)
tween.stop_all()
tween.interpolate_property(moves_node, "scale", moves_node.scale, Vector2(1,1),\
tween_speed, Tween.TRANS_ELASTIC, Tween.EASE_OUT)
tween.start()
# Called when the node enters the scene tree for the first time.
func _ready():
get_tree().get_root().connect("size_changed", self, "size_and_position")
position.x -= width/2
position.y -= height/2
size_and_position()
_update_score()
_update_moves()
Globals.connect("score_set", self, "_update_score")
Globals.connect("moves_set", self, "_update_moves")