code refactor

This commit is contained in:
matixezor 2021-03-15 21:08:05 +01:00
parent e8a6a287a7
commit eba1b5cb41
2 changed files with 13 additions and 12 deletions

View File

@ -2,6 +2,7 @@ from pygame import image
from config import main_path
WIDTH = 800
HEIGHT = 800

View File

@ -1,4 +1,4 @@
import pygame
import pygame as pg
from const import ICON
from agent import Agent
@ -8,9 +8,9 @@ from environment import Environment
def main():
pygame.init()
pygame.display.set_caption('Super Saper')
pygame.display.set_icon(pygame.image.load(ICON))
pg.init()
pg.display.set_caption('Super Saper')
pg.display.set_icon(pg.image.load(ICON))
env = Environment(DEFAULT_FIELD)
agent = Agent()
@ -19,19 +19,19 @@ def main():
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
for event in pg.event.get():
if event.type == pg.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_d and agent.x_px < 700:
elif event.type == pg.KEYDOWN:
if event.key == pg.K_d and agent.x*80 < 700:
game_ui.move('x', 1)
elif event.key == pygame.K_a and agent.x_px > 5:
elif event.key == pg.K_a and agent.x*80 > 5:
game_ui.move('x', -1)
elif event.key == pygame.K_s and agent.y_px < 700:
elif event.key == pg.K_s and agent.y*80 < 700:
game_ui.move('y', 1)
elif event.key == pygame.K_w and agent.y_px > 0:
elif event.key == pg.K_w and agent.y*80 > 0:
game_ui.move('y', -1)
elif event.key == pygame.K_SPACE:
elif event.key == pg.K_SPACE:
if env.field[agent.y][agent.x] in [2, 3]:
env.field[agent.y][agent.x] -= 2
game_ui.update()