-
Notifications
You must be signed in to change notification settings - Fork 0
/
global_variables.gd
264 lines (214 loc) · 5.76 KB
/
global_variables.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
extends Node
var actuator_state = 0
var overlapping = 0
var PLAYER_GRAV = 1
var CETERA_GRAV = 1
var PLAYER_SPAWN = Vector2(0, 0)
var PLAYER_POSITION = Vector2(0, 0)
var PROXY_SPAWN = Vector2(0, 0)
var PROXY_POSITION = Vector2(0, 0)
var PLAYER_ACTIVE = 1
var PROXY_ACTIVE = 0
var PROXY_OVERLAP = 0
var PROXY_DIR = 0
var PROXY_COOL = 0
var PROXY_IMMOBILE = 0
var PROXY_ROTATION_STEPS = 1
var BAR_LOWER = 16 * 10
var BAR_UPPER = -16 * 10000
var CLOCK = 1.0 / 40.0
var REDSTONE_TICK = 0
var MENU_SCREEN = 0
var NUM_MENUS = 2
func TICK_REDSTONE():
return REDSTONE_TICK == 0
# Level Names + Data
var LEVEL_NAMES = ["Prelude", "Introduction", "Commencement", "Specification", "Discrete", "Vorspiel",
"Motion", "Displacement"]
var DIFFICULTIES = ["Easy", "Easy", "Easy", "Normal", "Normal", "Normal",
"Normal", "Normal"]
var CurrentSelectedLevel = -1
var CheckPointPosition = null
var CheckpointTriggered = false
# Player or proxy enemy death.
# SAVE DATA
var save_path = "user://savegame.save"
func load_data():
var data = SaveData.new()
if FileAccess.file_exists(save_path):
print("FOUND SAVE DATA")
var file = FileAccess.open(save_path, FileAccess.READ)
data.levels = file.get_var()
data.Enemies = file.get_var()
data.CurrentLevel = file.get_var()
data.CurrentEnemies = file.get_var()
print("LOADED DATA...", data.levels, " ", data.CurrentLevel, " = ", data.Enemies)
else:
print("ERROR 404 FILE NOT FOUND")
return data
'''
levels = 1
Enemies = []
CurrentLevel = -1
CurrentEnemies = 0
'''
func save_data(data):
var file = FileAccess.open(save_path, FileAccess.WRITE)
file.store_var(data.levels)
file.store_var(data.Enemies)
file.store_var(data.CurrentLevel)
file.store_var(data.CurrentEnemies)
print("NUMBER OF ENEMIES ", data.CurrentEnemies)
func reset_game():
save_data(SaveData.new())
# EVERY TICK
var RESET_SCENE = 0
# PROXY
func _process(delta):
if (RESET_SCENE > 0):
RESET_SCENE -= 1
elif (RESET_SCENE < 0):
RESET_SCENE += 1
if (PROXY_COOL > 1):
PROXY_COOL -= 1
# if (PROXY_DIR >= 0):
# print("PROXY DATA ", PROXY_DIR, " ", PROXY_COOL)
if (PROXY_COOL <= 0):
if Input.is_action_pressed("PROXY_RIGHT"):
PROXY_DIR = 0
elif Input.is_action_pressed("PROXY_DOWN"):
PROXY_DIR = 1
elif Input.is_action_pressed("PROXY_LEFT"):
PROXY_DIR = 2
elif Input.is_action_pressed("PROXY_UP"):
PROXY_DIR = 3
elif Input.is_action_pressed("PROXY_ROT"):
PROXY_DIR = 4
else:
PROXY_DIR = -1
if (PROXY_COOL <= 0 && PROXY_DIR >= 0):
# print("KEY PRESSED ", PROXY_DIR)
PROXY_COOL = 4
PROXY_OVERLAP = 0
PROXY_IMMOBILE = 0
elif (PROXY_COOL == 3 && PROXY_DIR >= 0):
pass
# print("COLLECTING DATA")
# print("PROXY OVERLAP ", PROXY_OVERLAP, " | ", PROXY_IMMOBILE)
elif (PROXY_COOL == 2 && PROXY_DIR >= 0):
pass
# print("MOVING PROXY...")
elif (PROXY_COOL == 1 && PROXY_DIR >= 0):
PROXY_COOL = 0.5
if (PROXY_DIR <= 3):
await get_tree().create_timer(CLOCK).timeout
else:
await get_tree().create_timer(CLOCK * 2).timeout
PROXY_DIR = -1
PROXY_COOL = 0
# When PROXY_COOL == 3 we collect data from all the PROXY blocks
# When PROXY_COOL == 2 we move the PROXY blocks when possible.
# When PROXY_COOL == 1 we simply wait a little bit and then reset.
# Called when the node enters the scene tree for the first time.
func _ready():
print_debug("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
actuator_state = 0
overlapping = 0
PLAYER_GRAV = 1
CETERA_GRAV = 1
request_ready()
func resetCurrentScene():
print_debug("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
actuator_state = 0
overlapping = 0
PLAYER_GRAV = 1
RESET_SCENE = 2
var data = load_data()
save_data(data)
get_tree().reload_current_scene()
func is_Physical_Entity(v: String):
if (v == "Player"):
return 1
if (v.substr(0, 6) == "Roller"):
return 1
if (v.substr(0, 11) == "NormalEnemy"):
return 1
if (v.substr(0, 14) == "ProtectedEnemy"):
return 1
if (v.substr(0, 15) == "EnemyProtection"):
return 1
return 0
func is_Entity(v: String):
if (is_Physical_Entity(v)):
return 1
if (v.substr(0, 12) == "FallingBlock"):
return 1
return 0
func is_Block(v: String):
if (v.substr(0, 7) == "TileMap"):
return 1
if (v.substr(0, 7) == "Launcher"):
return 1
if (v.substr(0, 6) == "Spring"):
return 1
if (v.substr(0, 11) == "PressurePad"):
return 1
if (v.substr(0, 8) == "Actuator"):
return 1
if (v.substr(0, 7) == "Fragile"):
return 1
if (is_Proxy(v)):
return 1
return 0
func is_Proxy(v: String):
if (v.substr(0, 9) == "ProxyCore"):
return 1
if (v.substr(0, 10) == "ProxyBlock"):
return 1
func is_Redstone_Transmission(v: String):
if (v.substr(0, 12) == "RedstoneWire"):
return 1
if (v.substr(0, 12 + 1) == "RedstoneBlock"):
return 1
if (v.substr(0, 12 + 1) == "RedstoneDiode"):
return 1
if (v.substr(0, 16) == "RedstoneInverter"):
return 1
if (v.substr(0, 14) == "PressureSensor"):
return 1
if (v.substr(0, 17) == "RedstonePowerable"):
return 1
return 0
func redstone_Block_Connected(v: String):
if (v.substr(0, 12) == "RedstoneWire"):
return 1
if (v.substr(0, 12 + 1) == "RedstoneDiode"):
return 1
if (v.substr(0, 16) == "RedstoneInverter"):
return 1
if (v.substr(0, 16) == "RedstoneActuator"):
return 1
return 0
func piston_Movable(v: String):
if (v.substr(0, 17) == "RedstonePowerable"):
return 1
if (v.substr(0, 12) == "MovableBlock"):
return 1
if (v.substr(0, 12 + 1) == "RedstoneBlock"):
return 1
if (v.substr(0, 5) == "Spike"):
return 1
return 0
# MATH / UTIL FUNCTIONS
func sigmoid(x, s): # Sigmoid with dy/dx = s @x = 0
var res = 1 + exp(-2 * s * x)
return (2.0 / res) - 1
func rotate(disp: Vector2, step):
if (step == 1):
return Vector2(-1 * disp.y, disp.x)
if (step == 2):
return Vector2(-1 * disp.x, -1 * disp.y)
if (step == 3):
return Vector2(disp.y, -1 * disp.x)
else:
return Vector2(disp.x, disp.y)