Advertisement
drakon-firestone

Untitled

Dec 5th, 2023
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. import pygame # importu biblioteki/modułu pygame
  2. pygame.init() # inicjalizacja pygame'a
  3.  
  4. # ustalenie rozmiaru okna
  5. SCREEN_WIDTH = 800
  6. SCREEN_HEIGHT = 600
  7.  
  8. # utworzenie okna
  9. # i ustalenie wymiarów okienka
  10. screen_surface = pygame.display.set_mode( (SCREEN_WIDTH, SCREEN_HEIGHT) )
  11.  
  12. # nadawanie nazwy oknu
  13. pygame.display.set_caption('Pierwsza gra w Pygame')
  14.  
  15. clock = pygame.time.Clock()
  16.  
  17.  
  18. def load_image(img_path: str, position):
  19. image = pygame.image.load(img_path)
  20. surface = image.convert()
  21.  
  22. transparent_color = (0,0,0)
  23. surface.set_colorkey(transparent_color)
  24. rect = surface.get_rect(center=position)
  25.  
  26. return [image, surface, rect]
  27.  
  28.  
  29. def print_image(img_list):
  30. #image = list[0]
  31. #surface = list[1]
  32. #rect = list[2]
  33.  
  34. image, surface, rect = img_list
  35. screen_surface.blit(surface, rect)
  36. pass
  37.  
  38. def set_image_position(img_list, position):
  39. image, surface, rect = img_list
  40. rect = surface.get_rect(center=position)
  41. return [image, surface, rect]
  42.  
  43. ###### ZMIENNE GRY #############
  44. player_pos = [SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2]
  45. player = load_image('player.png', player_pos)
  46. ###### koniec zmiennych gry ####
  47.  
  48.  
  49. game_running = True
  50. while game_running:
  51. # główna pętla programu
  52.  
  53. events = pygame.event.get() # zapisanie wszystkich zdarzeń do listy events
  54.  
  55. for event in events:
  56. print(event)
  57.  
  58. if event.type == pygame.QUIT:
  59. game_running = False
  60. pass
  61. pass
  62.  
  63. pressed_keys = pygame.key.get_pressed()
  64.  
  65. if(pressed_keys[pygame.K_ESCAPE]):
  66. game_running = False
  67.  
  68.  
  69. print_image(player)
  70.  
  71. pygame.display.update() # odświeżenie okna
  72. clock.tick(60)
  73. pass
  74.  
  75. pygame.quit() # zapytaknie aplikacji pygame
  76. quit() # zamknięcie skryptu
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement