reprezentacja wiedzy 1
|
@ -0,0 +1,21 @@
|
||||||
|
import pygame
|
||||||
|
from Shelf import Shelf
|
||||||
|
from Grid import Grid
|
||||||
|
|
||||||
|
HORIZONTAL = 1250
|
||||||
|
VERTICAL = 750
|
||||||
|
|
||||||
|
TILE_SIZE = 50
|
||||||
|
|
||||||
|
background = (49, 51, 53)
|
||||||
|
|
||||||
|
class Environment:
|
||||||
|
def __init__(self, window):
|
||||||
|
self.window = window
|
||||||
|
self.grid = Grid(self.window)
|
||||||
|
self.Shelf = Shelf(self.window)
|
||||||
|
|
||||||
|
def drawEnviroment(self):
|
||||||
|
self.window.fill(background)
|
||||||
|
self.Shelf.drawShelves()
|
||||||
|
self.grid.drawGrid()
|
|
@ -0,0 +1,37 @@
|
||||||
|
import pygame
|
||||||
|
from Environment import Environment
|
||||||
|
from Package import Package
|
||||||
|
|
||||||
|
TILE_SIZE = 50
|
||||||
|
|
||||||
|
class Forklift:
|
||||||
|
def __init__(self, window):
|
||||||
|
self.window = window
|
||||||
|
self.image = pygame.image.load('resources/images.png').convert_alpha()
|
||||||
|
self.x = 50
|
||||||
|
self.y = 350
|
||||||
|
self.environment = Environment(self.window)
|
||||||
|
self.hasPackage = False
|
||||||
|
self.package = Package(self.window)
|
||||||
|
|
||||||
|
def drawForklift(self):
|
||||||
|
self.environment.drawEnviroment()
|
||||||
|
self.package.drawPackage()
|
||||||
|
self.window.blit(self.image, (self.x, self.y))
|
||||||
|
pygame.display.flip()
|
||||||
|
|
||||||
|
def moveForkliftRight(self):
|
||||||
|
self.x += TILE_SIZE
|
||||||
|
self.drawForklift()
|
||||||
|
|
||||||
|
def moveForkliftLeft(self):
|
||||||
|
self.x -= TILE_SIZE
|
||||||
|
self.drawForklift()
|
||||||
|
|
||||||
|
def moveForkliftUp(self):
|
||||||
|
self.y -= TILE_SIZE
|
||||||
|
self.drawForklift()
|
||||||
|
|
||||||
|
def moveForkliftDown(self):
|
||||||
|
self.y += TILE_SIZE
|
||||||
|
self.drawForklift()
|
|
@ -0,0 +1,24 @@
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
HORIZONTAL = 1250
|
||||||
|
VERTICAL = 750
|
||||||
|
|
||||||
|
TILE_SIZE = 50
|
||||||
|
|
||||||
|
line_color = (85, 85, 85)
|
||||||
|
|
||||||
|
class Grid:
|
||||||
|
def __init__(self, window):
|
||||||
|
self.window = window
|
||||||
|
|
||||||
|
def drawGrid(self):
|
||||||
|
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(self.window, line_color, (x, 0), (x, VERTICAL))
|
||||||
|
for i in range(num_of_rows):
|
||||||
|
y += TILE_SIZE
|
||||||
|
pygame.draw.line(self.window, line_color, (0, y), (HORIZONTAL, y))
|
|
@ -0,0 +1,25 @@
|
||||||
|
import numpy as np
|
||||||
|
import pygame
|
||||||
|
import glob2
|
||||||
|
import random
|
||||||
|
|
||||||
|
TILE_SIZE = 50
|
||||||
|
|
||||||
|
class Package:
|
||||||
|
def __init__(self, window):
|
||||||
|
self.window = window
|
||||||
|
self.imageDefault = pygame.image.load('resources/indeks.png').convert_alpha()
|
||||||
|
self.x = 1150
|
||||||
|
self.y = 350
|
||||||
|
self.markImage = self.getMarkingImage()
|
||||||
|
|
||||||
|
def getMarkingImage(self):
|
||||||
|
file_path_type = ["resources/package/*.jpg"]
|
||||||
|
images = glob2.glob(random.choice(file_path_type))
|
||||||
|
markImage = random.choice(images)
|
||||||
|
print(markImage)
|
||||||
|
return markImage
|
||||||
|
|
||||||
|
def drawPackage(self):
|
||||||
|
self.window.blit(self.imageDefault, (self.x, self.y))
|
||||||
|
pygame.display.flip()
|
|
@ -0,0 +1,36 @@
|
||||||
|
import pygame
|
||||||
|
from pygame.locals import *
|
||||||
|
from Forklift import Forklift
|
||||||
|
|
||||||
|
HORIZONTAL = 1250
|
||||||
|
VERTICAL = 750
|
||||||
|
|
||||||
|
TILE_SIZE = 50
|
||||||
|
|
||||||
|
class Program:
|
||||||
|
def __init__(self):
|
||||||
|
pygame.init()
|
||||||
|
self.window = pygame.display.set_mode((HORIZONTAL, VERTICAL))
|
||||||
|
self.caption = pygame.display.set_caption('Autonomiczny wózek widłowy')
|
||||||
|
self.agent = Forklift(self.window)
|
||||||
|
self.agent.drawForklift()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
running = True
|
||||||
|
while running:
|
||||||
|
for event in pygame.event.get():
|
||||||
|
if event.type == KEYDOWN:
|
||||||
|
if event.key == K_RIGHT:
|
||||||
|
self.agent.moveForkliftRight()
|
||||||
|
if event.key == K_LEFT:
|
||||||
|
self.agent.moveForkliftLeft()
|
||||||
|
if event.key == K_UP:
|
||||||
|
self.agent.moveForkliftUp()
|
||||||
|
if event.key == K_DOWN:
|
||||||
|
self.agent.moveForkliftDown()
|
||||||
|
if event.key == K_ESCAPE:
|
||||||
|
running = False
|
||||||
|
elif event.type == pygame.QUIT:
|
||||||
|
running = False
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
import pygame
|
||||||
|
|
||||||
|
HORIZONTAL = 1250
|
||||||
|
VERTICAL = 750
|
||||||
|
|
||||||
|
TILE_SIZE = 50
|
||||||
|
shelf = (138, 126, 74)
|
||||||
|
|
||||||
|
class Shelf:
|
||||||
|
def __init__(self, window):
|
||||||
|
self.window = window
|
||||||
|
self.color = shelf
|
||||||
|
self.width = 5 * TILE_SIZE
|
||||||
|
self.height = TILE_SIZE
|
||||||
|
|
||||||
|
def drawShelves(self):
|
||||||
|
|
||||||
|
for j in range(0, 5 * TILE_SIZE, 2 * TILE_SIZE):
|
||||||
|
for i in range(TILE_SIZE + 1, HORIZONTAL - TILE_SIZE, 6 * TILE_SIZE):
|
||||||
|
pygame.draw.rect(self.window, shelf, pygame.Rect(i, j, self.width, self.height))
|
||||||
|
|
||||||
|
for k in range(VERTICAL - 5 * TILE_SIZE, VERTICAL, 2 * TILE_SIZE):
|
||||||
|
for l in range(TILE_SIZE + 1, HORIZONTAL - TILE_SIZE, 6 * TILE_SIZE):
|
||||||
|
pygame.draw.rect(self.window, shelf, pygame.Rect(l, k, self.width, self.height))
|
86
main.py
|
@ -1,87 +1,7 @@
|
||||||
import pygame
|
import pygame
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
|
from Program import Program
|
||||||
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__":
|
if __name__ == "__main__":
|
||||||
run()
|
program = Program()
|
||||||
|
program.run()
|
||||||
|
|
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 50 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 55 KiB |
After Width: | Height: | Size: 47 KiB |
After Width: | Height: | Size: 58 KiB |
After Width: | Height: | Size: 69 KiB |
After Width: | Height: | Size: 1.5 MiB |