-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.gd
58 lines (40 loc) · 1.07 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
extends Node
export(PackedScene) var mob_scene
var score
func _ready():
randomize()
func game_over():
$Music.stop()
$DeathSound.play()
$ScoreTimer.stop()
$MobTimer.stop()
$HUD.show_game_over()
func new_game():
$Music.play()
get_tree().call_group("mobs", "queue_free")
score = 0
$Player.start($StartPosition.position)
# $Player/CollisionShape2D.disabled = true
$StartTimer.start()
$HUD.update_score(score)
$HUD.show_message("Get ready")
func _on_Player_hit():
game_over()
func _on_StartTimer_timeout():
$MobTimer.start()
$ScoreTimer.start()
func _on_ScoreTimer_timeout():
score += 1
$HUD.update_score(score)
func _on_MobTimer_timeout():
var mob = mob_scene.instance()
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.offset = randi()
var direction = mob_spawn_location.rotation + PI/2
direction += rand_range(-PI/4, PI/4)
mob.position = mob_spawn_location.position
mob.rotation = direction
mob.linear_velocity = Vector2(rand_range(150.0, 250.0), 0).rotated(direction)
add_child(mob)
func _on_HUD_start_game():
new_game()