-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMain.gd
63 lines (45 loc) · 1.79 KB
/
Main.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
extends Node2D
const Player = preload("res://actors/Player.tscn")
const GameOverScreen = preload("res://UI/GameOverScreen.tscn")
const PauseScreen = preload("res://UI/PauseScreen.tscn")
onready var capturable_base_manager = $CapturableBaseManager
onready var ally_ai = $AllyMapAI
onready var enemy_ai = $EnemyMapAI
onready var bullet_manager = $BulletManager
onready var camera = $Camera2D
onready var gui = $GUI
onready var ground = $Ground
onready var pathfinding = $Pathfinding
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
randomize()
GlobalSignals.connect("bullet_fired", bullet_manager, "handle_bullet_spawned")
var ally_respawns = $AllyRespawnPoints
var enemy_respawns = $EnemyRespawnPoints
pathfinding.create_navigation_map(ground)
var bases = capturable_base_manager.get_capturable_bases()
ally_ai.initialize(bases, ally_respawns.get_children(), pathfinding)
enemy_ai.initialize(bases, enemy_respawns.get_children(), pathfinding)
capturable_base_manager.connect("player_captured_all_bases", self, "handle_player_win")
capturable_base_manager.connect("player_lost_all_bases", self, "handle_player_lost")
spawn_player()
func spawn_player():
var player = Player.instance()
add_child(player)
player.set_camera_transform(camera.get_path())
player.connect("died", self, "spawn_player")
gui.set_player(player)
func handle_player_win():
var game_over = GameOverScreen.instance()
add_child(game_over)
game_over.set_title(true)
get_tree().paused = true
func handle_player_lost():
var game_over = GameOverScreen.instance()
add_child(game_over)
game_over.set_title(false)
get_tree().paused = true
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("pause"):
var pause_menu = PauseScreen.instance()
add_child(pause_menu)