127 lines
3.9 KiB
Python
127 lines
3.9 KiB
Python
import sys
|
|
import pygame
|
|
import regal
|
|
import paczka
|
|
#from wozek import Wozek
|
|
|
|
pygame.init()
|
|
screen = pygame.display.set_mode((980, 980))
|
|
miejsce = pygame.image.load('images/miejsce_paczek.png')
|
|
|
|
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("images/pusty_wozek.png")
|
|
# Credit: Forklift icons created by Smashicons - Flaticon
|
|
# https://www.flaticon.com/free-icons/forklift
|
|
|
|
def draw(self):
|
|
screen.blit(self.image, (self.x, self.y))
|
|
|
|
#storage = ["none"] * 10
|
|
storage = []
|
|
max_size = 10
|
|
|
|
def add_element(element, storage, max_size):
|
|
if len(storage) < max_size:
|
|
storage.append(element)
|
|
else:
|
|
print("I'm full!")
|
|
def remove_element(storage):
|
|
if len(storage) > 0:
|
|
place = storage.pop()
|
|
return place
|
|
else:
|
|
print("I'm empty!")
|
|
|
|
def dynamic_wozek_picture(wozek, storage):
|
|
if len(storage) == 0:
|
|
wozek.image = pygame.image.load("images/pusty_wozek.png")
|
|
elif ((len(storage) > 0) and (len(storage) < 4)):
|
|
wozek.image = pygame.image.load("images/pelny_wozek_1_crate.png")
|
|
elif ((len(storage) > 3) and (len(storage) < 10)):
|
|
wozek.image = pygame.image.load("images/pelny_wozek_2_crates.png")
|
|
elif (len(storage) == 10):
|
|
wozek.image = pygame.image.load("images/pelny_wozek_full_3_crates.png")
|
|
|
|
|
|
def main():
|
|
wozek = Wozek()
|
|
while True:
|
|
for event in pygame.event.get():
|
|
if event.type == pygame.QUIT:
|
|
sys.exit(0)
|
|
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
|
|
sys.exit(0)
|
|
|
|
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((51,51,51)) # removes object trail
|
|
screen.blit(miejsce, (430, 400))
|
|
|
|
# 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)
|
|
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)
|
|
|
|
wozek.draw()
|
|
|
|
pygame.display.flip() # updating frames
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|