-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.gd
60 lines (46 loc) · 1.37 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
extends Node
export(PackedScene) var fly_scene
var score
func _ready():
randomize()
func game_over():
$ScoreTimer.stop()
$FlyTimer.stop()
$HUD.show_game_over()
func game_won():
$ScoreTimer.stop()
$FlyTimer.stop()
$HUD.show_20_secs()
func new_game():
score = 0
$Player.start($StartPosition.position)
get_tree().call_group("mobs", "queue_free")
$StartTimer.start()
$HUD.update_score(score)
$HUD.show_message("Dodge the flies for 20 seconds")
func _on_FlyTimer_timeout():
# Create a new instance of the fly scene.
var fly = fly_scene.instance()
# Choose a random location on Path2D.
var fly_spawn_location = get_node("FlyPath/SpawnLocation")
fly_spawn_location.offset = randi()
# Set the fly's direction perpendicular to the path direction.
var direction = fly_spawn_location.rotation + PI / 2
# Set the fly's position to a random location.
fly.position = fly_spawn_location.position
# Add some randomness to the direction.
direction += rand_range(-PI / 4, PI / 4)
fly.rotation = direction
# Choose the velocity for the fly.
var velocity = Vector2(rand_range(150.0, 250.0), 0.0)
fly.linear_velocity = velocity.rotated(direction)
# Spawn the fly by adding it to the Main scene.
add_child(fly)
func _on_ScoreTimer_timeout():
score += 1
if score == 20:
game_won()
$HUD.update_score(score)
func _on_StartTimer_timeout():
$ScoreTimer.start()
$FlyTimer.start()