code refactor
This commit is contained in:
parent
e8a6a287a7
commit
eba1b5cb41
@ -2,6 +2,7 @@ from pygame import image
|
|||||||
|
|
||||||
from config import main_path
|
from config import main_path
|
||||||
|
|
||||||
|
|
||||||
WIDTH = 800
|
WIDTH = 800
|
||||||
HEIGHT = 800
|
HEIGHT = 800
|
||||||
|
|
||||||
|
24
src/main.py
24
src/main.py
@ -1,4 +1,4 @@
|
|||||||
import pygame
|
import pygame as pg
|
||||||
|
|
||||||
from const import ICON
|
from const import ICON
|
||||||
from agent import Agent
|
from agent import Agent
|
||||||
@ -8,9 +8,9 @@ from environment import Environment
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
pygame.init()
|
pg.init()
|
||||||
pygame.display.set_caption('Super Saper')
|
pg.display.set_caption('Super Saper')
|
||||||
pygame.display.set_icon(pygame.image.load(ICON))
|
pg.display.set_icon(pg.image.load(ICON))
|
||||||
|
|
||||||
env = Environment(DEFAULT_FIELD)
|
env = Environment(DEFAULT_FIELD)
|
||||||
agent = Agent()
|
agent = Agent()
|
||||||
@ -19,19 +19,19 @@ def main():
|
|||||||
|
|
||||||
running = True
|
running = True
|
||||||
while running:
|
while running:
|
||||||
for event in pygame.event.get():
|
for event in pg.event.get():
|
||||||
if event.type == pygame.QUIT:
|
if event.type == pg.QUIT:
|
||||||
running = False
|
running = False
|
||||||
elif event.type == pygame.KEYDOWN:
|
elif event.type == pg.KEYDOWN:
|
||||||
if event.key == pygame.K_d and agent.x_px < 700:
|
if event.key == pg.K_d and agent.x*80 < 700:
|
||||||
game_ui.move('x', 1)
|
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)
|
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)
|
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)
|
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]:
|
if env.field[agent.y][agent.x] in [2, 3]:
|
||||||
env.field[agent.y][agent.x] -= 2
|
env.field[agent.y][agent.x] -= 2
|
||||||
game_ui.update()
|
game_ui.update()
|
||||||
|
Loading…
Reference in New Issue
Block a user