Compare commits

..

17 Commits

Author SHA1 Message Date
Wiktor Szynaka
cb890c028c garbageCan 2023-03-26 14:33:33 +02:00
94e65feaa9 Merge pull request 'add garbage class' (#8) from garbage into master
Reviewed-on: #8
Reviewed-by: Mikołaj Gawor <mikgaw@st.amu.edu.pl>
2023-03-25 17:50:08 +01:00
Pawel Felcyn
9b3902a163 add garbage class 2023-03-25 10:53:19 +01:00
27a5589146 Merge pull request 'replace house with container' (#7) from container_img into master
Reviewed-on: #7
2023-03-25 10:35:32 +01:00
Pawel Felcyn
d340f2cebe replace house with container 2023-03-25 10:30:52 +01:00
a364695ff1 Merge pull request 'modify readme' (#6) from project_desc into master
Reviewed-on: #6
2023-03-18 13:23:19 +01:00
Pawel Felcyn
4dedaf57cb modify readme 2023-03-18 13:22:01 +01:00
dd54ef193f Merge pull request 'changed stick man to dust car, renamed variables' (#5) from changing_stick_man_to_dust_car into master
Reviewed-on: #5
2023-03-13 09:53:56 +01:00
majkellll
58437a4854 changed stick man to dust car, renamed variables 2023-03-13 08:49:34 +01:00
4c385d0674 Merge pull request 'dust_car_img' (#4) from dust_car_img into master
Reviewed-on: #4
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-03-12 18:32:05 +01:00
majkellll
5de5994519 "add smaller dust car image" 2023-03-12 17:08:37 +01:00
majkellll
454fb8dcce add dust car image 2023-03-12 16:59:15 +01:00
ca41c47dd9 Merge pull request 'movement' (#3) from movement into master
Reviewed-on: #3
2023-03-12 16:51:41 +01:00
Pawel Felcyn
b8b2e5e319 rename stick man file 2023-03-12 16:49:32 +01:00
Pawel Felcyn
853b025a84 add stick man movement 2023-03-12 16:47:18 +01:00
Pawel Felcyn
9f7bc7f3e1 display stick man in window 2023-03-12 16:08:54 +01:00
Pawel Felcyn
03e2aea285 add stick man img 2023-03-11 15:17:35 +01:00
9 changed files with 72 additions and 47 deletions

View File

@ -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
View 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))

View File

@ -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):
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))

21
garbage.py Normal file
View 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
View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 331 B

BIN
imgs/dust_car.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

45
main.py
View File

@ -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()