forked from s474139/Inteligentny_Wozek
added letters
This commit is contained in:
parent
aa340e68d3
commit
133e54ab12
28
ekran.py
28
ekran.py
@ -1,7 +1,7 @@
|
||||
import pygame
|
||||
import plansza
|
||||
from regal import Regal
|
||||
from packageList import *
|
||||
from itemList import *
|
||||
|
||||
EKRAN_SZEROKOSC = 770
|
||||
EKRAN_WYSOKOSC = 770
|
||||
@ -14,8 +14,9 @@ pygame.display.set_caption("Inteligentny wozek")
|
||||
icon = pygame.image.load('images/icon.png')
|
||||
pygame.display.set_icon(icon)
|
||||
|
||||
lista_paczek = []
|
||||
lista_itemow = []
|
||||
lista_paczek_na_regalach = []
|
||||
lista_listow_w_skrzynce = []
|
||||
|
||||
def narysuj_regaly():
|
||||
global lista_regalow
|
||||
@ -62,7 +63,7 @@ def odswiez_ekran(wozek):
|
||||
screen.blit(miejsce,(plansza.a_pix, plansza.b_pix))
|
||||
screen.blit(skrzynka,(plansza.c_pix, plansza.d_pix))
|
||||
narysuj_siatke()
|
||||
narysuj_paczki(wozek)
|
||||
narysuj_items()
|
||||
narysuj_paczke_na_regale()
|
||||
narysuj_regaly()
|
||||
wozek.draw()
|
||||
@ -85,17 +86,26 @@ def sprawdz_ktora_kolumna(y):
|
||||
nr_kolumny = nr_kolumny + 1
|
||||
|
||||
|
||||
def narysuj_paczki(wozek):
|
||||
for paczka in lista_paczek:
|
||||
paczka.narysuj(paczka.x, paczka.y, screen)
|
||||
def narysuj_items():
|
||||
for item in lista_itemow:
|
||||
item.narysuj(item.x, item.y, screen)
|
||||
|
||||
def narysuj_paczke_na_regale():
|
||||
for paczka in lista_paczek_na_regalach:
|
||||
if paczka.is_in_move is False:
|
||||
paczka.narysuj(paczka.x, paczka.y, screen)
|
||||
|
||||
def dodaj_paczki_na_rampe(p1, p2):
|
||||
lista_paczek.append(p1)
|
||||
lista_paczek.append(p2)
|
||||
def narysuj_list_na_skrzynce():
|
||||
for letter in lista_listow_w_skrzynce:
|
||||
if letter.is_in_move is False:
|
||||
letter.narysuj(letter.x, letter.y, screen)
|
||||
|
||||
def dodaj_na_rampe(p1, p2, l1, l2):
|
||||
lista_itemow.append(p1)
|
||||
lista_itemow.append(p2)
|
||||
lista_itemow.append(l1)
|
||||
lista_itemow.append(l2)
|
||||
p1.update_position(plansza.a_pix, plansza.b_pix)
|
||||
p2.update_position(plansza.a_pix, plansza.b_pix)
|
||||
l1.update_position(plansza.a_pix, plansza.b_pix)
|
||||
l2.update_position(plansza.a_pix, plansza.b_pix)
|
BIN
images/letter.png
Normal file
BIN
images/letter.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
@ -2,17 +2,17 @@ import pygame
|
||||
|
||||
# from paczka import Paczka
|
||||
|
||||
class listOfPackages:
|
||||
class listOfItems:
|
||||
list = []
|
||||
package_group = pygame.sprite.Group()
|
||||
item_group = pygame.sprite.Group()
|
||||
|
||||
def add(self, item):
|
||||
self.list.append(item)
|
||||
self.package_group.add(item)
|
||||
self.item_group.add(item)
|
||||
|
||||
def remove(self):
|
||||
last_package = self.list.pop()
|
||||
self.package_group.remove(last_package)
|
||||
last_item = self.list.pop()
|
||||
self.item_group.remove(last_item)
|
||||
|
||||
|
||||
# def zainicjuj_liste_paczek(init_x, init_y):
|
23
letter.py
Normal file
23
letter.py
Normal file
@ -0,0 +1,23 @@
|
||||
import pygame
|
||||
|
||||
letter_pic = pygame.image.load("images/letter.png")
|
||||
|
||||
class Letter(pygame.sprite.Sprite):
|
||||
def __init__(self, id):
|
||||
super().__init__()
|
||||
self.id = id
|
||||
self.image = pygame.transform.scale(letter_pic, (40, 40))
|
||||
self.rect = self.image.get_rect()
|
||||
self.x = 430
|
||||
self.y = 400
|
||||
self.is_in_move = False
|
||||
|
||||
def narysuj(self, x, y, screen):
|
||||
self.x = x
|
||||
self.y = y
|
||||
screen.blit(self.image, (self.x, self.y))
|
||||
|
||||
def update_position(self, x, y):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.rect.topleft = (x, y)
|
32
main.py
32
main.py
@ -3,10 +3,12 @@ import sys
|
||||
import joblib
|
||||
import pygame
|
||||
from paczka import Paczka
|
||||
from letter import Letter
|
||||
from wozek import Wozek
|
||||
import wyszukiwanie
|
||||
import ekran
|
||||
from grid import GridCellType, SearchGrid
|
||||
import plansza
|
||||
|
||||
|
||||
from plansza import a_pix, b_pix
|
||||
@ -17,7 +19,9 @@ def main():
|
||||
wozek = Wozek()
|
||||
p1 = Paczka('duzy', 12, 'narzedzia', False, True, False, any, any, any, any, any)
|
||||
p2 = Paczka('maly', 1, 'ogród', False, True, False, any, any, any, any, any)
|
||||
ekran.dodaj_paczki_na_rampe(p1, p2)
|
||||
l1 = Letter(1)
|
||||
l2 = Letter(2)
|
||||
ekran.dodaj_na_rampe(p2, l1, p1, l2)
|
||||
grid_points = SearchGrid()
|
||||
|
||||
# Odczyt drzewa z pliku
|
||||
@ -31,9 +35,8 @@ def main():
|
||||
sys.exit(0)
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_SPACE:
|
||||
## sprawdzenie czy lista z paczkami nie jest pusta
|
||||
if ekran.lista_paczek:
|
||||
## wozek jedzie po paczke
|
||||
|
||||
## wozek jedzie po itemy
|
||||
wiersz = ekran.sprawdz_ktory_wiersz(a_pix)
|
||||
kolumna = ekran.sprawdz_ktora_kolumna(b_pix)
|
||||
docelowy_stan = wyszukiwanie.Stan(wiersz * 70, kolumna * 70, 1)
|
||||
@ -43,13 +46,17 @@ def main():
|
||||
sciezka = wyszukiwanie.znajdz_sciezke(wezel)
|
||||
wozek.przemiesc_wozek_po_sciezce(sciezka)
|
||||
|
||||
if grid_points.grid[(wiersz, kolumna)] is GridCellType.PLACE: #picks up package
|
||||
## sprawdzenie czy lista itemow nie jest pusta
|
||||
if ekran.lista_itemow:
|
||||
if grid_points.grid[(wiersz, kolumna)] is GridCellType.PLACE: #picks up item
|
||||
if wozek.ln == 0:
|
||||
wozek.picks_up_package()
|
||||
wozek.picks_up_item()
|
||||
wozek.dynamic_wozek_picture()
|
||||
|
||||
przenoszony_item = wozek.storage[-1]
|
||||
if isinstance(przenoszony_item,Paczka):
|
||||
## wozek jedzie odlozyc paczke na regal
|
||||
przenoszona_paczka = wozek.storage[-1]
|
||||
przenoszona_paczka = przenoszony_item
|
||||
|
||||
array, reg = przenoszona_paczka.tablica_do_drzewa(przenoszona_paczka.kategoria)
|
||||
|
||||
@ -68,6 +75,17 @@ def main():
|
||||
if wozek.ln != 0: # drops package
|
||||
wozek.drops_package(przenoszona_paczka, reg, predictions)
|
||||
wozek.dynamic_wozek_picture()
|
||||
else:
|
||||
#list przenoszony do skrzynki
|
||||
docelowy_stan = wyszukiwanie.Stan(plansza.c_pix, plansza.d_pix, 1)
|
||||
wezel = wyszukiwanie.wyszukiwanie_a_star(wozek.obecnyStan, docelowy_stan, grid_points)
|
||||
sciezka = wyszukiwanie.znajdz_sciezke(wezel)
|
||||
wozek.przemiesc_wozek_po_sciezce(sciezka)
|
||||
|
||||
if wozek.ln != 0: # drops letter
|
||||
wozek.drops_letter(przenoszony_item)
|
||||
wozek.dynamic_wozek_picture()
|
||||
|
||||
|
||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||
# lewy przycisk myszy
|
||||
|
28
wozek.py
28
wozek.py
@ -1,9 +1,11 @@
|
||||
import ekran
|
||||
import pygame,math
|
||||
# from packageList import listOfPackages
|
||||
from ekran import lista_paczek
|
||||
from ekran import lista_itemow
|
||||
from letter import Letter
|
||||
import plansza
|
||||
|
||||
listOfPackages = lista_paczek
|
||||
listOfPackages = lista_itemow
|
||||
|
||||
class Wozek(pygame.sprite.Sprite):
|
||||
def __init__(self):
|
||||
@ -118,11 +120,17 @@ class Wozek(pygame.sprite.Sprite):
|
||||
else:
|
||||
self.image = pygame.transform.rotate(self.image, 90)
|
||||
|
||||
def picks_up_package(self):
|
||||
paczka_pop = ekran.lista_paczek.pop()
|
||||
ekran.lista_paczek_na_regalach.append(paczka_pop)
|
||||
paczka_pop.is_in_move = True
|
||||
self.storage.append(paczka_pop)
|
||||
def picks_up_item(self):
|
||||
item_pop = ekran.lista_itemow.pop()
|
||||
if isinstance(item_pop,Letter):
|
||||
ekran.lista_listow_w_skrzynce.append(item_pop)
|
||||
item_pop.is_in_move = True
|
||||
self.storage.append(item_pop)
|
||||
self.ln = self.ln + 1
|
||||
else:
|
||||
ekran.lista_paczek_na_regalach.append(item_pop)
|
||||
item_pop.is_in_move = True
|
||||
self.storage.append(item_pop)
|
||||
self.ln = self.ln + 1
|
||||
|
||||
def drops_package(self, paczka, reg, predictions):
|
||||
@ -132,3 +140,9 @@ class Wozek(pygame.sprite.Sprite):
|
||||
self.ln = self.ln - 1
|
||||
reg.put_package_on_the_regal(paczka, predictions)
|
||||
|
||||
def drops_letter(self, letter):
|
||||
letter.update_position(plansza.c_pix, plansza.d_pix)
|
||||
letter.is_in_move = False
|
||||
self.storage.pop()
|
||||
self.ln = self.ln - 1
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user