display stick man in window
This commit is contained in:
parent
03e2aea285
commit
9f7bc7f3e1
5
gameContext.py
Normal file
5
gameContext.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class GameContext:
|
||||||
|
dust_car_position_x = 0
|
||||||
|
dust_car_position_y = 0
|
||||||
|
stick_man_pygame = None
|
||||||
|
canvas = None
|
@ -1,4 +1,9 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
from gameContext import GameContext
|
||||||
|
|
||||||
def handle_game_event(event):
|
def handle_game_event(event, game_context: GameContext):
|
||||||
|
update_canvas(game_context)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def update_canvas(game_context: GameContext):
|
||||||
|
game_context.canvas.blit(game_context.stick_man_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y))
|
11
main.py
11
main.py
@ -1,11 +1,20 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from gameEventHandler import handle_game_event
|
from gameEventHandler import handle_game_event
|
||||||
|
from gameContext import GameContext
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
pygame.init()
|
pygame.init()
|
||||||
|
|
||||||
canvas = pygame.display.set_mode((800, 800))
|
canvas = pygame.display.set_mode((800, 800))
|
||||||
|
|
||||||
pygame.display.set_caption("Inteligentna śmieciarka")
|
pygame.display.set_caption("Inteligentna śmieciarka")
|
||||||
|
stick_man_pil = Image.open('imgs/sickMan.jpg')
|
||||||
|
|
||||||
|
gameContext = GameContext()
|
||||||
|
gameContext.stick_man_pygame = pygame.image.frombuffer(stick_man_pil.tobytes(), stick_man_pil.size, 'RGB')
|
||||||
|
gameContext.canvas = canvas
|
||||||
|
|
||||||
|
|
||||||
exit = False
|
exit = False
|
||||||
|
|
||||||
while not exit:
|
while not exit:
|
||||||
@ -13,6 +22,6 @@ while not exit:
|
|||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
exit = True
|
exit = True
|
||||||
else:
|
else:
|
||||||
handle_game_event(event)
|
handle_game_event(event, gameContext)
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
Loading…
Reference in New Issue
Block a user