Compare commits
No commits in common. "ca41c47dd9c9d7fc57393f26f42f56ca472e61ad" and "c5e9a7de0c57fb172ed33d7ddfc270176ea0d478" have entirely different histories.
ca41c47dd9
...
c5e9a7de0c
@ -1,12 +0,0 @@
|
|||||||
import pygame
|
|
||||||
|
|
||||||
class GameContext:
|
|
||||||
dust_car_speed = 20
|
|
||||||
dust_car_position_x = 0
|
|
||||||
dust_car_position_y = 0
|
|
||||||
stick_man_pygame = None
|
|
||||||
stick_man_pil = None
|
|
||||||
canvas = None
|
|
||||||
|
|
||||||
def startup(game_context: GameContext):
|
|
||||||
game_context.canvas.blit(game_context.stick_man_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y))
|
|
@ -1,24 +1,4 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from gameContext import GameContext
|
|
||||||
|
|
||||||
def handle_game_event(event, game_context: GameContext):
|
def handle_game_event(event):
|
||||||
dust_car_movement(event, game_context)
|
return
|
||||||
return
|
|
||||||
|
|
||||||
def dust_car_movement(event, game_context:GameContext):
|
|
||||||
if event.type != pygame.KEYDOWN:
|
|
||||||
return
|
|
||||||
(width, height) = game_context.stick_man_pil.size
|
|
||||||
if event.key == pygame.K_LEFT:
|
|
||||||
pygame.draw.rect(game_context.canvas, (0, 0, 0), (game_context.dust_car_position_x, game_context.dust_car_position_y, width, height))
|
|
||||||
game_context.dust_car_position_x -= game_context.dust_car_speed
|
|
||||||
elif event.key == pygame.K_RIGHT:
|
|
||||||
pygame.draw.rect(game_context.canvas, (0, 0, 0), (game_context.dust_car_position_x, game_context.dust_car_position_y, width, height))
|
|
||||||
game_context.dust_car_position_x += game_context.dust_car_speed
|
|
||||||
elif event.key == pygame.K_UP:
|
|
||||||
pygame.draw.rect(game_context.canvas, (0, 0, 0), (game_context.dust_car_position_x, game_context.dust_car_position_y, width, height))
|
|
||||||
game_context.dust_car_position_y -= game_context.dust_car_speed
|
|
||||||
elif event.key == pygame.K_DOWN:
|
|
||||||
pygame.draw.rect(game_context.canvas, (0, 0, 0), (game_context.dust_car_position_x, game_context.dust_car_position_y, width, height))
|
|
||||||
game_context.dust_car_position_y += game_context.dust_car_speed
|
|
||||||
game_context.canvas.blit(game_context.stick_man_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y))
|
|
Binary file not shown.
Before Width: | Height: | Size: 29 KiB |
14
main.py
14
main.py
@ -1,23 +1,11 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from gameEventHandler import handle_game_event
|
from gameEventHandler import handle_game_event
|
||||||
from gameContext import GameContext
|
|
||||||
from gameContext import startup
|
|
||||||
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/stickMan.jpg')
|
|
||||||
|
|
||||||
game_context = GameContext()
|
|
||||||
game_context.stick_man_pil = stick_man_pil
|
|
||||||
game_context.stick_man_pygame = pygame.image.frombuffer(stick_man_pil.tobytes(), stick_man_pil.size, 'RGB')
|
|
||||||
game_context.canvas = canvas
|
|
||||||
startup(game_context)
|
|
||||||
|
|
||||||
|
|
||||||
exit = False
|
exit = False
|
||||||
|
|
||||||
while not exit:
|
while not exit:
|
||||||
@ -25,6 +13,6 @@ while not exit:
|
|||||||
if event.type == pygame.QUIT:
|
if event.type == pygame.QUIT:
|
||||||
exit = True
|
exit = True
|
||||||
else:
|
else:
|
||||||
handle_game_event(event, game_context)
|
handle_game_event(event)
|
||||||
|
|
||||||
pygame.display.update()
|
pygame.display.update()
|
Loading…
Reference in New Issue
Block a user