Merge pull request 'Add AI agent movement' (#5) from AddAgentMovement into master
Reviewed-on: #5 Reviewed-by: Emil Gutkiewicz <emigut@st.amu.edu.pl>
This commit is contained in:
commit
9f007383da
13
main.py
13
main.py
@ -7,6 +7,16 @@ FPS = 30
|
||||
AGENT_IMG = pygame.image.load("dot-22-433567.png")
|
||||
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):
|
||||
WIN.fill((255,255,255))
|
||||
@ -19,10 +29,13 @@ def main():
|
||||
agent = pygame.Rect(0, 0, 50, 50)
|
||||
|
||||
while run:
|
||||
clock.tick(FPS)
|
||||
for event in pygame.event.get():
|
||||
if event.type == pygame.QUIT:
|
||||
run = False
|
||||
draw_window(agent)
|
||||
keys_pressed = pygame.key.get_pressed()
|
||||
agent_movement(keys_pressed, agent)
|
||||
|
||||
pygame.quit()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user