Advertisement
k1alo

Untitled

Mar 15th, 2024
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. import pygame
  2. from sys import exit
  3.  
  4. pygame.init()
  5. display = pygame.display.set_mode((800, 600))
  6. tree_x = 300
  7. tree_y = 300
  8. tree_speed = 5
  9.  
  10. running = True
  11. while running:
  12.     for event in pygame.event.get():
  13.         if event.type == pygame.QUIT:
  14.             running = False
  15.  
  16.     keys = pygame.key.get_pressed()
  17.     if keys[pygame.K_LEFT]:
  18.         tree_x -= tree_speed
  19.     if keys[pygame.K_RIGHT]:
  20.         tree_x += tree_speed
  21.     if keys[pygame.K_UP]:
  22.         tree_y -= tree_speed
  23.     if keys[pygame.K_DOWN]:
  24.         tree_y += tree_speed
  25.  
  26.     pygame.draw.rect(display, (0, 128, 255), pygame.Rect(tree_x, tree_y, 30, 30))
  27.  
  28.     screen.fill((255, 255, 255))
  29.  
  30.  
  31.  
  32.     pygame.display.flip()
  33.  
  34.  
  35. pygame.quit()
  36. sys.exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement