Dodanie metod do poruszania się agentem

This commit is contained in:
andrzej 2020-04-06 15:12:50 +02:00
parent 70bb6c6b5e
commit dae93da39d
2 changed files with 23 additions and 3 deletions

View File

@ -1,6 +1,26 @@
class Agent: class Agent:
def __init__(self, start_x, start_y, radius=5): def __init__(self, start_x, start_y, assigned_warehouse, radius=5):
self.x = start_x self.x = start_x
self.y = start_y self.y = start_y
self.radius = radius self.radius = radius
self.assigned_warehouse = assigned_warehouse
def move_right(self):
self.x += 1
if self.x > self.assigned_warehouse.width - 1:
self.x = self.assigned_warehouse.width - 1
def move_left(self):
self.x -= 1
if self.x < 0:
self.x = 0
def move_down(self):
self.y += 1
if self.y > self.assigned_warehouse.height - 1:
self.y = self.assigned_warehouse.height - 1
def move_up(self):
self.y -= 1
if self.y < 0:
self.y = 0

View File

@ -28,7 +28,7 @@ class MainGameFrame:
self.display = pygame.display.set_mode(WINDOW_SIZE) self.display = pygame.display.set_mode(WINDOW_SIZE)
self.warehouse_map = warehouse.Warehouse(20, 20, 150, 20) self.warehouse_map = warehouse.Warehouse(20, 20, 150, 20)
starting_x, starting_y = self.set_starting_agent_position() starting_x, starting_y = self.set_starting_agent_position()
self.agent = agent.Agent(starting_x, starting_y, 20) self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map ,20)
def run(self): def run(self):
self.draw_floor() self.draw_floor()