-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.gd
53 lines (40 loc) · 1.67 KB
/
Main.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
extends Node2D
var hitball: Resource = preload("res://Hitball.tscn")
func _on_timer_timeout() -> void:
var instance = hitball.instantiate()
instance.counter = $Interface/ScoreLabel
instance.audio_player = $AudioStreamPlayer2D
var radius: float = instance.get_radius()
instance.position = Vector2(
randf_range(0 + radius, 1920 - radius),
randf_range(0 + radius, 1080 - radius)
)
add_child(instance)
instance.game_over.connect(_on_game_over)
instance.game_over.connect($Interface._on_game_over)
$Timer.start()
func _on_start_game() -> void:
$Timer.start()
func _on_game_over() -> void:
get_tree().call_group("hitballs", "queue_free")
$Timer.stop()
var username: String = $Interface/MainContainer/UsernameContainer/UsernameEdit.text
var password: String = $Interface/MainContainer/UsernameContainer/PasswordEdit.text
var score: int = $Interface/ScoreLabel.text.to_int()
var level: int = $Interface/OptionsPage/Container/LevelSlider.value
if $Interface/MainContainer/UsernameContainer/UsernameEdit.text:
var success: bool = await Requests.submit_score(username, password, score, level)
if not success:
print('Failed to submit score')
return
var leaderboard: Dictionary = await Requests.get_scores()
$Interface/LeaderBoardContainer.show()
$Interface/LeaderBoardContainer/LeaderBoard.set_leaderboard(leaderboard)
func _unhandled_input(event):
if event.is_action_pressed("fullscreen"):
print(DisplayServer.window_get_mode())
match DisplayServer.window_get_mode():
DisplayServer.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
_:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)