Advertisement
Techmo

PONG (sizure warning)

Feb 18th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.63 KB | None | 0 0
  1. #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2. # WARNING: Do not run this code if you have epilepsy or are prone to sizures
  3. #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  4. import pygame
  5. import random
  6. pygame.init()
  7. #pygame.mixer.init()
  8. x = 50
  9. y = 50
  10. y1 = 0
  11. y2 = 0
  12. pSpeed = 6
  13. speed = 4.5
  14. aiSpeed = 6
  15. score = 0
  16. aiScore = 0
  17. color = (255, 0, 255)
  18. color2 = (255, 255, 255)
  19. flashing = False
  20. loss = False
  21. windowSize = pygame.display.Info()
  22. f = 1
  23. flag = True
  24. screen = pygame.display.set_mode((windowSize.current_w, windowSize.current_h), pygame.FULLSCREEN)
  25. #ballHit = pygame.mixer.Sound("ballHit.wav")
  26. #ballBounce =  pygame.mixer.Sound("ballBounce.wav")
  27. myriadProFont = pygame.font.SysFont("Myriad Pro", 48)
  28. directionX = 1
  29. directionY = 1
  30. clock = pygame.time.Clock()
  31. pygame.key.set_repeat(1, 10)
  32. pygame.mouse.set_visible(0)
  33. def col():
  34.     color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
  35. while flag:
  36.     clock.tick(100)
  37.     scoreCount = myriadProFont.render(str(score), 1, (255, 255, 255), (0, 0, 0))
  38.     aiScoreCount = myriadProFont.render(str(aiScore), 1, (255, 255, 255), (0, 0, 0))
  39.     keystate = pygame.key.get_pressed()
  40.     for event in pygame.event.get():
  41.         if event.type == pygame.QUIT:
  42.             flag = False
  43.     if y2 < y and y2 <= windowSize.current_h - 80:
  44.         y2 += aiSpeed
  45.     if y < y2 and y2 >= 0:
  46.         y2 -= aiSpeed
  47.     if keystate[pygame.K_w] and y1 >= 0:
  48.         y1 -= pSpeed
  49.     if keystate[pygame.K_s] and y1 <= windowSize.current_h - 80:
  50.         y1 += pSpeed
  51.     if keystate[pygame.K_r] and speed == 0:
  52.         x = 50
  53.         y = 50
  54.         y1 = 0
  55.         y2 = 0
  56.         score = 0
  57.         f = 1
  58.         flag = True
  59.         speed = 5
  60.         directionX = 1
  61.         directionY = 1
  62.         aiScore = 0
  63.         loss = False
  64.     if keystate[pygame.K_e] and speed == 0:
  65.         flag = False
  66.     screen.fill(color2)
  67.     pygame.draw.rect(screen, (255, 255, 255), (screen.get_size()[0] / 2 - 5/2, 0, 5, windowSize.current_w))
  68.     pygame.draw.rect(screen, color, (x, y, 10, 10))
  69.     pygame.draw.rect(screen, (255, 255, 255), (0, y1, 10, 80))
  70.     pygame.draw.rect(screen, (255, 255, 255), (windowSize.current_w - 10, y2 - 30, 10, 80))
  71.  
  72.     size = (20, 20)
  73.     x += speed * directionX
  74.     y += speed * directionY
  75.     if x <= 10 and  y > y1 and y < y1 + 80 and loss == False:
  76.         directionX *= -1
  77.         score += 1
  78.         speed += 0.2
  79.         pSpeed += 0.2
  80.         aiSpeed += 0.2
  81.         #ballHit.play()
  82.         if random.randint(1, 6) == 2:
  83.             if flashing == False:
  84.                 flashing = True
  85.         elif flashing:
  86.             flashing = False
  87.         if not flashing:
  88.             color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
  89.     if x < 0:
  90.         loss = True
  91.         screen.fill((0, 0, 0))
  92.         finalScore = myriadProFont.render("Final Score: " + str(score), 1, (255, 255, 255), (0, 0, 0))
  93.         retry = myriadProFont.render("Press 'r' to retry", 1, (255, 255, 255), (0, 0, 0))
  94.         end = myriadProFont.render("Press 'e' to exit", 1, (255, 255, 255), (0, 0, 0))
  95.         screen.blit(finalScore, (screen.get_size()[0] / 2 - finalScore.get_size()[0] / 2, 200))
  96.         screen.blit(retry, (screen.get_size()[0] / 2 - retry.get_size()[0] / 2, 250))
  97.         screen.blit(end, (screen.get_size()[0] / 2 - end.get_size()[0] / 2, 300))
  98.         speed = 0
  99.         aiSpeed = 4
  100.         pSpeed = 6
  101.     if x >= windowSize.current_w - 10 and loss == False:
  102.         directionX *= -1
  103.         aiScore += 1
  104.         speed += 0.2
  105.         pSpeed += 0.2
  106.         aiSpeed += 0.2
  107.         #ballHit.play()
  108.         if random.randint(1, 6) == 2:
  109.             if flashing == False:
  110.                 flashing = True
  111.         elif flashing:
  112.             flashing = False
  113.         if not flashing:
  114.  
  115.             color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
  116.  
  117.     if y + size[1] > windowSize.current_h or y <= 0:
  118.         directionY *= -1
  119.         #ballBounce.play()
  120.         if not flashing:
  121.  
  122.             color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
  123.     screen.blit(scoreCount, (screen.get_size()[0] / 2 - scoreCount.get_size()[0] / 2-20, 0))
  124.     screen.blit(aiScoreCount, (screen.get_size()[0] / 2 - aiScoreCount.get_size()[0] / 2+20, 0))
  125.     pygame.display.update()
  126.     if flashing:
  127.         color2 = (random.randint(0, 255),random.randint(0, 255),random.randint(0, 255))
  128.         color = (random.randint(0, 255),random.randint(0, 255),random.randint(0, 255))
  129.     else:
  130.         color2 = (0, 0, 0)
  131. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement