fix going offscren with W key, code refactor

This commit is contained in:
matixezor 2021-04-09 22:32:08 +02:00
parent 30b8fc3fae
commit 9123ccf3f9

View File

@ -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: