dodanie mozliwosci poruszania sie agenta

This commit is contained in:
ddamiankowalski 2022-03-08 11:42:06 +01:00
parent 69e54b2c31
commit 8a79b45b91

18
board
View File

@ -41,9 +41,17 @@ def draw(square_num, objectArr):
radius = 10 radius = 10
pygame.draw.circle(screen, agent_color, (a + circleX, b + circleY), radius) pygame.draw.circle(screen, agent_color, (a + circleX, b + circleY), radius)
def kb_listen(objectArray):
def close(): #by móc zamnkąć okno iksem
for event in pygame.event.get(): 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: if event.type == pygame.QUIT:
sys.exit() sys.exit()
@ -59,9 +67,9 @@ if __name__ == '__main__':
height = 530 height = 530
screen = pygame.display.set_mode((width, height)) #ustalanie rozmiarów okna 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: 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) draw(10, objectArray)
close() kb_listen(objectArray)
pygame.display.update() #by krata pojawiła się w okienku - update powierzchni pygame.display.update() #by krata pojawiła się w okienku - update powierzchni