-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFightstick.gd
More file actions
79 lines (65 loc) · 1.34 KB
/
Fightstick.gd
File metadata and controls
79 lines (65 loc) · 1.34 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
extends Node2D
var current = [0, 0]
var top_notes = {
1: 'F',
2: 'F#',
3: 'E',
4: 'C',
5: 'D',
6: 'D#',
7: 'C#'
}
var bottom_notes = {
1: 'A#',
2: 'B',
3: 'A',
4: 'G',
6: 'G#'
}
func _ready():
if OS.has_touchscreen_ui_hint():
$HelpText.visible = false
func _input(event):
if event is InputEventKey and event.scancode == KEY_H:
$Help.visible = event.is_pressed()
func play():
var pitch = 4
var note
$Toot.pitch_scale = 1
if current[0] != 0:
note = top_notes.get(current[0])
elif current[1] != 0:
note = bottom_notes.get(current[1])
if note == null:
return
if $Stick/Up.pressed:
pitch += 1
if $Stick/Down.pressed:
pitch -= 1
# We don't actually have wavs for C3.
if 'C' in note and pitch == 3:
pitch += 1
$Toot.pitch_scale = .5
if '#' in note:
note = '%s%s#' % [note[0], pitch]
else:
note = '%s%s' % [note[0], pitch]
$Toot.stream = load('res://trumpet/%s.wav' % note)
$Toot.play()
# Cut the toots short.
$Toot/Timer.start()
func _on_Timer_timeout():
$Toot.stop()
func _fingering():
current = [0, 0]
var n = 0
for row in [$Top, $Bottom]:
for i in range(row.get_child_count()):
if row.get_child(i).pressed:
current[n] += int(pow(2, i))
n += 1
play()
func _on_Button_pressed():
# Buffer inputs for when multiple buttons are pressed.
if $InputBuffer.is_stopped():
$InputBuffer.start()