-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.gd
43 lines (29 loc) · 980 Bytes
/
Game.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
extends Node2D
var player_scene = load("res://characters/Player.tscn")
var is_game_over := false
func player_is_ded():
$AsteroidSpawner/SpawnTimer.stop()
$StarSpawner/StarTimer.stop()
for asteroid in get_tree().get_nodes_in_group("asteroids"):
if(!asteroid.is_queued_for_deletion() and asteroid.has_node("AudioStreamPlayer2D")):
asteroid.get_node("AudioStreamPlayer2D").stop()
$GameOverTimer.start()
print("Game Over")
func _unhandled_input(event: InputEvent):
if(is_game_over and event.is_action_released("restart_game")):
restart_game()
func respawn_player():
var player = player_scene.instance()
player.position = Vector2(626, 680)
add_child(player)
func undo_game_over():
$GameOverLabel.visible = false
func restart_game():
respawn_player()
undo_game_over()
is_game_over = false
$AsteroidSpawner/SpawnTimer.start()
$StarSpawner/StarTimer.start()
func _on_GameOverTimer_timeout():
$GameOverLabel.visible = true
is_game_over = true