-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path32flappybird.py
145 lines (106 loc) · 3.11 KB
/
32flappybird.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
from pythonosc import udp_client
import time
import math
import random
client = udp_client.SimpleUDPClient("192.168.100.20", 10023)
def ch_floating_zero(ch):
return ("0" + str(ch))[-2:]
def set_ch_on(ch, on):
ch = ch_floating_zero(ch)
client.send_message("/ch/" + ch + "/mix/on", "OFF" if on else "ON")
def set_fader(ch, val):
ch = ch_floating_zero(ch)
client.send_message("/ch/" + ch + "/mix/fader", val)
def set_ch_color(ch, col):
ch = ch_floating_zero(ch)
client.send_message("/ch/" + ch + "/config/color", col)
def set_ch_name(ch, name):
ch = ch_floating_zero(ch)
client.send_message("/ch/" + ch + "/config/name", name)
colors = ["OFF", "GN", "RD", "YE", "BL", "MG", "CY", "WH", "OFFi"]
remapper = {0: 0, 199: 1, 391: 2, 568: 3, 724: 4, 851: 5, 946: 6, 1004: 7, 1024: 8}
map = [0] * 15
lastMove = 0
moveDelay = 1
MAX_HEIGHT = 1024
global bird, lastBird
bird = 2024
lastBird = 0
lastBirdFall = 0
score = 0
def moveMap():
global score
if map[0]:
print("crash", bird, map[0])
if (map[0] - 200 < bird and map[0] + 200 > bird):
score += 1
else:
gameOver()
a = 1 / 0
for i in range(len(map) - 1):
map[i] = map[i + 1]
map[-1] = 0
def addHole():
if map[-1] + map[-2] + map[-3] == 0:
map[-1] = int((MAX_HEIGHT / 8) * random.randint(2, 8))
# print("adding hole")
def drawMap():
# print(map)
for i in range(len(map)):
set_fader(i + 2, map[i])
set_ch_on(i + 2, map[i])
def drawBird():
set_fader(1, bird)
def drawScore():
global score
scorestring = ("0" * 17) + "{0:b}".format(score)
for i in range(1, 17):
set_ch_color(i, colors[int(scorestring[-i])])
def checkButton():
client.send_message("/xremote", 0)
global bird, lastBird
while 1:
try:
msg = client._sock.recv(1024)
if str(msg, "utf8").startswith("/ch/01/mix/on"):
if not msg[-1]:
# print("bird should go up", lastBird, time.time())
# if lastBird + 0.01 < time.time():
# print("bird up")
bird += 150
if bird > MAX_HEIGHT:
bird = MAX_HEIGHT
drawBird()
set_ch_on(1, 0)
lastBird = time.time()
except(BlockingIOError, UnicodeDecodeError):
break
def gameOver():
for i in range(1, 17):
set_fader(i, 0)
for _i in range(5):
for i in range(1, 17):
set_ch_on(i, 1)
drawScore()
time.sleep(0.2)
for i in range(1, 17):
set_ch_on(i, 0)
set_ch_color(i, colors[0])
time.sleep(0.2)
for i in range(16):
set_ch_name(i + 1, str(2 ** i))
while 1:
if lastMove + moveDelay < time.time():
moveMap()
lastMove = time.time()
addHole()
drawMap()
drawScore()
if lastBird + 0.1 < time.time():
bird -= 20
if bird < 0:
gameOver()
a = 1 / 0
drawBird()
checkButton()
time.sleep(0.05)