Advertisement
ML2030

Untitled

Sep 28th, 2021
1,585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2.  
  3. pygame.init()
  4. window = pygame.display.set_mode([800,580])
  5.  
  6. X = 200
  7. Y = 200
  8. speedX = 1
  9. speedY = 1
  10.  
  11. clock = pygame.time.Clock()
  12.  
  13. while True:
  14.     window.fill((255,255,255))
  15.  
  16.     pygame.draw.polygon(
  17.     window,
  18.     (255, 0, 0),
  19.     ((100,100),(300,100),(300,300))
  20.     )
  21.    
  22.     for event in pygame.event.get():
  23.      
  24.       if event.type == pygame.KEYDOWN:
  25.         if event.key == pygame.K_LEFT:
  26.           speedX = -1
  27.          
  28.         if event.key == pygame.K_RIGHT:
  29.           speedX = 1
  30.          
  31.       if event.type == pygame.KEYUP:
  32.         if (event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT):
  33.             speedX = 0
  34.  
  35.     pygame.display.update()
  36.     clock.tick(60)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement