movement #3
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
|
||||
from gameContext import GameContext
|
||||
|
||||
def handle_game_event(event):
|
||||
return
|
||||
def handle_game_event(event, game_context: GameContext):
|
||||
update_canvas(game_context)
|
||||
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
|
||||
from gameEventHandler import handle_game_event
|
||||
from gameContext import GameContext
|
||||
from PIL import Image
|
||||
|
||||
pygame.init()
|
||||
|
||||
canvas = pygame.display.set_mode((800, 800))
|
||||
|
||||
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
|
||||
|
||||
while not exit:
|
||||
@ -13,6 +22,6 @@ while not exit:
|
||||
if event.type == pygame.QUIT:
|
||||
exit = True
|
||||
else:
|
||||
handle_game_event(event)
|
||||
handle_game_event(event, gameContext)
|
||||
|
||||
pygame.display.update()
|
Loading…
Reference in New Issue
Block a user