zAktualizacja wyglądu agenta
This commit is contained in:
parent
abb75def38
commit
ff27920f3d
17
agent.py
17
agent.py
@ -6,22 +6,21 @@ class Agent:
|
|||||||
self.istate = istate
|
self.istate = istate
|
||||||
self.x, self.y, self.direction = istate
|
self.x, self.y, self.direction = istate
|
||||||
self.grid_size = grid_size
|
self.grid_size = grid_size
|
||||||
self.image_original = pygame.image.load(image_path)
|
self.image= pygame.image.load(image_path)
|
||||||
self.image_original = pygame.transform.scale(self.image_original, (grid_size, grid_size))
|
self.image = pygame.transform.scale(self.image, (grid_size, grid_size))
|
||||||
self.image = self.image_original
|
|
||||||
|
|
||||||
|
|
||||||
def draw(self, screen):
|
def draw(self, screen, grid_size):
|
||||||
# Obróć obrazek zgodnie z kierunkiem
|
# Obróć obrazek zgodnie z kierunkiem
|
||||||
if self.direction == 'E':
|
if self.direction == 'E':
|
||||||
self.image = pygame.transform.rotate(self.image_original, -90)
|
self.image= pygame.image.load('images/agent4.png')
|
||||||
elif self.direction == 'S':
|
elif self.direction == 'S':
|
||||||
self.image = pygame.transform.rotate(self.image_original, 180)
|
self.image= pygame.image.load('images/agent1.png')
|
||||||
elif self.direction == 'W':
|
elif self.direction == 'W':
|
||||||
self.image = pygame.transform.rotate(self.image_original, 90)
|
self.image= pygame.image.load('images/agent3.png')
|
||||||
else: # direction == 'N'
|
else: # direction == 'N'
|
||||||
self.image = self.image_original
|
self.image= pygame.image.load('images/agent2.png')
|
||||||
|
self.image = pygame.transform.scale(self.image, (grid_size, grid_size))
|
||||||
screen.blit(self.image, (self.x * self.grid_size, self.y * self.grid_size))
|
screen.blit(self.image, (self.x * self.grid_size, self.y * self.grid_size))
|
||||||
|
|
||||||
def handle_event(self, event, max_x, max_y, animals, obstacles):
|
def handle_event(self, event, max_x, max_y, animals, obstacles):
|
||||||
|
BIN
images/agent1.png
Normal file
BIN
images/agent1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
BIN
images/agent2.png
Normal file
BIN
images/agent2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
BIN
images/agent3.png
Normal file
BIN
images/agent3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.7 KiB |
BIN
images/agent4.png
Normal file
BIN
images/agent4.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.0 KiB |
4
main.py
4
main.py
@ -154,7 +154,7 @@ def generate_obstacles():
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
initial_state = (1,1,'W')
|
initial_state = (1,1,'W')
|
||||||
agent = Agent(initial_state, 'images/agent.png', GRID_SIZE)
|
agent = Agent(initial_state, 'images/agent1.png', GRID_SIZE)
|
||||||
|
|
||||||
obstacles = generate_obstacles()
|
obstacles = generate_obstacles()
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ def main():
|
|||||||
spawned = True
|
spawned = True
|
||||||
draw_Animals()
|
draw_Animals()
|
||||||
opengates()
|
opengates()
|
||||||
agent.draw(screen)
|
agent.draw(screen, GRID_SIZE)
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
clock.tick(10)
|
clock.tick(10)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user