Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCube.py
More file actions
Latest commit
executable file
·127 lines (98 loc) · 4.18 KB
/
Copy pathCube.py
File metadata and controls
executable file
·127 lines (98 loc) · 4.18 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
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
importthreading
importtime
importDirection
importExit
importFFT
importFrameCollection2DasFrames
importGameasGame
importPong
importPongMulti
importSnake
importWeather
importapi
classLEDCube(threading.Thread):
cube_games= []
current_item=0
current_game=None
current_face=api.Face.FRONT
def__init__(self, cube_size: int, delay):
super().__init__()
api.cubeSize=cube_size
api.delay=delay
# api.setup()
defregister(self, *games: Game.CubeGame):
forgameingames:
ifgame.get_menu_frame() isnotNone:
self.cube_games=self.cube_games+ [game]
defrun(self):
self.open_menu()
defunregister_all(self):
self.cube_games= []
defreset_all(self):
self.unregister_all()
Direction.direction=None
defopen_menu(self):
ifnotself.cube_games:
self.show_2d_frame(Frames.question_mark)
else:
whileTrue:
whileself.current_gameisNone:
updated=False
ifself.cube_games[self.current_item].has_menu_animation():
self.cube_games[self.current_item].play_animation()
whilenotupdated:
self.show_menu_state()
ifapi.get_pressed_enter():
self.cube_games[self.current_item].close_animation()
self.current_game=self.cube_games[self.current_item]
api.set_pressed_enter(False)
updated=True
ifDirection.direction_p_1.value==int(Direction.Direction.RIGHT) andself.current_item<len(
self.cube_games) -1:
self.cube_games[self.current_item].close_animation()
self.current_item+=1
Direction.direction_p_1.value=0
api.clear_all()
updated=True
ifDirection.direction_p_1.value==int(Direction.Direction.LEFT) andself.current_item>0:
self.cube_games[self.current_item].close_animation()
self.current_item-=1
Direction.direction_p_1.value=0
api.clear_all()
updated=True
# Otherwise we will get array out of bounds exception (similar to mathf.clamp)
# self.current_item = max(0, min(self.current_item, len(self.cube_games) - 1))
time.sleep(0.2)
api.clear_all()
self.start_game(self.current_item)
api.clear_all()
# Reset everything for next menu launch
self.reset_all()
register_all()
api.set_pressed_enter(False)
self.current_game=None
defshow_2d_frame(self, frame):
api.change_face(self.current_face, 0, frame)
defstart_game(self, game_id):
self.cube_games[game_id].start()
self.cube_games[game_id].join()
Direction.direction_p_1.value=0
defkill_game(self, game_id):
pass
defshow_menu_state(self):
ifnotself.cube_games[self.current_item].is_animation_alive():
ifself.current_item>0:
api.change_face(api.Face.LEFT, 0, Frames.arrow_left)
ifself.current_item<len(self.cube_games) -1:
api.change_face(api.Face.RIGHT, 0, Frames.arrow_right)
self.show_2d_frame(self.cube_games[self.current_item].get_menu_frame())
defregister_all():
ifled_cubeisnotNone:
led_cube.register(Snake.Snake(api.cubeSize, frame_size), Pong.Pong(api.cubeSize, frame_size),
PongMulti.PongMulti(api.cubeSize, frame_size), Weather.Weather(api.cubeSize, frame_size),
FFT.AudioVis(api.cubeSize, frame_size), Exit.Exit(api.cubeSize, frame_size))
frame_size= (8, 8)
led_cube=LEDCube(8, 0.001)
register_all()
led_cube.start()
api.start()