-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.py
179 lines (145 loc) · 2.87 KB
/
global.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
from sense_hat import SenseHat
import time
sense=SenseHat()
sense.clear()
ball_x=5
ball_y=3
sense.set_pixel(ball_x,ball_y,132,32,84)
bacx=5
bacxh=bacx-1
bacxb=bacx+1
sense.set_pixel(bacxh,7,132,32,87)
sense.set_pixel(bacx,7,132,32,87)
sense.set_pixel(bacxb,7,132,32,87)
def bup():
global bacx
global bacxh
global bacxb
if (bacx>1):
bacx-=1
bacxh=bacx-1
bacxb=bacx+1
sense.clear()
sense.set_pixel(bacxh,7,132,32,87)
sense.set_pixel(bacx,7,132,32,87)
sense.set_pixel(bacxb,7,132,32,87)
sense.set_pixel(ball_x,ball_y,132,32,84)
def bdown():
global bacx
global bacxh
global bacxb
if (bacx<6):
bacx+=1
bacxh=bacx-1
bacxb=bacx+1
sense.clear()
sense.set_pixel(bacxh,7,132,32,87)
sense.set_pixel(bacx,7,132,32,87)
sense.set_pixel(bacxb,7,132,32,87)
sense.set_pixel(ball_x,ball_y,132,32,84)
time.sleep(1)
def ball_bouge():
global ball_x
global ball_y
sense.clear()
sense.set_pixel(bacxh,7,132,32,87)
sense.set_pixel(bacx,7,132,32,87)
sense.set_pixel(bacxb,7,132,32,87)
sense.set_pixel(ball_x,ball_y,132,32,84)
def ballhg():
global ball_x
global ball_y
ball_x-=1
ball_y+=1
def ballbg():
global ball_x
global ball_y
ball_x+=1
ball_y+=1
def ballbd():
global ball_x
global ball_y
ball_x+=1
ball_y-=1
def ballhd():
global ball_x
global ball_y
ball_x-=1
ball_y-=1
sense.set_pixel(ball_x,ball_y,132,32,84)
ballbgs=0
ballbds=1
ballhgs=0
ballhds=0
continuer=True
while continuer:
if (ballbds==1):
ballbd()
ball_bouge()
time.sleep(0.5)
if (ball_x==7 and ball_y!=0):
ballbds=0
ballhds=1
if (ball_y==0 and ball_x!=7):
ballbds=0
ballbgs=1
if (ball_x==7 and ball_y==0):
ballbds=0
ballhgs=1
for event in sense.stick.get_events():
if event.direction=="up":
bup()
if event.direction=="down":
bdown()
elif (ballhds==1):
ballhd()
ball_bouge()
time.sleep(0.5)
if (ball_x==0 and ball_y!=0):
ballhds=0
ballbds=1
if (ball_y==0 and ball_x!=0):
ballhds=0
ballhgs=1
if (ball_x==0 and ball_y==0):
ballhds=0
ballbgs=1
for event in sense.stick.get_events():
if event.direction=="up":
bup()
if event.direction=="down":
bdown()
elif (ballhgs==1):
ballhg()
ball_bouge()
time.sleep(0.5)
if (ball_y==7):
continuer=False
if (ball_x==0 and ball_y!=7):
ballhgs=0
ballbgs=1
if (ball_y==5 and (ball_x==bacx or ball_x==bacxh or ball_x==bacxb)):
ballhgs=0
ballhds=1
for event in sense.stick.get_events():
if event.direction=="up":
bup()
if event.direction=="down":
bdown()
elif (ballbgs==1):
time.sleep(0.5)
if (ball_y==7):
continuer=False
if (ball_x==6 and ball_y!=7):
ballbgs=0
ballhds=1
if (ball_y==6 and (ball_x==bacx or ball_x==bacxh or ball_x==bacxb)):
ballbgs=0
ballbds=1
for event in sense.stick.get_events():
if event.direction=="up":
bup()
if event.direction=="down":
bdown()
ballbg()
ball_bouge()