Advertisement
ML2030

Untitled

Sep 30th, 2021
1,604
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.  
  7. window = pygame.display.set_mode([800, 580])
  8. spaceship = pygame.image.load('spaceship.png')
  9. imgX = 350
  10. speedX = 0
  11.  
  12.  
  13. clock = pygame.time.Clock()
  14.  
  15. while True:
  16.    for event in pygame.event.get():
  17.      if event.type == pygame.KEYDOWN:
  18.        if event.key == pygame.K_LEFT:
  19.          speedX = -1
  20.         if event.key == pygame.K_RIGHT:
  21.           speedX = 1
  22.       if event.type == pygame.KEYUP:
  23.         if (event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT):
  24.           speedX = 0
  25.          
  26.          
  27.   window.fill((255, 255, 255))
  28.   window.blit(spaceship, [350, 400])
  29.  
  30.   pygame.draw.rect(
  31.     window, (0, 0, 255), [100, 100, 100, 150]
  32.     )
  33.  
  34.   imgX += speedX
  35.   quadY += 1
  36.  
  37.    if 400 < quadY + 100 and 528 > quadY:
  38.      if imgX < quadX + 100 and imgX + 128 > quadX:
  39.        sys.exit()
  40.  
  41.   if quadY > 580:
  42.     quadY = 0
  43.     quadX = random.randrange(0, 480)
  44.  
  45.  
  46.   pygame.display.update()
  47.   clock.tick(60
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement