fix moving off screen when using 'wasd'

This commit is contained in:
matixezor 2021-03-30 11:45:20 +02:00
parent 2513f49fdc
commit 85993ddec5

View File

@ -26,17 +26,19 @@ def main():
if event.type == pg.QUIT:
running = False
elif event.type == pg.KEYDOWN:
if event.key == pg.K_d or event.key == pg.K_RIGHT and agent.x*80 < 700:
if (event.key == pg.K_d or event.key == pg.K_RIGHT) and agent.x*80 < 700:
game_ui.move('x', 1)
elif event.key == pg.K_a or event.key == pg.K_LEFT and agent.x*80 > 5:
elif (event.key == pg.K_a or event.key == pg.K_LEFT) and agent.x*80 > 5:
game_ui.move('x', -1)
elif event.key == pg.K_s or event.key == pg.K_DOWN and agent.y*80 < 700:
elif (event.key == pg.K_s or event.key == pg.K_DOWN) and agent.y*80 < 700:
game_ui.move('y', 1)
elif event.key == pg.K_w or event.key == pg.K_UP and agent.y*80 > 0:
elif (event.key == pg.K_w or event.key == pg.K_UP) and agent.y*80 > 0:
game_ui.move('y', -1)
elif event.key == pg.K_SPACE:
if env.field[agent.y][agent.x].number > 3:
env.field[agent.y][agent.x] = factory.createField(IMAGES_MAPPING[env.field[agent.y][agent.x].number])
env.field[agent.y][agent.x] = factory.create_field(
IMAGES_MAPPING[env.field[agent.y][agent.x].number]
)
game_ui.update()