-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.gd
71 lines (52 loc) · 1.86 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
extends Node
var gameState: Enums.GameState
var gameScenePath: String = "res://Levels/level.tscn"
var sceneInstance: Node = null
@onready var startMenu: Control = $CanvasLayer/StartMenu
@onready var pauseMenu: CanvasLayer = $CanvasLayer/PauseMenu
func _ready():
set_state(Enums.GameState.ON_START)
startMenu.get_node("Panel/StartButton").pressed.connect(self._on_press_start)
pauseMenu.get_node("Panel/VBoxContainer/ResumeButton").pressed.connect(self._on_press_resume)
pauseMenu.get_node("Panel/VBoxContainer/QuitButton").pressed.connect(self._on_press_quit)
#$titleAudioLoop.play()
func _input (event: InputEvent):
if(gameState != Enums.GameState.ON_START && event.is_action_pressed("ui_cancel")):
match gameState:
Enums.GameState.IN_GAME:
set_state(Enums.GameState.PAUSED)
Enums.GameState.PAUSED:
set_state(Enums.GameState.IN_GAME)
func set_state(newState: Enums.GameState):
match newState:
Enums.GameState.ON_START:
if gameState == Enums.GameState.PAUSED:
pauseMenu.close()
get_tree().paused = false
startMenu.visible = true
pauseMenu.visible = false
Enums.GameState.IN_GAME:
if gameState == Enums.GameState.PAUSED:
pauseMenu.close()
while await pauseMenu.animation.animation_finished != "pause_menu":
pass
get_tree().paused = false
startMenu.visible = false
pauseMenu.visible = false
Enums.GameState.PAUSED:
pauseMenu.open()
get_tree().paused = true
pauseMenu.visible = true
gameState = newState
func _on_press_start():
sceneInstance = load(gameScenePath).instantiate()
$Main3D.add_child(sceneInstance)
set_state(Enums.GameState.IN_GAME)
$titleAudioLoop.stop()
func _on_press_resume():
set_state(Enums.GameState.IN_GAME)
func _on_press_quit():
set_state(Enums.GameState.ON_START)
if (is_instance_valid(sceneInstance)):
sceneInstance.queue_free()
sceneInstance = null