Advertisement
ML2030

Untitled

Sep 30th, 2021
1,380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2. import random
  3. import sys
  4.  
  5. pygame.init()
  6. window = pygame.display.set_mode([800, 580])
  7. spaceship = pygame.image.load('spaceship.png')
  8.  
  9. imgX = 350
  10. imgY = 400
  11. speedX = 0
  12. quadX = random.randrange(0, 700)
  13. quadY = 0
  14.  
  15. score = 0
  16.  
  17. clock = pygame.time.Clock()
  18.  
  19. while True:
  20.   for event in pygame.event.get():
  21.     if event.type == pygame.KEYDOWN:
  22.       if event.key == pygame.K_LEFT:
  23.         speedX = -10
  24.       if event.key == pygame.K_RIGHT:
  25.         speedX = 10
  26.     if event.type == pygame.KEYUP:
  27.       if (event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT):
  28.           speedX = 0
  29.          
  30.          
  31.   window.fill((255, 255, 255))
  32.   window.blit(spaceship, [imgX, imgY])
  33.  
  34.   pygame.draw.rect(
  35.     window, (0, 0, 0), [quadX, quadY, 100, 100]
  36.   )
  37.   imgX += speedX
  38.   quadY += 1
  39.  
  40.   if imgY < quadY + 100 and imgY + 128 > quadY:
  41.     if imgX < quadX + 100 and imgX + 128 > quadX:
  42.       sys.exit()
  43.        
  44.          
  45.   if quadY > 580:
  46.     quadY = 0
  47.     quadX = random.randrange(0, 700)
  48.    
  49.   if imgY < quadY + 100 and imgY + 128 > quadY:
  50.     if imgX < quadX + 100 and imgX + 128 > quadX:
  51.       font = pygame.font.Font('freesansbold.ttf', 150)
  52.       text = font.render('BATEU', True, (0, 0, 0))
  53.       window.blit(text, [150, 100])
  54.       pygame.display.update()
  55.       pygame.time.wait(2000)
  56.       sys.exit()
  57.      
  58.   font = pygame.font.Font('freesansbold.ttf', 32)
  59.   text = font.render(
  60.     'score: ' + str(score), True, (0, 0, 0)
  61.   )
  62.   window.blit(text, [20, 20])
  63.  
  64.  
  65.   if quadY > 580:
  66.     quadY = 0
  67.     quadX = random.randrange(0, 700)
  68.     score += 1
  69.      
  70.   pygame.display.update()
  71.   clock.tick(30)
  72.  
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement