-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.py
68 lines (47 loc) · 1.43 KB
/
client.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
import pygame
from src.constant import WIDTH, HEIGHT, FPS
from network import Network
from src import color
pygame.init()
WIN = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption('multiplayer pong')
FONT = pygame.font.SysFont('monospace', 50)
# def draw(win):
# win.fill(color.BLACK)
# pygame.display.update()
def draw(win, players, ball, score):
win.fill((40, 40, 40))
score.draw(win)
for player in players:
player.draw(win)
for i in range(10, HEIGHT, HEIGHT // 20):
if i % 2 == 1:
continue
pygame.draw.rect(win, color.WHITE,
(WIDTH // 2 - 5, i, 10, HEIGHT // 20))
ball.draw(win)
pygame.display.update()
def main():
pygame.init()
run = True
n = Network()
player = n.get_player()
clock = pygame.time.Clock()
while run:
clock.tick(FPS)
player2, ball, score, closing = n.send(player)
if closing:
run = False
pygame.quit()
if score.left_score == "You WIN!" or score.right_score == "You WIN!":
player.ready = False
keys = pygame.key.get_pressed()
for event in pygame.event.get():
if event.type == pygame.QUIT or keys[pygame.K_ESCAPE]:
run = False
pygame.quit()
player.move()
draw(WIN, [player, player2], ball, score)
pygame.quit()
if __name__ == '__main__':
main()