From 69e54b2c316ffe4b9d65cdda0eb9a2d9a988c6c8 Mon Sep 17 00:00:00 2001 From: ddamiankowalski Date: Tue, 8 Mar 2022 11:25:50 +0100 Subject: [PATCH 1/3] dodanie agenta --- board | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 board diff --git a/board b/board new file mode 100644 index 0000000..a3c52fe --- /dev/null +++ b/board @@ -0,0 +1,67 @@ +import sys +import pygame + +screen = [] +objectArray = [] + +class Agent: + def __init__(self, name, xPos, yPos): + self.name = name + self.xPos = xPos + self.yPos = yPos + +def draw(square_num, objectArr): + #następne dwie linijki do odkomentowania, jak będzie wgrane zdjęcie do tła + #background = pygame.image.load("ścieżka do pliku").convert() #tu ścieżka do zdjęcia w tle + #screen.blit(background, (0, 0)) + grid_color = (0, 0, 0) #kolor czarny + + grid_size = 500 #rozmiar kraty + square = grid_size/square_num #rozmiar pojedyńczego kwadracika + + a = 50 + b = 10 #odległości kraty od krawędzi okna + + for i in range(square_num): + pygame.draw.line(screen, grid_color, (a + i*square, b), (a + i*square, b + grid_size), 2) + + pygame.draw.line(screen, grid_color, (a, b + i*square), (a + grid_size, b + i*square), 2) + + pygame.draw.line(screen, grid_color, (a, b + grid_size), (a + grid_size, + b + grid_size), 2) + pygame.draw.line(screen, grid_color, (a + grid_size, b), + (a + grid_size, b + grid_size), 2) + + ## tutaj rysujemy agenta i inne obiekty juz na gotowej mapie + + ## RYSUJEMY AGENTA + agent_color = (255, 0, 0) + circleX = objectArr[0].xPos * square + square / 2 + circleY = objectArr[0].yPos * square - square / 2 + radius = 10 + pygame.draw.circle(screen, agent_color, (a + circleX, b + circleY), radius) + + +def close(): #by móc zamnkąć okno iksem + for event in pygame.event.get(): + if event.type == pygame.QUIT: + sys.exit() + + +if __name__ == '__main__': + pygame.init() #inicjalizacja modułów, na razie niepotrzebna + + #Tworzymy nowego playera, czy tam agenta + agent = Agent("smieciarka", 5, 7) + objectArray.append(agent) + + width = 600 + 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: + draw(10, objectArray) + close() + pygame.display.update() #by krata pojawiła się w okienku - update powierzchni \ No newline at end of file From 8a79b45b91357dbcc622d30487227ff8b099c846 Mon Sep 17 00:00:00 2001 From: ddamiankowalski Date: Tue, 8 Mar 2022 11:42:06 +0100 Subject: [PATCH 2/3] 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 From 1ed782d5de754e84554ec4429c72279ce78c1357 Mon Sep 17 00:00:00 2001 From: ddamiankowalski Date: Tue, 8 Mar 2022 14:30:25 +0100 Subject: [PATCH 3/3] 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