Advertisement
harisha

Pygame - kod Michała

Feb 14th, 2022
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. import pygame, sys
  2.  
  3. max_tps = 20.0
  4.  
  5. pygame.init()
  6.  
  7. screen = pygame.display.set_mode((720,576))
  8. box = pygame.Rect(10,10,50,50)
  9. box2 = pygame.Rect(10,500,50,50)
  10. clock = pygame.time.Clock()
  11. delta = 0.0
  12.  
  13. while True:
  14.   for event in pygame.event.get():
  15.     if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
  16.       sys.exit(0)
  17.  
  18.   delta += clock.tick()/1000.0
  19.   while delta > 1/max_tps:
  20.     delta -= 1/max_tps
  21.  
  22.   keys = pygame.key.get_pressed()
  23.   if keys[pygame.K_UP]:
  24.     box.y -= 1
  25.   if keys[pygame.K_DOWN]:
  26.     box.y += 1
  27.   if keys[pygame.K_LEFT]:
  28.     box.x -= 1
  29.   if keys[pygame.K_RIGHT]:
  30.     box.x += 1
  31.  
  32.   if keys[pygame.K_w]:
  33.     box2.y -= 1
  34.   if keys[pygame.K_s]:
  35.     box2.y += 1
  36.   if keys[pygame.K_a]:
  37.     box2.x -= 1
  38.   if keys[pygame.K_d]:
  39.     box2.x += 1
  40.  
  41.  
  42.  
  43.   screen.fill((0,0,0))
  44.   pygame.draw.rect(screen, (52, 218, 206), box)
  45.   pygame.draw.rect(screen, (52, 208, 200), box2)
  46.   pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement