From 1ed782d5de754e84554ec4429c72279ce78c1357 Mon Sep 17 00:00:00 2001 From: ddamiankowalski Date: Tue, 8 Mar 2022 14:30:25 +0100 Subject: [PATCH] poruszanie sie fix dodanie poruszania sie tylko po okreslonych polach --- board | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/board b/board index 7dbda9d..0c91d78 100644 --- a/board +++ b/board @@ -41,16 +41,16 @@ def draw(square_num, objectArr): radius = 10 pygame.draw.circle(screen, agent_color, (a + circleX, b + circleY), radius) -def kb_listen(objectArray): +def kb_listen(objectArray, gridLength): for event in pygame.event.get(): if event.type == pygame.KEYDOWN: - if event.key == pygame.K_LEFT: + if event.key == pygame.K_LEFT and objectArray[0].xPos > 0: objectArray[0].xPos = objectArray[0].xPos - 1 - if event.key == pygame.K_RIGHT: + if event.key == pygame.K_RIGHT and objectArray[0].xPos < gridLength - 1: objectArray[0].xPos = objectArray[0].xPos + 1 - if event.key == pygame.K_UP: + if event.key == pygame.K_UP and objectArray[0].yPos > 1: objectArray[0].yPos = objectArray[0].yPos - 1 - if event.key == pygame.K_DOWN: + if event.key == pygame.K_DOWN and objectArray[0].yPos < gridLength: objectArray[0].yPos = objectArray[0].yPos + 1 if event.type == pygame.QUIT: sys.exit() @@ -70,6 +70,6 @@ if __name__ == '__main__': while 1: c = (255, 255, 255) #tymczasowy kolor tła - do usunięcia, jak już będzie zdjęcie screen.fill(c) - draw(10, objectArray) - kb_listen(objectArray) + draw(15, objectArray) + kb_listen(objectArray, 15) pygame.display.update() #by krata pojawiła się w okienku - update powierzchni \ No newline at end of file