-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.gd
More file actions
128 lines (103 loc) · 3.32 KB
/
main.gd
File metadata and controls
128 lines (103 loc) · 3.32 KB
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
extends Node
const LEVELS := [
"res://Maps/Level1/level_1.tscn",
"res://Maps/Level2/level_2.tscn",
"res://Maps/Level3/level_3.tscn",
"res://Maps/Level4/level_4.tscn",
"res://Maps/Level5/level_5.tscn",
"res://Maps/BossLevel/boss_level.tscn",
]
@onready var player = $Player
@onready var player_start_position: Vector3 = player.global_position
@onready var terminal_window = %TerminalWindow
@onready var camera_3d = %Camera3D
@onready var interpolated_camera_3d = %InterpolatedCamera3D
var node_being_hacked
var current_level_path
var level
func _ready():
await get_tree().create_timer(0.3).timeout
%MainMenu.setup_level_menu(LEVELS)
show_main_menu()
func show_main_menu():
player.is_playing = false
%MainMenu.show_menu()
func _on_main_menu_level_selected(path):
%MainMenu.hide_menu()
load_level(path)
func load_level(path):
var packed_scene = load(path)
if packed_scene == null or not packed_scene is PackedScene:
return
current_level_path = path
if level != null:
remove_child(level)
level.queue_free()
level = packed_scene.instantiate()
level.name = "Level"
add_child(level)
level.root_node_hacked.connect(self._on_root_node_hacked)
player.reset_player()
player.global_position = player_start_position
player.is_playing = true
%HealthLabel.text = str(player.health)
snap_camera()
func unload_level():
if level != null:
remove_child(level)
level.queue_free()
level = null
player.reset_player()
player.global_position = player_start_position
%HealthLabel.text = str(player.health)
snap_camera()
func snap_camera():
camera_3d.make_current()
await get_tree().process_frame
interpolated_camera_3d.global_position = camera_3d.global_position
interpolated_camera_3d.make_current()
func _on_player_hack_activated(node):
if not node_being_hacked:
if not node.is_hacked and node.check_hackable():
node_being_hacked = node
terminal_window.activate_terminal(node_being_hacked.security_remaining)
else:
$Player.hack_failed()
func _on_player_player_moved():
if node_being_hacked:
terminal_window.deactivate_terminal()
node_being_hacked = null
func _on_player_player_hurt():
%HealthLabel.text = str(player.health)
if node_being_hacked:
terminal_window.deactivate_terminal()
node_being_hacked = null
func _on_terminal_window_security_reduced(remaining):
if node_being_hacked:
node_being_hacked.hack(remaining)
func _on_terminal_window_terminal_completed():
node_being_hacked = null
func _on_root_node_hacked():
player.is_playing = false
var index = LEVELS.find(current_level_path)
index += 1
if index >= LEVELS.size():
%AcceptMenu.show_accept_menu("CONGRATULATIONS!\nYou have HACKED UP.\nAll their systems now belong to us.", "", "Return to main menu")
else:
%AcceptMenu.show_accept_menu("You hacked the root node!", "Advance to next vector", "Return to main menu")
func _on_player_player_died():
player.is_playing = false
%AcceptMenu.show_accept_menu("Your feeble system intrusion was stopped by the network's defenses.", "Retry current attack vector", "Return to main menu")
func _on_accept_menu_ok_pressed():
if player.is_dead:
load_level(current_level_path)
else:
# Figure out the next level
var index = LEVELS.find(current_level_path)
index += 1
if index >= LEVELS.size():
index = 0
load_level(LEVELS[index])
func _on_accept_menu_cancel_pressed():
unload_level()
show_main_menu()