movement and graphics changed

This commit is contained in:
Zuzanna Wójcik 2023-03-26 21:21:52 +02:00
parent 6f3ce87ac2
commit b369c5d21c
13 changed files with 75 additions and 33 deletions

Binary file not shown.

Binary file not shown.

BIN
images/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

BIN
images/pusty_wozek.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

BIN
images/regal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
images/regal1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 964 B

BIN
images/regal2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 B

BIN
images/regal3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 957 B

82
main.py
View File

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

View File

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

View File

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