-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal_state.gd
342 lines (308 loc) · 7.39 KB
/
global_state.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
extends Node
var level_1 := preload("res://Scenes/Level1.tscn")
var level_2 := preload("res://Scenes/Level2.tscn")
@onready var audio_manager := get_node("/root/AudioManager")
const playspace := Vector2(384.0/4, 288.0/2 - 10)
const scrap_value := 1200
const money_speed := 60.0
const money_exponent := 1.5
var max_lives := 5
var lives := max_lives
var starting_money := 10000.0
var money := starting_money
var bullets_fired := 0
var bullets_hit := 0
var max_ammo := 100
var current_ammo := max_ammo
var heckler_percent_diff := 5.0
var heckler_shares_owned := 0
const max_trades := 10
var trades_remaining := max_trades
var stock_price_low_bound := 10_000.0
var stock_price_high_bound := 30_000.0
var heckler_stock_price := stock_price_high_bound
var last_heckler_stock_price := stock_price_high_bound
var current_level := 1
var stock_rng := RandomNumberGenerator.new()
var bullet_rng := RandomNumberGenerator.new()
signal money_added
signal player_died
signal player_damaged
signal weapon_equipped
signal weapon_fired
enum EndScreenState {
LEVEL_CLEAR,
VICTORY,
DEFEAT,
YOU_DIED,
}
var end_screen_state: EndScreenState = EndScreenState.YOU_DIED
const Ol_Reliable := {
"name": "Ol'Reliable",
"damage": 10.0,
"shootsound": preload("res://Resources/Audio/SFX/pea_shooter_sound.ogg"),
"shopprice": 10000.0,
"cycles": 120,
"shot_delay": 0.1,
"rotation": 180,
"friend": true,
"type": "linear",
"bullet_data": {
"velocity": 300.0,
"color": Color("YELLOW"),
"size": 1.0,
"acceleration": 1.0,
"type": "linear",
}
}
const Scrapper := {
"name": "Scrapper",
"damage": 15.0,
"shopprice": 15000.0,
"shootsound": preload("res://Resources/Audio/SFX/shoot_sound_2.ogg"),
"cycles": 80,
"bullet_speed": 400,
"shot_delay": 0.08,
"rotation": 180,
"friend": true,
"type": "linear",
"bullet_data": {
"velocity": 300.0,
"color": Color("YELLOW"),
"size": 1.0,
"acceleration": 1.0,
"frequency": 20,
"amplitude": 3,
"type": "linear",
}
}
const Bertha := {
"name": "Bertha",
"damage": 50.0,
"shopprice": 20000.0,
"shootsound": preload("res://Resources/Audio/SFX/shoot_sound_3.ogg"),
"cycles": 40,
"bullet_speed": 200,
"shot_delay": 0.3,
"rotation": 180,
"friend": true,
"type": "linear",
"bullet_data": {
"velocity": 300.0,
"color": Color("YELLOW"),
"size": 2.0,
"acceleration": 1.0,
"frequency": 20,
"amplitude": 3,
"type": "linear",
}
}
const Sawed_Off := {
"name": "Sawed-Off",
"damage": 15.0,
"shopprice": 15000.0,
"shootsound": preload("res://Resources/Audio/SFX/shoot_sound_2.ogg"),
"cycles": 40,
"bullet_speed": 200,
"shot_delay": 0.2,
"rotation": 180,
"friend": true,
"type": "radial",
"random": Vector2(-2, 2),
"spawn_params": {
"amount":3,
"degrees":20,
},
"bullet_data": {
"velocity": 500.0,
"color": Color("YELLOW"),
"size": 1.0,
"acceleration": 1.0,
"frequency": 20,
"amplitude": 3,
"type": "linear",
}
}
const Minigun := {
"name": "Minigun",
"damage": 3.0,
"shopprice": 17500.0,
"shootsound": preload("res://Resources/Audio/SFX/shoot_sound_6.ogg"),
"cycles": 400,
"bullet_speed": 200,
"shot_delay": 0.02,
"rotation": 180,
"friend": true,
"type": "radial",
"random": Vector2(-5, 5),
"spawn_params": {
"amount":2,
"degrees":10,
},
"bullet_data": {
"velocity": 400.0,
"color": Color("YELLOW"),
"size": 0.5,
"acceleration": 1.0,
"frequency": 20,
"amplitude": 3,
"type": "linear",
}
}
const Bendy := {
"name": "Bendy",
"damage": 15.0,
"shopprice": 15000.0,
"shootsound": preload("res://Resources/Audio/SFX/shoot_sound_5.ogg"),
"cycles": 100,
"bullet_speed": 450,
"shot_delay": 0.08,
"rotation": 180,
"friend": true,
"type": "linear",
"spawn_params": {
},
"bullet_data": {
"velocity": 400.0,
"color": Color("YELLOW"),
"size": 1.0,
"acceleration": 1.0,
"frequency": 20,
"amplitude": 4,
"type": "sin",
}
}
const Shank := {
"name": "Shank",
"damage": 25.0,
"shopprice": 5000.0,
"shootsound": preload("res://Resources/Audio/SFX/shoot_sound_7.ogg"),
"cycles": 10000,
"bullet_speed": 800,
"shot_delay": 0.01,
"rotation": 180,
"friend": true,
"type": "linear",
"spawn_params": {
},
"bullet_data": {
"velocity": 400.0,
"color": Color("YELLOW"),
"size": 0.5,
"acceleration": 0.93,
"lifetime": 0.15,
"frequency": 20,
"amplitude": 2,
"type": "linear",
}
}
var current_weapon: Dictionary = Ol_Reliable
var current_purchasable_weapon: Dictionary = Scrapper
const weapon_list := [
Ol_Reliable,
Scrapper,
Bertha,
Sawed_Off,
Minigun,
Bendy,
Shank
]
func _ready() -> void:
bullet_rng.seed = int("2hu")
func set_new_heckler_stock_price() -> void:
last_heckler_stock_price = heckler_stock_price
heckler_stock_price = stock_rng.randf() * (stock_price_high_bound - stock_price_low_bound) + stock_price_low_bound
heckler_percent_diff = (heckler_stock_price - last_heckler_stock_price) / heckler_stock_price * 100.0
func buy_heckler_stock() -> bool:
if money < heckler_stock_price || trades_remaining <= 0:
return false
trades_remaining -= 1
heckler_shares_owned += 1
money -= heckler_stock_price
audio_manager.play_buy_share_sfx()
return true
func sell_heckler_stock() -> bool:
if heckler_shares_owned <= 0 || trades_remaining <= 0:
return false
trades_remaining -= 1
heckler_shares_owned -= 1
money += heckler_stock_price
audio_manager.play_sell_share_sfx()
return true
func add_money(x: float) -> void:
money += x
money_added.emit()
func buy_and_equip_gun_from_shop() -> bool:
if current_purchasable_weapon["shopprice"] > money:
return false
equip_weapon(current_purchasable_weapon)
money -= current_weapon["shopprice"]
return true
func reset_trade_count():
trades_remaining = max_trades
func equip_weapon(weapon):
current_weapon = weapon
max_ammo = current_weapon.cycles
current_ammo = max_ammo
weapon_equipped.emit()
func update_bullet_counter() -> void:
current_ammo -= 1
bullets_fired += 1
weapon_fired.emit()
func get_ammo_percent() -> float:
return float(current_ammo) / max_ammo
func get_accuracy() -> float:
if bullets_fired == 0:
return 100.0
return float(bullets_hit) / float(bullets_fired) * 100.0
func take_damage() -> void:
lives -= 1
if lives <= 0:
player_died.emit()
end_screen_state = EndScreenState.YOU_DIED
goto_end_screen()
player_damaged.emit()
func collect_scrap() -> void:
add_money(scrap_value)
func reset_game() -> void:
current_weapon = Ol_Reliable
current_level = 0
lives = max_lives
money = starting_money
bullets_fired = 0
bullets_hit = 0
trades_remaining = max_trades
func start_new_game() -> void:
reset_game()
load_next_level()
start_level()
func load_next_level() -> void:
lives = max_lives
current_level += 1
match current_level:
1:
get_tree().change_scene_to_packed(level_1)
2:
get_tree().change_scene_to_packed(level_2)
_:
goto_main_menu()
func start_level() -> void:
equip_weapon(current_weapon)
func finish_level() -> void:
if current_level < 3:
end_screen_state = EndScreenState.LEVEL_CLEAR
else:
end_screen_state = EndScreenState.VICTORY
goto_end_screen()
func goto_end_screen() -> void:
audio_manager.stop_soundtrack()
var end_scene := preload("res://Scenes/EndOfLevel.tscn")
get_tree().change_scene_to_packed(end_scene)
func goto_main_menu() -> void:
var main_menu := preload("res://Scenes/MainMenu.tscn")
get_tree().change_scene_to_packed(main_menu)
func get_random_weapon() -> Dictionary:
var my_rng := RandomNumberGenerator.new()
my_rng.randomize()
var index := my_rng.randi() % len(weapon_list)
return weapon_list[index]