-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.gd
75 lines (53 loc) · 1.48 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 Node2D
var enemy = preload("res://Enemy.tscn")
var speedUp = preload("res://SpeedUp.tscn")
var colors = [
Color(214/255.0, 214/255.0, 214/255.0),
Color(134/255.0, 103/255.0, 103/255.0),
Color(120/255.0, 159/255.0, 156/255.0),
Color(113/255.0, 104/255.0, 133/255.0)
];
func _ready():
get_tree().paused = false
randomize()
$SpawnTimer.wait_time = 1.2
setSpeedUpTimer()
spawn()
func setSpeedUpTimer():
$SpeedUpTimer.wait_time = randf() * 12
func spawn():
var node = enemy.instance()
node.position.x = randi() % 1120 + 80
add_child(node)
func _on_SpawnTimer_timeout():
spawn()
func endGame():
$GameOver.visible = true
get_tree().paused = true
$RestartGame.start()
func _on_RestartGame_timeout():
get_tree().reload_current_scene()
func increaseDifficulty():
$SpawnTimer.wait_time -= randf() * 0.05
if ($SpawnTimer.wait_time < 0.3):
$SpawnTimer.wait_time = 0.3
global.enemyBaseSpeed += randf()
if (global.enemyBaseSpeed > 650):
global.enemyBaseSpeed = 650
func _on_left_button_down():
$Player.changeMovement(-1, 0)
func _on_left_button_up():
$Player.changeMovement(1, 0)
func _on_right_button_down():
$Player.changeMovement(1, 0)
func _on_right_button_up():
$Player.changeMovement(-1, 0)
func _on_SpeedUpTimer_timeout():
var node = speedUp.instance()
node.position.x = randi() % 1120 + 80
add_child(node)
setSpeedUpTimer()
func removeSpeed():
$SpeedUpTimer.stop()
func _on_ColorChange_timeout():
$ColorRect.color = colors[randi() % colors.size()]