Inteligentny_Wozek/main.py
2023-03-21 12:36:50 +01:00

72 lines
2.1 KiB
Python

import sys
import pygame
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)
class Wozek:
def __init__(self):
self.x = 55
self.y = 55
self.height = 64
self.width = 64
self.image = pygame.image.load("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))
def main():
wozek = Wozek()
while True:
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:
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
# Drawing
screen.fill((0, 0, 0)) # 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)
draw_grid()
wozek.draw()
pygame.display.flip() # updating frames
if __name__ == "__main__":
main()