diff --git a/__pycache__/main.cpython-310.pyc b/__pycache__/main.cpython-310.pyc new file mode 100644 index 0000000..0a7d4f0 Binary files /dev/null and b/__pycache__/main.cpython-310.pyc differ diff --git a/__pycache__/regal.cpython-310.pyc b/__pycache__/regal.cpython-310.pyc new file mode 100644 index 0000000..d394c2a Binary files /dev/null and b/__pycache__/regal.cpython-310.pyc differ diff --git a/images/icon.png b/images/icon.png new file mode 100644 index 0000000..4046b9a Binary files /dev/null and b/images/icon.png differ diff --git a/paczka_obrazek.png b/images/paczka.png similarity index 100% rename from paczka_obrazek.png rename to images/paczka.png diff --git a/wozek.png b/images/pelny_wozek.png similarity index 100% rename from wozek.png rename to images/pelny_wozek.png diff --git a/images/pusty_wozek.png b/images/pusty_wozek.png new file mode 100644 index 0000000..463e7d0 Binary files /dev/null and b/images/pusty_wozek.png differ diff --git a/images/regal.png b/images/regal.png new file mode 100644 index 0000000..83a3e9a Binary files /dev/null and b/images/regal.png differ diff --git a/images/regal1.png b/images/regal1.png new file mode 100644 index 0000000..e099f54 Binary files /dev/null and b/images/regal1.png differ diff --git a/images/regal2.png b/images/regal2.png new file mode 100644 index 0000000..23c2a55 Binary files /dev/null and b/images/regal2.png differ diff --git a/images/regal3.png b/images/regal3.png new file mode 100644 index 0000000..ba51f82 Binary files /dev/null and b/images/regal3.png differ diff --git a/main.py b/main.py index c177c6f..3a84ecc 100644 --- a/main.py +++ b/main.py @@ -4,23 +4,20 @@ import regal pygame.init() screen = pygame.display.set_mode((980, 980)) -c = (0, 150, 0) - - -def draw_grid(): - for y in range(80, 960, 80): # horizontal lines - pygame.draw.line(screen, c, (80, y), (960 - 80, y), 1) - for x in range(80, 960, 80): # vertical lines - pygame.draw.line(screen, c, (x, 80), (x, 960 - 80), 1) +pygame.display.set_caption("Inteligentny wozek") +icon = pygame.image.load('images/icon.png') +pygame.display.set_icon(icon) class Wozek: def __init__(self): self.x = 55 self.y = 55 + self.x_change = 0 + self.y_change = 0 self.height = 64 self.width = 64 - self.image = pygame.image.load("wozek.png") + self.image = pygame.image.load("images/pusty_wozek.png") # Credit: Forklift icons created by Smashicons - Flaticon # https://www.flaticon.com/free-icons/forklift @@ -35,33 +32,62 @@ def main(): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) - elif event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: + if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: sys.exit(0) - elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: - if wozek.y <= 800: - wozek.y += 80 - elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: - if wozek.y >= 100: - wozek.y -= 80 - elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT: - if wozek.x <= 800: - wozek.x += 80 - elif event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT: - if wozek.x >= 100: - wozek.x -= 80 + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_DOWN: + wozek.y_change = 1 + if event.key == pygame.K_UP: + wozek.y_change = -1 + if event.key == pygame.K_RIGHT: + wozek.x_change = 1 + if event.key == pygame.K_LEFT: + wozek.x_change = -1 + + if event.type == pygame.KEYUP: + if event.key == pygame.K_DOWN or event.key == pygame.K_UP: + wozek.y_change = 0 + if event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT: + wozek.x_change = 0 + + wozek.x += wozek.x_change + wozek.y += wozek.y_change + + if wozek.x <= 0: + wozek.x = 0 + elif wozek.x >= 916: + wozek.x = 916 + if wozek.y <= 0: + wozek.y = 0 + elif wozek.x >= 916: + wozek.x = 916 # Drawing - screen.fill((0, 0, 0)) # removes object trail + screen.fill((51,51,51)) # removes object trail # idRegału, Długość regału podana w kratkach, Współrzędne od których ma być tworzony regał (wiersz,kolumna) - poziomo # Współrzędne od (1,1) do (10,10) - regal1 = regal.Regal(1, 5, 1, 1) - regal.Regal(2, 10, 2, 3) - regal.Regal(3, 2, 3, 7) - regal.Regal(4, 1, 10, 10) + regal.Regal(1, 1, 2, 2) + regal.Regal(2, 1, 2, 3) + regal.Regal(3, 1, 3, 2) + regal.Regal(4, 1, 3, 3) + + regal.Regal(5, 1, 8, 2) + regal.Regal(6, 1, 8, 3) + regal.Regal(7, 1, 9, 2) + regal.Regal(8, 1, 9, 3) + + regal.Regal(9, 1, 2, 8) + regal.Regal(10, 1, 2, 9) + regal.Regal(11, 1, 3, 8) + regal.Regal(12, 1, 3, 9) + + regal.Regal(13, 1, 8, 8) + regal.Regal(14, 1, 8, 9) + regal.Regal(15, 1, 9, 8) + regal.Regal(16, 1, 9, 9) - draw_grid() wozek.draw() pygame.display.flip() # updating frames diff --git a/paczka.py b/paczka.py index c952b95..7a6aec7 100644 --- a/paczka.py +++ b/paczka.py @@ -12,7 +12,7 @@ class Paczka: self.y = 0 self.szerokosc = 0 self.wysokosc = 0 - self.image = pygame.image.load("paczka_obrazek.png") + self.image = pygame.image.load("images/paczka_obrazek.png") # zmienia rozmiar obrazka w zaleznosci od rozmiaru def __dobierz_rozmiar_obrazka(self): diff --git a/regal.py b/regal.py index 428fd07..6d26ad4 100644 --- a/regal.py +++ b/regal.py @@ -21,7 +21,7 @@ def obliczPixeleDlugosciRegalu(self): #Przeliczanie dlugości regału podanego class Regal: def __init__(self, numerRegalu, dlugoscRegaluWKratkach, numerWiersza, numerKolumny): self.numerRegalu = numerRegalu - self.wysokoscRegalu = 40 + self.wysokoscRegalu = 64 self.dlugoscRegaluWKratkach = dlugoscRegaluWKratkach self.numerKolumny = numerKolumny @@ -29,7 +29,23 @@ class Regal: self.kolumna = obliczPixeleNaPodstawieKratek(numerKolumny) self.dlugosc = obliczPixeleDlugosciRegalu(self) - reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu]) - reg.fill((255, 0, 0)) - screen.blit(reg, (self.wiersz, self.kolumna)) + if(self.numerRegalu >= 0 and self.numerRegalu <= 4): + reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu]) + reg = pygame.image.load("images/regal.png") + screen.blit(reg, (self.wiersz, self.kolumna)) + + if(self.numerRegalu >= 5 and self.numerRegalu <= 8): + reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu]) + reg = pygame.image.load("images/regal1.png") + screen.blit(reg, (self.wiersz, self.kolumna)) + + if(self.numerRegalu >= 9 and self.numerRegalu <= 12): + reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu]) + reg = pygame.image.load("images/regal2.png") + screen.blit(reg, (self.wiersz, self.kolumna)) + + if(self.numerRegalu >= 13 and self.numerRegalu <= 16): + reg = pygame.Surface([self.dlugosc, self.wysokoscRegalu]) + reg = pygame.image.load("images/regal3.png") + screen.blit(reg, (self.wiersz, self.kolumna))