From 9123ccf3f926a52f6ab22fc4fe4a6e716546e1dc Mon Sep 17 00:00:00 2001 From: matixezor Date: Fri, 9 Apr 2021 22:32:08 +0200 Subject: [PATCH] fix going offscren with W key, code refactor --- src/main.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main.py b/src/main.py index e7175e5..c4cd2c8 100644 --- a/src/main.py +++ b/src/main.py @@ -1,9 +1,9 @@ import pygame as pg from agent import Agent -from game_ui import GameUi -from environment import Environment from const import ICON, IMAGES +from environment import Environment +from game_ui import GameUi from tilesFactory import TilesFactory @@ -16,29 +16,31 @@ def main(): agent = Agent() game_ui = GameUi(agent, env) game_ui.update() - + factory = TilesFactory() running = True - #ruchy agenta: - #1 - right - #2 - up - #3 - left - #0 - down + # ruchy agenta: + # 1 - right + # 2 - up + # 3 - left + # 0 - down while running: for event in pg.event.get(): - # print(agent.x*80) if event.type == pg.QUIT: running = False elif event.type == pg.KEYDOWN: - if (event.key == pg.K_d or event.key == pg.K_RIGHT): + if event.key == pg.K_d or event.key == pg.K_RIGHT: game_ui.rotate(-1) - elif (event.key == pg.K_a or event.key == pg.K_LEFT): + elif event.key == pg.K_a or event.key == pg.K_LEFT: game_ui.rotate(1) - elif (event.key == pg.K_w or event.key == pg.K_UP and ((agent.dir == 1 and agent.x*80 < 700) or (agent.dir == 3 and agent.x*80 > 5) or - (agent.dir == 2 and agent.y*80 > 0) or (agent.dir == 0 and agent.y*80 < 700))): + elif (event.key == pg.K_w or event.key == pg.K_UP) \ + and ((agent.direction == 1 and agent.x * 80 < 700) + or (agent.direction == 3 and agent.x * 80 > 5) + or (agent.direction == 2 and agent.y * 80 > 0) + or (agent.direction == 0 and agent.y * 80 < 700)): game_ui.move() elif event.key == pg.K_SPACE: if env.field[agent.y][agent.x].mine: