From 8a79b45b91357dbcc622d30487227ff8b099c846 Mon Sep 17 00:00:00 2001 From: ddamiankowalski Date: Tue, 8 Mar 2022 11:42:06 +0100 Subject: [PATCH] dodanie mozliwosci poruszania sie agenta --- board | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/board b/board index a3c52fe..7dbda9d 100644 --- a/board +++ b/board @@ -41,9 +41,17 @@ def draw(square_num, objectArr): radius = 10 pygame.draw.circle(screen, agent_color, (a + circleX, b + circleY), radius) - -def close(): #by móc zamnkąć okno iksem +def kb_listen(objectArray): for event in pygame.event.get(): + if event.type == pygame.KEYDOWN: + if event.key == pygame.K_LEFT: + objectArray[0].xPos = objectArray[0].xPos - 1 + if event.key == pygame.K_RIGHT: + objectArray[0].xPos = objectArray[0].xPos + 1 + if event.key == pygame.K_UP: + objectArray[0].yPos = objectArray[0].yPos - 1 + if event.key == pygame.K_DOWN: + objectArray[0].yPos = objectArray[0].yPos + 1 if event.type == pygame.QUIT: sys.exit() @@ -59,9 +67,9 @@ if __name__ == '__main__': height = 530 screen = pygame.display.set_mode((width, height)) #ustalanie rozmiarów okna - c = (255, 255, 255) #tymczasowy kolor tła - do usunięcia, jak już będzie zdjęcie - screen.fill(c) 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) - close() + kb_listen(objectArray) pygame.display.update() #by krata pojawiła się w okienku - update powierzchni \ No newline at end of file