wozek-projekt/main.py

88 lines
2.8 KiB
Python
Raw Normal View History

2023-03-12 22:45:43 +01:00
import pygame
from pygame.locals import *
HORIZONTAL = 1250 # poziomy wymiar okna
VERTICAL = 750 # pionowy wymiar okna
TILE_SIZE = 50 # rozmiar kafelka
background = (49, 51, 53) # kolor tla
line_color = (85, 85, 85) # kolor linii
shelf = (138, 126, 74) # kolor polki
window = pygame.display.set_mode((HORIZONTAL, VERTICAL)) # okno 1250 x 750
pygame.display.set_caption('Autonomiczny wózek widłowy')
def drawGrid():
num_of_columns = int(HORIZONTAL / TILE_SIZE)
num_of_rows = int(VERTICAL / TILE_SIZE)
x = 0
y = 0
for i in range(num_of_columns):
x += TILE_SIZE
pygame.draw.line(window, line_color, (x, 0), (x, VERTICAL))
for i in range(num_of_rows):
y += TILE_SIZE
pygame.draw.line(window, line_color, (0, y), (HORIZONTAL, y))
def drawShelves():
width = 5 * TILE_SIZE
height = TILE_SIZE
for i in range(TILE_SIZE + 1, HORIZONTAL - TILE_SIZE, 6 * TILE_SIZE):
pygame.draw.rect(window, shelf, pygame.Rect(i, 0, width, height))
pygame.draw.rect(window, shelf, pygame.Rect(i, 101, width, height))
pygame.draw.rect(window, shelf, pygame.Rect(i, 201, width, height))
pygame.draw.rect(window, shelf, pygame.Rect(i, 501, width, height))
pygame.draw.rect(window, shelf, pygame.Rect(i, 601, width, height))
pygame.draw.rect(window, shelf, pygame.Rect(i, 701, width, height))
class Forklift:
def __init__(self):
self.image = pygame.image.load('resources/images.png').convert_alpha()
self.x = 50
self.y = 350
def drawForklift(self):
window.blit(self.image, (self.x, self.y))
class Package:
def __init__(self):
self.image = pygame.image.load('resources/indeks.png').convert_alpha()
self.x = 1150
self.y = 350
def drawPackage(self):
window.blit(self.image, (self.x, self.y))
def run():
running = True
forklift = Forklift()
package = Package()
while running:
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_RIGHT:
forklift.x += TILE_SIZE
if event.key == K_LEFT:
forklift.x -= TILE_SIZE
if event.key == K_UP:
forklift.y -= TILE_SIZE
if event.key == K_DOWN:
forklift.y += TILE_SIZE
if event.key == K_ESCAPE:
running = False
elif event.type == pygame.QUIT:
running = False
window.fill(background)
drawGrid()
drawShelves()
forklift.drawForklift()
package.drawPackage()
pygame.display.flip()
if __name__ == "__main__":
run()