-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame_scene.gd
More file actions
91 lines (74 loc) · 2.75 KB
/
Copy pathgame_scene.gd
File metadata and controls
91 lines (74 loc) · 2.75 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
extends Node2D
var asteroid_spawn: Resource = preload("res://scenes/asteroid_blueprint.tscn")
# Called when the node enters the scene tree for the first time.
var current_wait_time = 3;
var difficulty_wait_timer = 1;
var time = 0
var difficulty = 0
func _ready() -> void:
$Timer.wait_time = current_wait_time
$Difficulty.wait_time = difficulty_wait_timer
$Timer.start()
$Timer.autostart = true
$Difficulty.start()
$Difficulty.autostart = true
pass # Replace with function body.
var directions = [0,1,2,3] #up, down, left, right
var asteroids_count = [1,1,1,1,2,2,2,2,3,3]
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func toggle_gameover() -> void:
get_tree().paused = true
$gameover_window.visible = true
$gameover_window/final_score.text = "Final Score: " + str(time)
$gameover_window/difficulty_score.text = "Difficulty: " + str(difficulty + 1)
$gameover_window.process_mode = Node.PROCESS_MODE_ALWAYS
pass
func _on_timer_timeout() -> void:
var rng = randi_range(0,3)
#if rng != 0:
#return
rng = asteroids_count.pick_random() #number of asteroids
var directions_copy = directions.duplicate()
directions_copy.shuffle()
for i in range(rng):
send_asteroids(directions_copy[i])
$Timer.wait_time = randf_range(current_wait_time-0.2, current_wait_time+0.2)
#SETTING LOCATION AND MOVEMENT
pass # Replace with function body.
func send_asteroids(n: int):
var location: Vector2 = Vector2()
var asteroid_instance: Node = asteroid_spawn.instantiate()
asteroid_instance.connect("toggle_gameover", toggle_gameover)
add_child(asteroid_instance)
if n == 0: #up
location = Vector2(get_viewport().size.x/2, 0)
asteroid_instance.direction = Vector2.DOWN
elif n == 1: #down
location = Vector2(get_viewport().size.x/2, get_viewport().size.y)
asteroid_instance.direction = Vector2.UP
elif n == 2: #left
location = Vector2(0, get_viewport().size.y/2)
asteroid_instance.direction = Vector2.RIGHT
else: #right
location = Vector2(get_viewport().size.x, get_viewport().size.y/2)
asteroid_instance.direction = Vector2.LEFT
asteroid_instance.set_position(location)
func _on_audio_stream_player_finished() -> void:
$backgroundmusic.play()
pass # Replace with function body.
func _on_score_timeout() -> void:
time += 1
$score_label.text = "Score: " + str(time)
pass # Replace with function body.
func _on_difficulty_timeout() -> void:
if difficulty != 5:
difficulty += 1
current_wait_time -= 0.5
$Timer.wait_time = current_wait_time
print("Difficulty is now " + str(difficulty) + " with wait time " + str($Timer.wait_time))
pass # Replace with function body.
func _on_back_button_pressed() -> void:
get_tree().change_scene_to_file("res://title.tscn")
pass # Replace with function body.