-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.gd
149 lines (110 loc) · 3.88 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
extends Node2D
const MAX_SPEED = 1150
onready var rider = $rider
onready var track = $track
onready var ouch = $audio/ouch
onready var ouch2 = $audio/ouch2
onready var success = $audio/success
onready var wub1 = $audio/wub1
onready var wub2 = $audio/wub2
onready var wub3 = $audio/wub3
onready var wub4 = $audio/wub4
onready var wub5 = $audio/wub5
onready var lose_screen = $gui/lose_screen
onready var speed_label = $gui/stats/vbox/speed
onready var score_label = $gui/stats/vbox/score
onready var final_score_label = $gui/lose_screen/MarginContainer/VBoxContainer/final_score
onready var hearts = [
$gui/heart1,
$gui/heart2,
$gui/heart3
]
var segment_sounds
var t:float = 0
var score = 0
var health = 0
var current_segment:Segment
var last_segment:Segment
var offset = Vector2.ZERO
var last_up_segment:Segment
var do_loop_exit = false
var speed = 500
# Called when the node enters the scene tree for the first time.
func _ready():
current_segment = track.get_first_segment()
current_segment.color = Segment.COLOR_ACTIVE
for heart in hearts:
health += 1
segment_sounds = {
Segment.CURVE_RIGHT_UP: wub1,
Segment.CURVE_UP_LEFT: wub2,
Segment.CURVE_LEFT_DOWN: wub3,
#Segment.CURVE_DOWN_RIGHT: wub4,
Segment.STRAIGHT: wub5,
}
func lose_health():
if lose_screen.visible:
return
hearts[health-1].visible = false
health -= 1
if health < 0:
ouch2.play()
speed = 0
final_score_label.text = "Final Score: " + str(score)
lose_screen.visible = true
else:
ouch.play()
func _process(_delta):
t += speed * _delta
if t>=current_segment.get_baked_length():
t = 0
last_segment = current_segment
rider.space_sprite.visible = false
if current_segment.type_name == Segment.CURVE_RIGHT_UP: # we're exiting an CURVE_RIGHT_UP segment
last_up_segment = current_segment
if current_segment.type_name == Segment.CURVE_DOWN_RIGHT and do_loop_exit:
success.play()
score += round(current_segment.score_multi * speed)
speed += 25
speed = clamp(speed, 500, MAX_SPEED)
speed_label.text = "Speed: " + str(speed)
score_label.text = "Score: " + str(score)
if current_segment.type_name == Segment.CURVE_DOWN_RIGHT and not do_loop_exit:
current_segment.color = Segment.COLOR_IDLE
current_segment = last_up_segment
else:
current_segment = current_segment.next_segment
#current_segment = current_segment.next_segment
current_segment.prev_segment.color = Segment.COLOR_IDLE
current_segment.color = Segment.COLOR_ACTIVE
do_loop_exit = false
track.generate_segments()
track.clear_old_segments(rider.position.x - get_viewport_rect().size.x)
rider.draw_attention_circle(1)
if current_segment.type_name in segment_sounds:
segment_sounds[current_segment.type_name].play()
rider.position = current_segment.position + current_segment.interpolate_baked(t)
if last_segment:
last_segment.color = Segment.COLOR_ACTIVE.linear_interpolate(Segment.COLOR_IDLE, t / current_segment.get_baked_length())
current_segment.next_segment.color = Segment.COLOR_IDLE
if last_up_segment and last_up_segment != current_segment:
last_up_segment.color = Segment.COLOR_IDLE
if Input.is_action_just_pressed("change_route"):
if current_segment.type_name == Segment.CURVE_DOWN_RIGHT:
do_loop_exit = true
else:
if current_segment.type_name == Segment.STRAIGHT:
pass
else:
lose_health()
var interpol_color = Segment.COLOR_IDLE.linear_interpolate(Segment.COLOR_ACTIVE, t / current_segment.get_baked_length())
if current_segment.type_name == Segment.CURVE_DOWN_RIGHT and not do_loop_exit:
#rider.space_sprite.visible = true
rider.draw_attention_circle(t / current_segment.get_baked_length())
else:
rider.space_sprite.visible = false
#current_segment.next_segment.color = interpol_color
func _on_ok_button_pressed():
get_tree().reload_current_scene()
func _on_intro_hide_timer_timeout():
$gui/introduction.visible = false