Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- # WARNING: Do not run this code if you have epilepsy or are prone to sizures
- #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- import pygame
- import random
- pygame.init()
- #pygame.mixer.init()
- x = 50
- y = 50
- y1 = 0
- y2 = 0
- pSpeed = 6
- speed = 4.5
- aiSpeed = 6
- score = 0
- aiScore = 0
- color = (255, 0, 255)
- color2 = (255, 255, 255)
- flashing = False
- loss = False
- windowSize = pygame.display.Info()
- f = 1
- flag = True
- screen = pygame.display.set_mode((windowSize.current_w, windowSize.current_h), pygame.FULLSCREEN)
- #ballHit = pygame.mixer.Sound("ballHit.wav")
- #ballBounce = pygame.mixer.Sound("ballBounce.wav")
- myriadProFont = pygame.font.SysFont("Myriad Pro", 48)
- directionX = 1
- directionY = 1
- clock = pygame.time.Clock()
- pygame.key.set_repeat(1, 10)
- pygame.mouse.set_visible(0)
- def col():
- color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
- while flag:
- clock.tick(100)
- scoreCount = myriadProFont.render(str(score), 1, (255, 255, 255), (0, 0, 0))
- aiScoreCount = myriadProFont.render(str(aiScore), 1, (255, 255, 255), (0, 0, 0))
- keystate = pygame.key.get_pressed()
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- flag = False
- if y2 < y and y2 <= windowSize.current_h - 80:
- y2 += aiSpeed
- if y < y2 and y2 >= 0:
- y2 -= aiSpeed
- if keystate[pygame.K_w] and y1 >= 0:
- y1 -= pSpeed
- if keystate[pygame.K_s] and y1 <= windowSize.current_h - 80:
- y1 += pSpeed
- if keystate[pygame.K_r] and speed == 0:
- x = 50
- y = 50
- y1 = 0
- y2 = 0
- score = 0
- f = 1
- flag = True
- speed = 5
- directionX = 1
- directionY = 1
- aiScore = 0
- loss = False
- if keystate[pygame.K_e] and speed == 0:
- flag = False
- screen.fill(color2)
- pygame.draw.rect(screen, (255, 255, 255), (screen.get_size()[0] / 2 - 5/2, 0, 5, windowSize.current_w))
- pygame.draw.rect(screen, color, (x, y, 10, 10))
- pygame.draw.rect(screen, (255, 255, 255), (0, y1, 10, 80))
- pygame.draw.rect(screen, (255, 255, 255), (windowSize.current_w - 10, y2 - 30, 10, 80))
- size = (20, 20)
- x += speed * directionX
- y += speed * directionY
- if x <= 10 and y > y1 and y < y1 + 80 and loss == False:
- directionX *= -1
- score += 1
- speed += 0.2
- pSpeed += 0.2
- aiSpeed += 0.2
- #ballHit.play()
- if random.randint(1, 6) == 2:
- if flashing == False:
- flashing = True
- elif flashing:
- flashing = False
- if not flashing:
- color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
- if x < 0:
- loss = True
- screen.fill((0, 0, 0))
- finalScore = myriadProFont.render("Final Score: " + str(score), 1, (255, 255, 255), (0, 0, 0))
- retry = myriadProFont.render("Press 'r' to retry", 1, (255, 255, 255), (0, 0, 0))
- end = myriadProFont.render("Press 'e' to exit", 1, (255, 255, 255), (0, 0, 0))
- screen.blit(finalScore, (screen.get_size()[0] / 2 - finalScore.get_size()[0] / 2, 200))
- screen.blit(retry, (screen.get_size()[0] / 2 - retry.get_size()[0] / 2, 250))
- screen.blit(end, (screen.get_size()[0] / 2 - end.get_size()[0] / 2, 300))
- speed = 0
- aiSpeed = 4
- pSpeed = 6
- if x >= windowSize.current_w - 10 and loss == False:
- directionX *= -1
- aiScore += 1
- speed += 0.2
- pSpeed += 0.2
- aiSpeed += 0.2
- #ballHit.play()
- if random.randint(1, 6) == 2:
- if flashing == False:
- flashing = True
- elif flashing:
- flashing = False
- if not flashing:
- color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
- if y + size[1] > windowSize.current_h or y <= 0:
- directionY *= -1
- #ballBounce.play()
- if not flashing:
- color = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
- screen.blit(scoreCount, (screen.get_size()[0] / 2 - scoreCount.get_size()[0] / 2-20, 0))
- screen.blit(aiScoreCount, (screen.get_size()[0] / 2 - aiScoreCount.get_size()[0] / 2+20, 0))
- pygame.display.update()
- if flashing:
- color2 = (random.randint(0, 255),random.randint(0, 255),random.randint(0, 255))
- color = (random.randint(0, 255),random.randint(0, 255),random.randint(0, 255))
- else:
- color2 = (0, 0, 0)
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement