2023-03-09 19:44:02 +01:00
|
|
|
from gameEventHandler import handle_game_event
|
|
|
|
|
2023-03-11 08:23:30 +01:00
|
|
|
import pygame
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
2023-03-09 19:44:02 +01:00
|
|
|
pygame.init()
|
2023-03-11 08:23:30 +01:00
|
|
|
window_size = (800, 600)
|
|
|
|
screen = pygame.display.set_mode(window_size)
|
2023-03-09 19:44:02 +01:00
|
|
|
|
2023-03-11 08:23:30 +01:00
|
|
|
# wczytanie mapy i ludzika (jezeli chcemy robic to bez przeksztłcania pilem i uzyc samego pygame to trzeba miec img w tym samym
|
|
|
|
# folderze co gra)
|
|
|
|
mapa_pil = Image.open('imgs/house.jpg')
|
|
|
|
mapa_pygame = pygame.image.frombuffer(mapa_pil.tobytes(), mapa_pil.size, 'RGB')
|
|
|
|
ludzik_pil = Image.open('imgs/a.jpg')
|
|
|
|
ludzik_pygame = pygame.image.frombuffer(ludzik_pil.tobytes(), ludzik_pil.size, 'RGB')
|
2023-03-09 19:44:02 +01:00
|
|
|
|
2023-03-11 08:23:30 +01:00
|
|
|
# pozycja ludzika
|
|
|
|
ludzik_x = 0
|
|
|
|
ludzik_y = 0
|
2023-03-09 19:44:02 +01:00
|
|
|
|
2023-03-11 08:23:30 +01:00
|
|
|
# główna pętla gry
|
|
|
|
while True:
|
2023-03-09 19:44:02 +01:00
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
2023-03-11 08:23:30 +01:00
|
|
|
pygame.quit()
|
|
|
|
quit()
|
|
|
|
elif event.type == pygame.KEYDOWN:
|
|
|
|
if event.key == pygame.K_LEFT:
|
|
|
|
ludzik_x -= 10
|
|
|
|
elif event.key == pygame.K_RIGHT:
|
|
|
|
ludzik_x += 10
|
|
|
|
elif event.key == pygame.K_UP:
|
|
|
|
ludzik_y -= 10
|
|
|
|
elif event.key == pygame.K_DOWN:
|
|
|
|
ludzik_y += 10
|
|
|
|
|
|
|
|
screen.fill((255, 255, 255))
|
|
|
|
|
|
|
|
# wyświetlenie mapy i ludzika
|
|
|
|
screen.blit(mapa_pygame, (0, 0))
|
|
|
|
screen.blit(ludzik_pygame, (ludzik_x, ludzik_y))
|
2023-03-09 19:44:02 +01:00
|
|
|
|
2023-03-11 08:23:30 +01:00
|
|
|
# odświeżenie ekranu
|
|
|
|
pygame.display.update()
|