-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.gd
54 lines (36 loc) · 1.01 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
extends Node
export (PackedScene) var mob_scene
var score = 0
func new_game():
score = 0
$HUD.update_score(score)
get_tree().call_group("mobs", "queue_free")
$Player.start($StartPosition.position)
$StartTimer.start()
$Music.play()
$HUD.show_message("Get Ready..")
yield($StartTimer, "timeout")
$ScoreTimer.start()
$MobTimer.start()
func game_over():
$ScoreTimer.stop()
$MobTimer.stop()
$HUD.show_game_over()
$Music.stop()
$DeathSound.play()
func _ready():
randomize()
func _on_MobTimer_timeout():
var mob_spawn_location = $MobPath/MobSpawnLocation
mob_spawn_location.unit_offset = randf()
var mob = mob_scene.instance()
add_child(mob)
mob.position = mob_spawn_location.position
var direction = mob_spawn_location.rotation + PI / 2
direction += rand_range(-PI /4, PI / 4)
mob.rotation = direction
var velocity = Vector2(rand_range(mob.min_speed, mob.max_speed), 0)
mob.linear_velocity = velocity.rotated(direction)
func _on_ScoreTimer_timeout():
score += 1
$HUD.update_score(score)