-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.gd
615 lines (505 loc) · 21.8 KB
/
level.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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
class_name Level
extends Node2D
const MUSIC_BPM := 160.0
const MIN_ORBIT_DISTANCE := 50.0
const MAX_ORBIT_DISTANCE := 1500.0
const ENEMY_FIRE_RATE := 2.0
const PLAYER_FIRE_RATE := MUSIC_BPM / 60.0
const HEALTH_PICKUP_AMOUNT := 0.2
const FUEL_PICKUP_AMOUNT := 1.0
const BULLET_LIFETIME = 6.0
const BULLET_SPEED := 350.0
const PLANET_ENEMY_COLOR := Color("806787")
const PLANET_PLAYER_COLOR := Color("678784")
const GRAVITY := 9.8
const ENEMY_DAMAGE := 0.17
const PLANET_DAMAGE := 0.17
const PLAYER_DAMAGE_COOLDOWN := 8.0
const PLANET_BOUNCE_SPEED := 300.0
var planets_captured := 0
var current_time := 0.0
var confirm_restart := false
@onready var player: Player = $Player
@onready var bullet_scene := preload("res://bullet.tscn")
@onready var planet_scene := preload("res://planet.tscn")
@onready var fuel_scene := preload("res://fuel.tscn")
@onready var health_scene := preload("res://health.tscn")
@onready var moon_scene := preload("res://moon.tscn")
@onready var enemy_scene := preload("res://enemy.tscn")
var planet_textures: Array[Texture2D] = [
preload("res://planet_1.png"),
preload("res://planet_2.png"),
preload("res://planet_3.png"),
preload("res://planet_4.png"),
preload("res://planet_5.png"),
]
@onready var bars: Control = $CanvasLayer/Bars
@onready var health_bar: Panel = $CanvasLayer/Bars/Health
@onready var health_bar_fill: Panel = $CanvasLayer/Bars/Health/Fill
@onready var boost_bar: Panel = $CanvasLayer/Bars/Boost
@onready var boost_bar_fill: Panel = $CanvasLayer/Bars/Boost/Fill
@onready var enemy_planet_indicator: Control = $CanvasLayer/EnemyPlanetIndicator
@onready var enemy_planet_indicator_text: Control = $CanvasLayer/EnemyPlanetIndicator/Text
@onready var enemy_planet_indicator_label: Label = $CanvasLayer/EnemyPlanetIndicator/Text/Label
@onready var enemy_planet_indicator_arrow: Control = $CanvasLayer/EnemyPlanetIndicator/Arrow
@onready var planets_captured_label_bottom_right: Label = $CanvasLayer/PlanetsCapturedLabelBottomRight
@onready var planets_captured_label_center: Label = $CanvasLayer/PlanetsCapturedLabelCenter
@onready var planet_captured_label: Label = $CanvasLayer/PlanetCapturedLabel
@onready var speed_up_button: Button = $CanvasLayer/SpeedUpButton
@onready var pause_button: Button = $CanvasLayer/PauseButton
@onready var paused_control: Control = $CanvasLayer/Paused
@onready var play_button: Button = $CanvasLayer/Paused/PlayButton
@onready var restart_button: Button = $CanvasLayer/RestartButton
@onready var game_over_label: Label = $CanvasLayer/GameOverLabel
@onready var pause_menu_restart_button: Button = $CanvasLayer/Paused/RestartButton
@onready var bullets: Node2D = $Bullets
@onready var game_over_asp: AudioStreamPlayer = $GameOverASP
@onready var planet_captured_asp: AudioStreamPlayer = $PlanetCapturedASP
@onready var enemy_planet_asp: AudioStreamPlayer = $EnemyPlanetASP
@onready var speed_up_asp: AudioStreamPlayer = $SpeedUpASP
@onready var graphics_low_button: Button = $CanvasLayer/Paused/Settings/Graphics/Low
@onready var graphics_high_button: Button = $CanvasLayer/Paused/Settings/Graphics/High
@onready var vsync_off_button: Button = $CanvasLayer/Paused/Settings/Vsync/Off
@onready var vsync_on_button: Button = $CanvasLayer/Paused/Settings/Vsync/On
func _ready() -> void:
apply_graphics_quality()
speed_up_asp.play()
var start_planet := create_planet()
set_planet_to_player(start_planet)
var player_planet_r := start_planet.circle.radius + 1000.0
player.global_position = start_planet.global_position + Vector2(player_planet_r, 0.0)
var player_orbital_speed := sqrt(GRAVITY * start_planet.mass / player_planet_r)
player.linear_velocity = Vector2(0.0, player_orbital_speed)
pause_button.button_down.connect(on_pause_button_down)
play_button.button_down.connect(on_play_button_down)
restart_button.button_down.connect(on_restart_button_down)
pause_menu_restart_button.button_down.connect(on_pause_menu_restart_button_down)
graphics_low_button.button_down.connect(on_graphics_low_button_pressed)
graphics_high_button.button_down.connect(on_graphics_high_button_pressed)
vsync_off_button.button_down.connect(on_vsync_off_button_pressed)
vsync_on_button.button_down.connect(on_vsync_on_button_pressed)
if global.main.graphics_high:
graphics_low_button.modulate.v = 0.6
graphics_high_button.modulate.v = 1.0
else:
graphics_low_button.modulate.v = 1.0
graphics_high_button.modulate.v = 0.6
if global.main.vsync:
vsync_off_button.modulate.v = 0.6
vsync_on_button.modulate.v = 1.0
else:
vsync_off_button.modulate.v = 1.0
vsync_on_button.modulate.v = 0.6
get_tree().create_timer(2.0).timeout.connect(create_enemy_planet)
update_world_volume()
for line: Line2D in player.exhaust_lines.get_children():
line.clear_points()
line.modulate = Main.PLAYER_COLORS[0]
line.modulate.a = 0.2
func create_planet() -> Planet:
var planet: Planet = planet_scene.instantiate()
var sprite: Sprite2D = planet.get_node("Sprite2D")
sprite.texture = planet_textures.pick_random()
add_child(planet)
var dir := Vector2.from_angle(randf_range(-0.25, 0.25) * TAU)
var distance := randf_range(15000.0, 20000.0)
planet.global_position = player.global_position + dir * distance
planet.body_entered.connect(on_planet_body_entered.bind(planet))
if planets_captured > 2:
var moon: Moon = moon_scene.instantiate()
add_child(moon)
moon.planet = planet
moon.planet_theta = randf_range(0.0, TAU)
moon.planet_r = planet.circle.radius + moon.circle.radius + randf_range(MIN_ORBIT_DISTANCE, MAX_ORBIT_DISTANCE)
moon.position = moon.planet.position + Vector2.from_angle(moon.planet_theta) * moon.planet_r
moon.body_entered.connect(on_planet_body_entered.bind(moon))
planet.moon = moon
return planet
func create_enemy_planet() -> void:
var planet := create_planet()
var enemies := mini(planets_captured + 1, 5)
for i in enemies:
var enemy: Enemy = enemy_scene.instantiate()
enemy.planet = planet
enemy.planet_theta = randf_range(0.0, TAU)
enemy.planet_r = planet.circle.radius + randf_range(MIN_ORBIT_DISTANCE, MAX_ORBIT_DISTANCE)
enemy.position = enemy.planet.position + Vector2.from_angle(enemy.planet_theta) * enemy.planet_r
add_child(enemy)
enemy.exhaust_line.clear_points()
enemy.exhaust_line.modulate = Main.ENEMY_COLORS[0]
enemy.exhaust_line.modulate.a = 0.2
apply_enemy_graphics_quality(enemy)
var scene: PackedScene = [fuel_scene, health_scene].pick_random()
var pickup: Area2D = scene.instantiate()
add_child(pickup)
var pickup_dir := Vector2.from_angle(randf_range(0.0, TAU))
var pickup_dist := planet.circle.radius + randf_range(500.0, 2000.0)
pickup.global_position = planet.global_position + pickup_dir * pickup_dist
pickup.body_entered.connect(on_pickup_body_entered.bind(pickup))
update_enemy_planet_indicator()
enemy_planet_indicator.visible = true
func _physics_process(delta: float) -> void:
current_time += delta
physics_process_player(delta)
physics_process_planets(delta)
physics_process_bullets(delta)
physics_process_enemy(delta)
physics_process_ui()
func physics_process_player(delta) -> void:
if player.alive:
var mouse_global_position := player.camera.global_position - player.camera.get_viewport_rect().size / 2.0 + get_viewport().get_mouse_position()
var max_torque := 200000.0
var kp := 5.0
var kd := 2.0
var angle := player.get_angle_to(mouse_global_position)
var desired_torque := max_torque * (kp * angle + kd * -player.angular_velocity)
var actual_torque := clampf(desired_torque, -max_torque, max_torque)
player.apply_torque(actual_torque)
var thrust := 200.0
var thrusting := player.alive and Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT) and not speed_up_button.button_pressed
if thrusting:
player.apply_central_force(player.transform.x * thrust)
for p: GPUParticles2D in player.exhaust.get_children():
p.emitting = thrusting
var boost_m := -0.01 if thrusting else 0.0
player.boost = clampf(player.boost + boost_m * delta, 0.0, 1.0)
if player.boost == 0.0 and player.alive:
kill_player()
player.thrust_asp.stream_paused = not thrusting
if not player.exploded:
for planet: Planet in get_tree().get_nodes_in_group("planets"):
var v := planet.global_position - player.global_position
var d := v.normalized()
var r := v.length()
player.apply_central_force(d * GRAVITY * player.mass * planet.mass / (r ** 2.0))
for i in player.exhaust_lines.get_child_count():
var line: Line2D = player.exhaust_lines.get_child(i)
if speed_up_button.button_pressed or not global.main.graphics_high:
line.clear_points()
else:
var point: Node2D = player.exhaust_points.get_child(i)
line.add_point(point.global_position)
if line.points.size() > 200:
line.remove_point(0)
if current_time - player.last_fired_at >= 1.0 / PLAYER_FIRE_RATE and player.alive:
player.last_fired_at = current_time
var bullet: Bullet = bullet_scene.instantiate()
bullet.position = player.shoot_particles.global_position
bullet.velocity = player.linear_velocity + player.transform.x * BULLET_SPEED
bullet.body_entered.connect(on_bullet_body_entered.bind(bullet))
bullet.area_entered.connect(on_bullet_area_entered.bind(bullet))
bullet.created_at = current_time
bullet.source = Bullet.Source.PLAYER
bullets.add_child(bullet)
bullet.line.clear_points()
bullet.line.modulate = Main.PLAYER_COLORS[0]
bullet.line.modulate.a = 0.1
bullet.sprite.modulate = Main.PLAYER_COLORS[0]
player.shoot_asp.play()
player.shoot_particles.restart()
player.shoot_particles.emitting = true
var damage_cooldown := current_time - player.last_hit_at < PLAYER_DAMAGE_COOLDOWN
if damage_cooldown and player.alive:
if fmod(current_time, 0.2) < 0.1:
player.modulate.a = 0.3
else:
player.modulate.a = 1.0
else:
player.modulate.a = 1.0
func physics_process_planets(delta: float) -> void:
for planet: Planet in get_tree().get_nodes_in_group("planets"):
planet.rotation += delta * TAU / 100.0
func physics_process_bullets(delta: float) -> void:
for bullet: Bullet in get_tree().get_nodes_in_group("bullets"):
for planet: Planet in get_tree().get_nodes_in_group("planets"):
var v := planet.global_position - bullet.global_position
var d := v.normalized()
var r := v.length()
bullet.velocity += d * GRAVITY * planet.mass / (r ** 2.0) * delta
bullet.position += bullet.velocity * delta
if current_time - bullet.created_at > BULLET_LIFETIME:
bullet.queue_free()
# Optimization - perf testing proved this is important
if speed_up_button.button_pressed or not global.main.graphics_high:
bullet.line.clear_points()
else:
bullet.line.add_point(bullet.global_position)
if bullet.line.points.size() > 30:
bullet.line.remove_point(0)
func physics_process_enemy(delta: float) -> void:
for enemy: Enemy in get_tree().get_nodes_in_group("enemies"):
if not enemy.alive:
continue
# Speed is velocity required for circular orbit
var speed := sqrt(GRAVITY * enemy.planet.mass / enemy.planet_r)
enemy.planet_theta += atan2(enemy.planet_r, 0.0) - atan2(enemy.planet_r, speed * delta)
var last_position := enemy.position
enemy.position = enemy.planet.position + Vector2.from_angle(enemy.planet_theta) * enemy.planet_r
var velocity := (enemy.position - last_position) / delta
# Optimization - perf testing proved this is important
if speed_up_button.button_pressed or not global.main.graphics_high:
enemy.exhaust_line.clear_points()
else:
enemy.exhaust_line.add_point(enemy.global_position)
if enemy.exhaust_line.points.size() > 200:
enemy.exhaust_line.remove_point(0)
if not player.exploded:
var fire_rate := ENEMY_FIRE_RATE
if current_time - enemy.last_fired_at >= 1.0 / fire_rate:
enemy.shoot_asp.play()
enemy.last_fired_at = current_time
var bullet: Bullet = bullet_scene.instantiate()
bullet.position = enemy.position
var player_angle := enemy.position.angle_to_point(player.position)
var spray := 0.05 * sin(current_time) * TAU
var spread := 0.02 * randf_range(-1.0, 1.0) * TAU
var bullet_angle := player_angle + spray + spread
enemy.rotation = bullet_angle
var bullet_dir := Vector2.from_angle(bullet_angle)
bullet.velocity = velocity + bullet_dir * BULLET_SPEED
bullet.body_entered.connect(on_bullet_body_entered.bind(bullet))
bullet.area_entered.connect(on_bullet_area_entered.bind(bullet))
bullet.created_at = current_time
bullet.source = Bullet.Source.ENEMY
bullets.add_child(bullet)
bullet.line.clear_points()
bullet.line.modulate = Main.ENEMY_COLORS[0]
bullet.line.modulate.a = 0.1
bullet.sprite.modulate = Main.ENEMY_COLORS[0]
bullet.line.visible = true
enemy.shoot_particles.restart()
enemy.shoot_particles.emitting = true
func physics_process_ui() -> void:
health_bar_fill.size.x = health_bar.size.x * player.health
boost_bar_fill.size.x = boost_bar.size.x * player.boost
update_enemy_planet_indicator()
speed_up_asp.stream_paused = not speed_up_button.button_pressed
if speed_up_button.button_pressed and player.alive:
Engine.time_scale = 10.0
Engine.physics_ticks_per_second = 600
Engine.max_physics_steps_per_frame = 80
else:
Engine.time_scale = 1.0
Engine.physics_ticks_per_second = 60
Engine.max_physics_steps_per_frame = 8
func _input(event: InputEvent) -> void:
var z := player.camera.zoom.x
if event is InputEventPanGesture:
var g := event as InputEventPanGesture
z += z * g.delta.y * 0.05
elif event.is_action("scroll_up"):
z *= 0.8
elif event.is_action("scroll_down"):
z *= 1.2
z = clampf(z, 0.1, 2.0)
player.camera.zoom = Vector2(z, z)
update_world_volume()
func update_world_volume() -> void:
var vol := remap(player.camera.zoom.x, 0.1, 2.0, -5.0, 0.0)
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("World"), vol)
func on_bullet_area_entered(area: Area2D, bullet: Bullet) -> void:
if area is Planet or area is Moon:
bullet.queue_free()
if area is Enemy and bullet.source == Bullet.Source.PLAYER:
var enemy: Enemy = area
if not enemy.alive:
return
bullet.queue_free()
enemy.alive = false
enemy.sprite.visible = false
enemy.exhaust_line.visible = false
enemy.explosion_asp.finished.connect(enemy.queue_free)
enemy.explosion_asp.play()
for p: GPUParticles2D in enemy.explosion_particles.get_children():
p.emitting = true
get_tree().create_timer(10.0).timeout.connect(enemy.queue_free)
if planet_has_living_enemy(enemy.planet):
return
# Need to get a reference to the planet because the enemy will be freed
var planet = enemy.planet
if not player.alive:
return
enemy_planet_indicator.visible = false
planet_captured_asp.play()
# It takes 1.7 seconds to reach the "climax" of the planet captured
# sound effect
await get_tree().create_timer(1.7).timeout
if not player.alive:
return
set_planet_to_player(planet)
planets_captured += 1
planet_captured_label.visible = true
planets_captured_label_bottom_right.text = "PLANETS CAPTURED: %s" % planets_captured
planets_captured_label_bottom_right.visible = true
await get_tree().create_timer(2.0).timeout
if not player.alive:
return
create_enemy_planet()
planet_captured_label.visible = false
func planet_has_living_enemy(planet: Planet) -> bool:
for enemy: Enemy in get_tree().get_nodes_in_group("enemies"):
if enemy.alive and enemy.planet == planet:
return true
return false
func on_bullet_body_entered(body: Node2D, bullet: Bullet) -> void:
if body is Player and bullet.source == Bullet.Source.ENEMY and not player.exploded:
player.hit_asp.play()
var damage_cooldown := current_time - player.last_hit_at < PLAYER_DAMAGE_COOLDOWN
if not damage_cooldown and player.alive:
player.last_hit_at = current_time
player.health = maxf(player.health - ENEMY_DAMAGE, 0.0)
if player.health == 0.0:
kill_player()
bullet.queue_free()
func on_planet_body_entered(body: Node2D, planet: Node2D) -> void:
if body is Player and not player.exploded:
player.hit_asp.play()
var damage_cooldown := current_time - player.last_hit_at < PLAYER_DAMAGE_COOLDOWN
if not damage_cooldown and player.alive:
player.last_hit_at = current_time
player.health = maxf(player.health - PLANET_DAMAGE, 0.0)
if player.health == 0.0:
kill_player()
var dir := planet.global_position.direction_to(player.global_position)
player.linear_velocity = dir * PLANET_BOUNCE_SPEED
func kill_player() -> void:
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Music"), -40.0)
player.alive = false
planets_captured_label_bottom_right.visible = false
planet_captured_label.visible = false
pause_button.visible = false
speed_up_button.visible = false
enemy_planet_indicator.visible = false
player.health = 0.0
player.boost = 0.0
player.alarm_asp.play()
player.angular_velocity = TAU * 0.6
await get_tree().create_timer(0.5).timeout
player.explosion_asp.play()
# It takes 1.65 seconds for the explosion sound effect to reach the climax
await get_tree().create_timer(1.65).timeout
for p: GPUParticles2D in player.explosion_particles.get_children():
p.emitting = true
bars.visible = false
player.exploded = true
player.sprite.visible = false
player.exhaust.visible = false
player.exhaust_lines.visible = false
player.alarm_asp.stop()
# Slow down camera to a stop
player.linear_damp = 2.0
await get_tree().create_timer(1.0).timeout
game_over_label.visible = true
restart_button.visible = true
planets_captured_label_center.text = "PLANETS CAPTURED: %s" % planets_captured
planets_captured_label_center.visible = true
game_over_asp.play()
# https://en.wikipedia.org/wiki/Ellipse#Polar_form_relative_to_center
func get_ellipse_r(theta: float, size: Vector2) -> float:
var a := size.x / 2.0
var b := size.y / 2.0
return a * b / sqrt((b * cos(theta)) ** 2.0 + (a * sin(theta)) ** 2.0)
func on_pickup_body_entered(body: RigidBody2D, pickup: Variant):
if not body is Player or not player.alive:
return
if pickup is Health:
player.health_pickup_asp.play()
player.health += HEALTH_PICKUP_AMOUNT
player.health = clampf(player.health, 0.0, 1.0)
else:
player.fuel_pickup_asp.play()
player.boost += FUEL_PICKUP_AMOUNT
player.boost = clampf(player.boost, 0.0, 1.0)
pickup.queue_free()
func on_pause_button_down() -> void:
get_tree().paused = true
paused_control.visible = true
global.interface_asp.play()
func on_play_button_down() -> void:
get_tree().paused = false
paused_control.visible = false
confirm_restart = false
pause_menu_restart_button.text = "RESTART"
global.interface_asp.play()
func on_restart_button_down() -> void:
get_tree().paused = false
get_tree().reload_current_scene()
AudioServer.set_bus_volume_db(AudioServer.get_bus_index("Music"), -20.0)
global.interface_asp.play()
func on_pause_menu_restart_button_down() -> void:
global.interface_asp.play()
if confirm_restart:
get_tree().paused = false
get_tree().reload_current_scene()
else:
confirm_restart = true
pause_menu_restart_button.text = "REALLY?"
func set_planet_to_player(planet: Planet) -> void:
planet.enemy = false
set_color_to_player(planet)
if planet.moon:
set_color_to_player(planet.moon)
func set_color_to_player(node: Node) -> void:
var sprite: Sprite2D = node.get_node("Sprite2D")
var shader: ShaderMaterial = sprite.material
shader.set_shader_parameter("shiftHue", -0.26)
func update_enemy_planet_indicator() -> void:
var nearest_enemy_planet: Planet
for planet: Planet in get_tree().get_nodes_in_group("planets"):
if not planet.enemy:
continue
if not nearest_enemy_planet:
nearest_enemy_planet = planet
continue
var d1 := planet.global_position.distance_to(player.global_position)
var d2 := nearest_enemy_planet.global_position.distance_to(player.global_position)
if d1 < d2:
nearest_enemy_planet = planet
if nearest_enemy_planet:
var dir := player.global_position.direction_to(nearest_enemy_planet.global_position)
var ellipse_size := get_viewport_rect().size * Vector2(0.7, 0.8)
var theta := dir.angle()
var r := get_ellipse_r(theta, ellipse_size)
var viewport_center := get_viewport_rect().size / 2.0
enemy_planet_indicator_text.position = viewport_center + dir * r
var dist := player.global_position.distance_to(nearest_enemy_planet.global_position)
enemy_planet_indicator_label.text = "ENEMY PLANET %s Mm" % round(dist / 1000.0)
var ellipse_2_size := enemy_planet_indicator_label.size * Vector2(1.2, 3.0)
var r_2 := get_ellipse_r(theta, ellipse_2_size)
var p := enemy_planet_indicator_text.position
enemy_planet_indicator_arrow.position = p + dir * r_2
enemy_planet_indicator_arrow.rotation = theta
func apply_graphics_quality() -> void:
var mode := Node.PROCESS_MODE_INHERIT if global.main.graphics_high else Node.PROCESS_MODE_DISABLED
player.shoot_particles.visible = global.main.graphics_high
player.shoot_particles.process_mode = mode
player.exhaust.visible = global.main.graphics_high
player.exhaust.process_mode = mode
player.explosion_particles.visible = global.main.graphics_high
player.explosion_particles.process_mode = mode
for enemy: Enemy in get_tree().get_nodes_in_group("enemies"):
apply_enemy_graphics_quality(enemy)
func apply_enemy_graphics_quality(enemy: Enemy) -> void:
var mode := Node.PROCESS_MODE_INHERIT if global.main.graphics_high else Node.PROCESS_MODE_DISABLED
enemy.shoot_particles.visible = global.main.graphics_high
enemy.shoot_particles.process_mode = mode
enemy.explosion_particles.visible = global.main.graphics_high
enemy.explosion_particles.process_mode = mode
func on_graphics_low_button_pressed() -> void:
graphics_low_button.modulate.v = 1.0
graphics_high_button.modulate.v = 0.6
global.main.on_graphics_low_button_pressed()
apply_graphics_quality()
func on_graphics_high_button_pressed() -> void:
graphics_low_button.modulate.v = 0.6
graphics_high_button.modulate.v = 1.0
global.main.on_graphics_high_button_pressed()
apply_graphics_quality()
func on_vsync_off_button_pressed() -> void:
global.main.on_vsync_off_button_pressed()
vsync_off_button.modulate.v = 1.0
vsync_on_button.modulate.v = 0.6
func on_vsync_on_button_pressed() -> void:
global.main.on_vsync_on_button_pressed()
vsync_off_button.modulate.v = 0.6
vsync_on_button.modulate.v = 1.0