-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay.py
55 lines (48 loc) · 1.36 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys
import pygame as pg
from scipy.interpolate import interp1d
import server as se
def main():
screen = pg.display.set_mode((640, 480))
clock = pg.time.Clock()
rect = pg.Rect(300, 220, 20, 20)
done = False
while not done:
for event in pg.event.get():
if event.type == pg.QUIT:
done = True
list1 = se.server_program()
list1 = list1.split(',')
axis0 = float(list1[0])
axis1= float(list1[1])
speed = float(list1[2])
button = 0
if axis0 <= -0.85: #to move left
if button == 0:
rect.x -= speed
if button ==1:
rect.x -= 5
elif axis0 >= 0.85: #to move right
if button == 0:
rect.x += speed
if button ==1:
rect.x += 5
elif axis1 <= -0.85: #to move up
if button == 0:
rect.y -= speed
if button ==1:
rect.y -= 5
elif axis1 >= 0.85: #to move down
if button == 0:
rect.y += speed
if button ==1:
rect.y += 5
screen.fill((40, 40, 40))
pg.draw.rect(screen, (150, 200, 20), rect)
pg.display.flip()
clock.tick(30)
if __name__ == '__main__':
pg.init()
main()
pg.quit()
sys.exit()