-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.gd
137 lines (102 loc) · 2.8 KB
/
game.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
extends Node2D
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
const STATE_START = "start"
const STATE_PLAYING = "playing"
const STATE_DEFEAT = "defeat"
const STATE_VICTORY = "victory"
const STATE_BOOK = "book"
var state = STATE_START
onready var main = $main
onready var menu = $menu
onready var victory = $menu/Victory
onready var defeat = $menu/Defeat
onready var banished = $menu/banished
onready var start = $menu/Start
onready var book = $menu/Spellbook
onready var btnAgain = $menu/btnAgain
onready var btnEndless = $menu/btnEndless
var main_scene = preload("res://main.tscn")
# Called when the node enters the scene tree for the first time.
func _ready():
self.pause_mode = Node.PAUSE_MODE_PROCESS
menu.pause_mode = Node.PAUSE_MODE_PROCESS
main.pause_mode = Node.PAUSE_MODE_STOP
Globals.game = self
set_start()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func set_start():
state = STATE_START
for child in menu.get_children():
child.visible = false
menu.visible = true
start.visible = true
btnAgain.visible = true
btnAgain.text = "start"
btnEndless.visible = true
get_tree().paused = true
func set_playing():
Globals.banished_enemies = 0
Globals.endless_mode = false
Globals.is_casting = false
state = STATE_PLAYING
main.queue_free()
main = main_scene.instance()
main.pause_mode = Node.PAUSE_MODE_STOP
add_child(main)
menu.visible = false
start.visible = false
get_tree().paused = false
func set_playing_endless():
set_playing()
Globals.endless_mode = true
func continue_playing():
state = STATE_PLAYING
menu.visible = false
get_tree().paused = false
func set_victory():
state = STATE_VICTORY
get_tree().paused = true
for child in menu.get_children():
child.visible = false
menu.visible = true
banished.visible = true
btnAgain.visible = true
btnAgain.text = "again"
btnEndless.visible = true
banished.text = "Enemies banished: %s" %[Globals.banished_enemies]
victory.visible = true
func set_defeat():
state = STATE_DEFEAT
get_tree().paused = true
for child in menu.get_children():
child.visible = false
menu.visible = true
btnAgain.visible = true
btnAgain.text = "again"
btnEndless.visible = true
banished.visible = true
banished.text = "Enemies banished: %s" %[Globals.banished_enemies]
defeat.visible = true
func set_book():
state = STATE_BOOK
get_tree().paused = true
for child in menu.get_children():
child.visible = false
menu.visible = true
book.visible = true
func _unhandled_input(event):
if event.is_action_released("interact"):
#if state == STATE_START:
# set_book()
# return
if state == STATE_BOOK:
continue_playing()
func _on_btnAgain_pressed():
if state == STATE_START:
set_book()
else:
set_playing()
func _on_btnEndless_pressed():
set_playing_endless()