-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.gd
75 lines (56 loc) · 1.7 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
64
65
66
67
68
69
70
71
72
73
74
75
extends Node
@export var mob_scene: PackedScene
var score
var play_music = false
var spawn_mob = true
var max_mob_count = 20
var mob_count = 0
func game_over():
get_tree().call_group("mobs", "queue_free")
mob_count = 0
$MobTimer.stop()
$GUI.show_game_over()
$Music.stop()
func new_game():
score = 0
$Player.start($StartPosition.position)
$StartTimer.start()
$GUI.update_score(score)
$GUI.show_message("Have Fun!")
if play_music:
$Music.play()
func _on_player_fire(Bullet, direction, location):
var spawned_bullet = Bullet.instantiate()
add_child(spawned_bullet)
spawned_bullet.rotation = direction
spawned_bullet.position = location
#rotate the bullet's velocity vector to point in the direction the ship is facing
spawned_bullet.velocity = spawned_bullet.velocity.rotated(direction)
# every time the mob timer runs out, generate a new mob entity
func _on_mob_timer_timeout():
if spawn_mob and mob_count < max_mob_count:
var mob = mob_scene.instantiate()
var mob_spawn_location = get_node("MobPath/MobSpawnLocation")
mob_spawn_location.progress_ratio = randf()
var direction = mob_spawn_location.rotation + PI / 2
mob.position = mob_spawn_location.position
direction += randf_range(-PI / 4, PI / 4)
#mob.rotation = direction
var velocity = Vector2(randf_range(150.0, 150.0), 0.0)
mob.linear_velocity = velocity.rotated(direction)
mob.connect("killed", killed)
add_child(mob)
mob_count = mob_count + 1
func killed():
$EnemyDead.play()
mob_count = mob_count - 1
score += 1
$GUI.update_score(score)
func _on_start_timer_timeout():
$MobTimer.start()
func _on_hud_mute_music():
play_music = not play_music
if not play_music:
$Music.stop()
else:
$Music.play()