Add AI agent movement #5

Merged
s459307 merged 1 commits from AddAgentMovement into master 2022-03-09 19:02:22 +01:00

13
main.py
View File

@ -7,6 +7,16 @@ FPS = 30
AGENT_IMG = pygame.image.load("dot-22-433567.png") AGENT_IMG = pygame.image.load("dot-22-433567.png")
AGENT = pygame.transform.scale(AGENT_IMG, (50, 50)) AGENT = pygame.transform.scale(AGENT_IMG, (50, 50))
def agent_movement(keys_pressed, agent):
if keys_pressed[pygame.K_LEFT] and agent.x > 0:
agent.x -= 50
if keys_pressed[pygame.K_RIGHT] and agent.x < 750:
agent.x += 50
if keys_pressed[pygame.K_UP] and agent.y > 0:
agent.y -= 50
if keys_pressed[pygame.K_DOWN] and agent.y < 750:
agent.y += 50
def draw_window(agent): def draw_window(agent):
WIN.fill((255,255,255)) WIN.fill((255,255,255))
@ -19,10 +29,13 @@ def main():
agent = pygame.Rect(0, 0, 50, 50) agent = pygame.Rect(0, 0, 50, 50)
while run: while run:
clock.tick(FPS)
for event in pygame.event.get(): for event in pygame.event.get():
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
run = False run = False
draw_window(agent) draw_window(agent)
keys_pressed = pygame.key.get_pressed()
agent_movement(keys_pressed, agent)
pygame.quit() pygame.quit()