ewalkowka

Pygame

Jan 8th, 2023
689
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.06 KB | None | 0 0
  1. import pygame
  2.  
  3. pygame.init()
  4.  
  5. SCREEN_WIDTH = 800
  6. SCREEN_HEIGH = 600
  7.  
  8. screen_surface = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGH))
  9. pygame.display.set_caption("Pierwsza Gra")
  10.  
  11. game_status = True
  12.  
  13. clock = pygame.time.Clock()
  14.  
  15. def load_image(img_path, position):
  16.     image = pygame.image.load(img_path)
  17.     surface = image.convert()
  18.  
  19.     transparent_color = (0,0,0)
  20.     surface.set_colorkey(transparent_color)
  21.  
  22.     rect = surface.get_rect(center=position)
  23.  
  24.     return [image, surface, rect]
  25.  
  26. def print_image(img_list):
  27.     #image, surface, rect
  28.     image, surface, rect = img_list
  29.     screen_surface.blit(surface, rect)
  30.     pass
  31.  
  32. player_pos = [SCREEN_WIDTH//2, SCREEN_HEIGH//2]
  33. player = load_image('player.png', player_pos)
  34.  
  35. while game_status:
  36.  
  37.     events = pygame.event.get()
  38.  
  39.     for event in events:
  40.         print(event)
  41.  
  42.         if event.type == pygame.QUIT:
  43.             game_status = False
  44.    
  45.     print_image(player)
  46.    
  47.     pygame.display.update()
  48.     clock.tick(10)
  49.  
  50. print("Zamykanie aplikacji")
  51. pygame.quit()
  52. quit()
Advertisement
Add Comment
Please, Sign In to add comment