From dae93da39dae8e4fc35d4aad48615558099c466d Mon Sep 17 00:00:00 2001 From: andrzej Date: Mon, 6 Apr 2020 15:12:50 +0200 Subject: [PATCH] =?UTF-8?q?Dodanie=20metod=20do=20poruszania=20si=C4=99=20?= =?UTF-8?q?agentem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- agent.py | 24 ++++++++++++++++++++++-- main.py | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/agent.py b/agent.py index 24e717e..265b7cb 100644 --- a/agent.py +++ b/agent.py @@ -1,6 +1,26 @@ 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.y = start_y - self.radius = radius \ No newline at end of file + 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 diff --git a/main.py b/main.py index 9097e6e..315c3f1 100644 --- a/main.py +++ b/main.py @@ -28,7 +28,7 @@ class MainGameFrame: self.display = pygame.display.set_mode(WINDOW_SIZE) 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, 20) + self.agent = agent.Agent(starting_x, starting_y, self.warehouse_map ,20) def run(self): self.draw_floor()