-
Notifications
You must be signed in to change notification settings - Fork 0
/
pong.py
4 lines (4 loc) · 2.59 KB
/
pong.py
1
2
3
4
import pygame, sys; move_j1, score_j1, move_j2, score_j2, move_balle, _, SCREEN, clock, j1, j2, balle, font = 0, 0, 0, 0, [7,3], pygame.init(), pygame.display.set_mode((650, 500)), pygame.time.Clock(), pygame.Rect(0, 210, 10, 80), pygame.Rect(640, 210, 10, 80), pygame.Rect(322.5, 247.5, 15, 15), pygame.font.SysFont("franklin gothic heavy", 40)
while True:
for e in pygame.event.get(): (pygame.quit(), sys.exit()) if e.type == pygame.QUIT or (e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE) else _
move_balle[0], move_balle[1], move_j1, move_j2, gagne, score_j1, score_j2, j1.y, j2.y, balle.x, balle.y = (10 - (((abs(balle.centery - j1.centery) / 40) / 100) * 70) * 10) if j1.collidepoint(balle.midleft) and abs(balle.left - 10) < 10 else ((- 10 + (((abs(balle.centery - j2.centery) / 40) / 100) * 70) * 10) if j2.collidepoint(balle.midright) and abs(balle.right - 640) < 10 else (-7 if balle.right >= 650 else (7 if balle.left <= 0 else move_balle[0]))), (((((balle.centery - j1.centery) / 40) / 100) * 70) * 10) if j1.collidepoint(balle.midleft) and abs(balle.left - 10) < 10 else ((((((balle.centery - j2.centery) / 40) / 100) * 70) * 10) if j2.collidepoint(balle.midright) and abs(balle.right - 640) < 10 else (-3 if balle.right >= 650 else (3 if balle.left <= 0 else (-move_balle[1] if balle.bottom >= 500 or balle.top <= 0 else move_balle[1])))), -10 if j1.top > 0 and pygame.key.get_pressed()[pygame.K_z] else (10 if j1.bottom < 500 and pygame.key.get_pressed()[pygame.K_s] else 0), -10 if j2.top > 0 and pygame.key.get_pressed()[pygame.K_UP] else (10 if j2.bottom < 500 and pygame.key.get_pressed()[pygame.K_DOWN] else 0), True if balle.right >= 650 or balle.left <= 0 else False, (score_j1 + 1) if balle.right >= 650 else score_j1, (score_j2 + 1) if balle.left <= 0 else score_j2, 210 if balle.right >= 650 or balle.left <= 0 else j1.y, 210 if balle.right >= 650 or balle.left <= 0 else j2.y, 322.5 if balle.right >= 650 or balle.left <= 0 else balle.x, 247.5 if balle.right >= 650 or balle.left <= 0 else balle.y; j1, j2, balle,_,_,_,_,_,_,_,_,_ = j1.move(0, move_j1), j2.move(0, move_j2), balle.move(move_balle[0], move_balle[1]), SCREEN.fill((0,0,0)), SCREEN.blit(font.render(str(score_j1), True, (100,100,100)), ((650 / 4 - font.size(str(score_j1))[0] /2), 100)), SCREEN.blit(font.render(str(score_j2), True, (100,100,100)), ((3 * (650 / 4) - font.size(str(score_j2))[0] /2), 100)), pygame.draw.rect(SCREEN, (255,255,255), j1, 0, 10), pygame.draw.rect(SCREEN, (255,255,255), j2, 0, 10), pygame.draw.rect(SCREEN, (255,255,255), balle, 0, 15), pygame.display.flip(), clock.tick(60), (pygame.time.wait(500)) if gagne else None