-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
183 lines (174 loc) · 6.94 KB
/
main.py
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
@namespace
class SpriteKind:
Background = SpriteKind.create()
Brush = SpriteKind.create()
Canvas = SpriteKind.create()
def on_a_pressed():
global current_scene, types, correct_types
if current_scene == "menu":
if currently_selecte_option_index == 0:
current_scene = "singleplayer"
clear_menu()
generate_string()
elif currently_selecte_option_index == 1:
clear_menu()
add_menu_options("In development...", "-", "-", False, False)
elif currently_selecte_option_index == 2:
current_scene = "credit"
clear_menu()
add_menu_options("Inspired by MonkeyType",
"Thanks for Justin's guide",
"",
False,
False)
show_menu()
elif current_scene == "singleplayer":
types += 1
if test_string[0] == "A":
correct_types += 1
sprites.destroy(show_string[0], effects.spray, 50)
test_string.remove_at(0)
show_string.remove_at(0)
music.play(music.melody_playable(music.zapped),
music.PlaybackMode.IN_BACKGROUND)
elif test_string[0] == "B":
scene.camera_shake(8, 100)
music.play(music.melody_playable(music.small_crash),
music.PlaybackMode.IN_BACKGROUND)
controller.A.on_event(ControllerButtonEvent.PRESSED, on_a_pressed)
def on_countdown_end():
global textSprite4, textSprite5, textSprite3, textSprite
clear_menu()
music.play(music.create_song(hex("""
0078000408020100001c00010a006400f401640000040000000000000000000000000005000004240000000400012c08000c0001291000140001271c002000012420002400012028002c000125
""")),
music.PlaybackMode.IN_BACKGROUND)
textSprite4 = textsprite.create("Accuracy: " + convert_to_text(Math.floor(correct_types / types * 100)) + "%",
0,
5)
textSprite4.set_max_font_height(9)
textSprite4.set_position(55, 25)
textSprite5 = textsprite.create("WPM: " + convert_to_text(correct_types / 10 * 60), 0, 5)
textSprite5.set_max_font_height(9)
textSprite5.set_position(40, 45)
textSprite3 = textsprite.create("Raw: " + convert_to_text(types / 10 * 60), 0, 5)
textSprite3.set_max_font_height(9)
textSprite3.set_position(40, 65)
textSprite = textsprite.create("Press Refresh to restart", 0, 1)
textSprite.set_max_font_height(9)
textSprite.set_position(75, 85)
info.on_countdown_end(on_countdown_end)
def clear_menu():
sprites.destroy(textSprite)
sprites.destroy(textSprite2)
sprites.destroy(textSprite3)
sprites.destroy(textSprite4)
sprites.destroy(textSprite5)
def on_up_pressed():
global currently_selecte_option_index
if show_drawing_menu:
currently_selecte_option_index = (currently_selecte_option_index + (len(all_options_in_menu) - 1)) % len(all_options_in_menu)
controller.up.on_event(ControllerButtonEvent.PRESSED, on_up_pressed)
def on_b_pressed():
global current_scene, types, correct_types
if current_scene == "credit":
clear_menu()
current_scene = "menu"
add_menu_options("Singleplayer", "Multiplayer", "Credit", True, True)
show_menu()
elif current_scene == "singleplayer":
types += 1
if test_string[0] == "B":
correct_types += 1
sprites.destroy(show_string[0], effects.spray, 50)
test_string.remove_at(0)
show_string.remove_at(0)
music.play(music.melody_playable(music.zapped),
music.PlaybackMode.IN_BACKGROUND)
elif test_string[0] == "A":
scene.camera_shake(8, 100)
music.play(music.melody_playable(music.small_crash),
music.PlaybackMode.IN_BACKGROUND)
controller.B.on_event(ControllerButtonEvent.PRESSED, on_b_pressed)
def on_create_renderable(screen2):
global index
if show_drawing_menu:
index = 0
while index <= len(all_options_in_menu) - 1:
if index == currently_selecte_option_index:
all_options_in_menu[index].set_border(1, 5)
else:
all_options_in_menu[index].set_border(0, 5)
index += 1
spriteutils.create_renderable(100, on_create_renderable)
def add_menu_options(option1: str, option2: str, option3: str, Selectable: bool, Title: bool):
global all_options_in_menu, textSprite, textSprite2, textSprite3, textSprite4, textSprite5
all_options_in_menu = []
textSprite = textsprite.create(option1, 0, 1)
textSprite.set_position(80, 65)
if Selectable:
all_options_in_menu.append(textSprite)
textSprite2 = textsprite.create(option2, 0, 1)
textSprite2.set_position(80, 80)
if Selectable:
all_options_in_menu.append(textSprite2)
textSprite3 = textsprite.create(option3, 0, 1)
textSprite3.set_position(80, 95)
if Selectable:
all_options_in_menu.append(textSprite3)
if Title:
textSprite4 = textsprite.create("ArcadeType", 0, 5)
textSprite4.set_position(55, 30)
textSprite4.set_max_font_height(10)
textSprite5 = textsprite.create("Ver1.0", 0, 5)
textSprite5.set_position(139, 110)
def show_menu():
for value in sprites.all_of_kind(SpriteKind.text):
value.set_flag(SpriteFlag.INVISIBLE, not (show_drawing_menu))
def on_down_pressed():
global currently_selecte_option_index
if show_drawing_menu:
currently_selecte_option_index = (currently_selecte_option_index + 1) % len(all_options_in_menu)
controller.down.on_event(ControllerButtonEvent.PRESSED, on_down_pressed)
def generate_string():
global test_string, show_string, string_generator
test_string = []
show_string = []
for index2 in range(21):
string_generator = randint(0, 1)
if string_generator == 0:
test_string.append("A")
show_string.append(textsprite.create(test_string[index2], 0, 1))
else:
test_string.append("B")
show_string.append(textsprite.create(test_string[index2], 0, 1))
show_string[index2].set_position(20 + index2 * 5, 65)
info.start_countdown(5)
string_generator = 0
index = 0
all_options_in_menu: List[TextSprite] = []
textSprite2: TextSprite = None
textSprite: TextSprite = None
textSprite3: TextSprite = None
textSprite5: TextSprite = None
textSprite4: TextSprite = None
show_string: List[TextSprite] = []
correct_types = 0
test_string: List[str] = []
types = 0
current_scene = ""
currently_selecte_option_index = 0
show_drawing_menu = False
scene.set_background_color(13)
show_drawing_menu = not (show_drawing_menu)
currently_selecte_option_index = 0
add_menu_options("Singleplayer", "Multiplayer", "Credit", True, True)
current_scene = "menu"
show_menu()
MakeyMakey.set_simulator_keymap(MakeyMakey.PlayerNumber.ONE,
MakeyMakey.MakeyMakeyKey.UP,
MakeyMakey.MakeyMakeyKey.DOWN,
MakeyMakey.MakeyMakeyKey.LEFT,
MakeyMakey.MakeyMakeyKey.RIGHT,
MakeyMakey.MakeyMakeyKey.F,
MakeyMakey.MakeyMakeyKey.G)