-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathping.py
63 lines (52 loc) · 1.81 KB
/
ping.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
from sense_hat import SenseHat
from time import sleep
sense = SenseHat()
sense.clear()
def baton(y,last_y):
sense.set_pixel(0,last_y,(0,0,0))
sense.set_pixel(7,last_y,(0,0,0))
sense.set_pixel(0,y,(200,200,200))
sense.set_pixel(0,y+1,(200,200,200))
sense.set_pixel(0,y-1,(200,200,200))
sense.set_pixel(7,y,(200,200,200))
sense.set_pixel(7,y+1,(200,200,200))
sense.set_pixel(7,y-1,(200,200,200))
def ping():
score=0
y = 4
last_y = 0
ball_position=[6,3]
ball_speed=[-0.5,-0.5]
jouer=True
while jouer:
for event in sense.stick.get_events():
if event.action == 'pressed':
if event.direction == 'down' and y < 6:
y += 1
last_y = y-2
elif event.direction == 'up' and y > 1:
y -= 1
last_y = y+2
sleep(0.25-(score/100))
sense.set_pixel(ball_position[0],ball_position[1],0,0,0)
baton(y,last_y)
ball_position[0] += ball_speed[0]
ball_position[1] += ball_speed[1]
if ball_position[1] == 0 or ball_position[1] == 7:
ball_speed[1] = -ball_speed[1]
if ball_position[0] == 1 and y-1 <= ball_position[1] <= y+1:
ball_speed[0] = -ball_speed[0]
score += 1
if ball_position[0] == 6 and y-1 <= ball_position[1] <= y+1:
ball_speed[0] = -ball_speed[0]
score += 1
if ball_position[0] == 0:
sense.show_message('Tu as perdu!')
jouer=False
break
if ball_position[0] == 7:
sense.show_message('Tu as perdu!')
jouer=False
break
sense.set_pixel(ball_position[0],ball_position[1],0,0,255)
sense.show_message(str(score) + " pts!")