-
Notifications
You must be signed in to change notification settings - Fork 1
/
play.py
31 lines (24 loc) · 836 Bytes
/
play.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
import pyxel
import json
MUSIC_FILE = "sample"
class App:
def __init__(self):
pyxel.init(160, 120, title="Pyxel Tracker Player")
with open(f"./musics/{MUSIC_FILE}.json", "rt") as fin:
self.music = json.loads(fin.read())
pyxel.run(self.update, self.draw)
def update(self):
if pyxel.btnp(pyxel.KEY_SPACE):
if pyxel.play_pos(0) is None:
for ch, sound in enumerate(self.music):
pyxel.sound(ch).set(*sound)
pyxel.play(ch, ch, loop=True)
else:
pyxel.stop()
if pyxel.btnp(pyxel.KEY_ESCAPE):
pyxel.quit()
def draw(self):
pyxel.cls(0)
pyxel.text(20, 52, "Press [SPACE] to play / stop.", 7)
pyxel.text(20, 64, "Press [ESC] to exit.", 7)
App()