Compare commits

..

No commits in common. "cb890c028c09462244d20b31fceabe314d6bc1a6" and "a146880414a400878937e53e7a77eb3834160892" have entirely different histories.

9 changed files with 47 additions and 72 deletions

View File

@ -1,3 +1,2 @@
# sztuczna_inteligencja_2023_smieciarka # sztuczna_inteligencja_2023_smieciarka
Symulacja inteligentnej śmieciarki. Śmieciarka zbiera śmieci z kubłów wystawionych przez mieszkańców, samodzielnie je segreguje i zawozi na wysypisko.

View File

@ -1,12 +0,0 @@
import pygame
class GameContext:
dust_car_speed = 20
dust_car_position_x = 0
dust_car_position_y = 0
dust_car_pygame = None
dust_car_pil = None
canvas = None
def startup(game_context: GameContext):
game_context.canvas.blit(game_context.dust_car_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y))

View File

@ -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.dust_car_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.dust_car_pygame, (game_context.dust_car_position_x, game_context.dust_car_position_y))

View File

@ -1,21 +0,0 @@
from enum import Enum
class GarbageType (Enum):
PAPER = 0,
PLASTIC_AND_METAL = 1
GLASS = 3
BIO = 4
MIXED = 5
class Garbage:
img: str
def __init__(self, img: str) -> None:
self.img = img
class RecognizedGarbage (Garbage):
garbage_type: GarbageType
def __init__(self, src: Garbage, garbage_type: GarbageType) -> None:
super().__init__(src.img)
self.garbage_type = garbage_type

View File

@ -1,16 +0,0 @@
from garbage import RecognizedGarbage
from typing import List, Tuple
class GarbageCan:
position: Tuple[float, float]
garbage: List[RecognizedGarbage]
def __init__(self, position: Tuple[float, float]) -> None:
self.position = position
self.garbage = []
def add_garbage(self, garbage: RecognizedGarbage) -> None:
self.garbage.append(garbage)
def remove_garbage(self, garbage: RecognizedGarbage) -> None:
self.garbage.remove(garbage)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 331 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 348 B

BIN
imgs/house.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

45
main.py Normal file
View File

@ -0,0 +1,45 @@
from gameEventHandler import handle_game_event
import pygame
from PIL import Image
pygame.init()
window_size = (800, 600)
screen = pygame.display.set_mode(window_size)
# 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')
# pozycja ludzika
ludzik_x = 0
ludzik_y = 0
# główna pętla gry
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
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))
# odświeżenie ekranu
pygame.display.update()