diff --git a/README.md b/README.md index a3db09c..7148fde 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # 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. \ No newline at end of file diff --git a/gameContext.py b/gameContext.py new file mode 100644 index 0000000..a59e292 --- /dev/null +++ b/gameContext.py @@ -0,0 +1,12 @@ +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)) diff --git a/gameEventHandler.py b/gameEventHandler.py index 106f1e8..479fb9e 100644 --- a/gameEventHandler.py +++ b/gameEventHandler.py @@ -1,4 +1,24 @@ import pygame +from gameContext import GameContext -def handle_game_event(event): - return \ No newline at end of file +def handle_game_event(event, game_context: GameContext): + dust_car_movement(event, game_context) + 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)) diff --git a/garbage.py b/garbage.py new file mode 100644 index 0000000..5769b4a --- /dev/null +++ b/garbage.py @@ -0,0 +1,21 @@ +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 \ No newline at end of file diff --git a/garbageCan.py b/garbageCan.py new file mode 100644 index 0000000..ecab807 --- /dev/null +++ b/garbageCan.py @@ -0,0 +1,16 @@ +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) \ No newline at end of file diff --git a/imgs/container.png b/imgs/container.png new file mode 100644 index 0000000..05a0bdf Binary files /dev/null and b/imgs/container.png differ diff --git a/imgs/dust_car.png b/imgs/dust_car.png new file mode 100644 index 0000000..9594b24 Binary files /dev/null and b/imgs/dust_car.png differ diff --git a/imgs/house.jpg b/imgs/house.jpg deleted file mode 100644 index a62ea8d..0000000 Binary files a/imgs/house.jpg and /dev/null differ diff --git a/main.py b/main.py deleted file mode 100644 index 74f4380..0000000 --- a/main.py +++ /dev/null @@ -1,45 +0,0 @@ -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()