dodanie skręcania i tekstury wózka

This commit is contained in:
Yakudami 2020-04-30 16:36:55 +02:00
parent 410aacdeca
commit b29f027943
4 changed files with 43 additions and 10 deletions

View File

@ -103,10 +103,36 @@ class Agent:
return
else:
next = self.path.pop()
star_dir = self.direction
print(next.x, next.y)
self.x = next.x
self.y = next.y
if self.x > next.x and not self.direction == 'left':
if self.direction == 'down':
self.turn_right()
else:
self.turn_left()
elif self.x < next.x and not self.direction == 'right':
if self.direction == 'down':
self.turn_left()
else:
self.turn_right()
elif self.y > next.y and not self.direction == 'up':
if self.direction == 'left':
self.turn_right()
else:
self.turn_left()
elif self.y < next.y and not self.direction == 'down':
if self.direction == 'right':
self.turn_right()
else:
self.turn_left()
if star_dir == self.direction:
self.x = next.x
self.y = next.y
else:
self.path.append(next)
self.closed = []
def check_if_can_move(self, next_coords: Coordinates):
tile_on_map = 0 <= next_coords.x < self.warehouse.width and 0 <= next_coords.y < self.warehouse.height
if not tile_on_map:

View File

@ -41,4 +41,11 @@ TURN_RIGHT_DIRECTIONS = {
"up": "right",
"right": "down",
"down": "left"
}
}
DIRECTION_ANGLES = {
"left": 0,
"up": -90,
"right": 180,
"down": 90
}

BIN
forklift.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

14
main.py
View File

@ -3,23 +3,24 @@ import warehouse
import agent
import random
import sys
from attributes import PackSize, PackStatus, COLORS
from attributes import PackSize, PackStatus, COLORS, DIRECTION_ANGLES
WINDOW_SIZE = (600, 600)
WINDOW_SIZE = (640, 640)
COLOR_OF_FIELD = {
'Floor': 'gray',
'Rack': 'white',
'Pack': 'yellow',
'path': 'orange'
}
TILE_WIDTH = 30
TILE_HEIGHT = 30
TILE_WIDTH = 32
TILE_HEIGHT = 32
CIRCLE_CENTER_X, CIRCLE_CENTER_Y = int(TILE_WIDTH/2), int(TILE_HEIGHT/2)
class MainGameFrame:
def __init__(self):
self.display = pygame.display.set_mode(WINDOW_SIZE)
agent_radius = int(TILE_WIDTH/2)
self.agent_tex = pygame.image.load('forklift.png')
self.warehouse_map = warehouse.Warehouse(20, 20, 150, 20)
starting_x, starting_y = self.set_starting_agent_position()
self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map, agent_radius)
@ -78,9 +79,8 @@ class MainGameFrame:
((pack_x * TILE_WIDTH) + 3, (pack_y * TILE_HEIGHT) + 3, TILE_WIDTH - 5, TILE_HEIGHT - 5))
def draw_agent(self):
agent_position_x, agent_position_y = self.agent.x, self.agent.y
agent_screen_position = ((agent_position_x*TILE_WIDTH) + CIRCLE_CENTER_X, (agent_position_y*TILE_HEIGHT) + CIRCLE_CENTER_Y)
pygame.draw.circle(self.display, COLORS['black'], agent_screen_position, self.agent.radius, int(self.agent.radius/2))
rotated = pygame.transform.rotate(self.agent_tex, DIRECTION_ANGLES.get(self.agent.direction))
self.display.blit(rotated, (self.agent.x*TILE_WIDTH, self.agent.y*TILE_WIDTH))
def set_starting_agent_position(self):
starting_x, starting_y = random.randrange(self.warehouse_map.width), random.randrange(self.warehouse_map.height)