-
Notifications
You must be signed in to change notification settings - Fork 1
/
SpeedTimer.gd
52 lines (40 loc) · 1.02 KB
/
SpeedTimer.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
extends Node2D
onready var timer = $SpeedrunTimer
onready var label1 = $SpeedText
onready var label2 = $SpeedText2
onready var sound = $MusicLoop
onready var endsound = $success
var hours = 0
var minutes = 0
var seconds = 0
var milliseconds = 0
var started = false
func _ready():
timer.connect("timeout", self, "handle_second")
func _process(delta):
if not started:
return
milliseconds += delta * 1000
if milliseconds > 1000:
seconds += milliseconds / 1000
milliseconds = int(milliseconds) % 1000
if seconds > 59:
seconds = 0
minutes += 1
if minutes > 59:
minutes = 0
hours += 1
func handle_second():
label1.text = "%02d:%02d:%02d:%03d" % [hours, minutes, seconds, milliseconds]
label2.text = "%02d:%02d:%02d:%03d" % [hours, minutes, seconds, milliseconds]
func start():
print_debug("start timer")
started = true
if sound.playing:
return
sound.play()
func _on_Area2D_area_entered(area):
start() # Replace with function body.
func _on_RaceEndCollider_area_entered(area):
started = false
endsound.play()