Compare commits
17 Commits
a146880414
...
cb890c028c
Author | SHA1 | Date | |
---|---|---|---|
|
cb890c028c | ||
94e65feaa9 | |||
|
9b3902a163 | ||
27a5589146 | |||
|
d340f2cebe | ||
a364695ff1 | |||
|
4dedaf57cb | ||
dd54ef193f | |||
|
58437a4854 | ||
4c385d0674 | |||
|
5de5994519 | ||
|
454fb8dcce | ||
ca41c47dd9 | |||
|
b8b2e5e319 | ||
|
853b025a84 | ||
|
9f7bc7f3e1 | ||
|
03e2aea285 |
@ -1,2 +1,3 @@
|
|||||||
# 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.
|
12
gameContext.py
Normal file
12
gameContext.py
Normal file
@ -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))
|
@ -1,4 +1,24 @@
|
|||||||
import pygame
|
import pygame
|
||||||
|
from gameContext import GameContext
|
||||||
|
|
||||||
def handle_game_event(event):
|
def handle_game_event(event, game_context: GameContext):
|
||||||
return
|
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))
|
||||||
|
21
garbage.py
Normal file
21
garbage.py
Normal file
@ -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
|
16
garbageCan.py
Normal file
16
garbageCan.py
Normal file
@ -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)
|
BIN
imgs/container.png
Normal file
BIN
imgs/container.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 331 B |
BIN
imgs/dust_car.png
Normal file
BIN
imgs/dust_car.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 348 B |
BIN
imgs/house.jpg
BIN
imgs/house.jpg
Binary file not shown.
Before Width: | Height: | Size: 5.3 KiB |
45
main.py
45
main.py
@ -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()
|
|
Loading…
Reference in New Issue
Block a user