add agent rotate
This commit is contained in:
parent
0b2b68ca3c
commit
fc4895fc4e
@ -5,5 +5,6 @@ class Agent:
|
||||
def __init__(self, x: int = 0, y: int = 0):
|
||||
self.name = "Kapitan Bomba"
|
||||
self.img = SAPPER_IDLE
|
||||
self.dir = 1
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
@ -12,7 +12,10 @@ class GameUi:
|
||||
self.clock = pg.time.Clock()
|
||||
self.screen = pg.display.set_mode((WIDTH, HEIGHT))
|
||||
|
||||
def move(self, coord: str, shift: int):
|
||||
def move(self):
|
||||
coord = 'x' if self.agent.dir in (1, 3) else 'y'
|
||||
shift = -1 if self.agent.dir in (2, 3) else 1
|
||||
# print(coord, shift)
|
||||
for x in range(8):
|
||||
setattr(
|
||||
self.agent,
|
||||
@ -31,3 +34,8 @@ class GameUi:
|
||||
self.screen.blit(IMAGES[self.env.field[y][x].number].img, (x * 80, y * 80))
|
||||
self.screen.blit(self.agent.img, (self.agent.x * 80, self.agent.y * 80))
|
||||
pg.display.update()
|
||||
|
||||
def rotate(self, dir):
|
||||
self.agent.dir = (self.agent.dir + dir) % 4
|
||||
print(self.agent.dir)
|
||||
|
||||
|
16
src/main.py
16
src/main.py
@ -23,17 +23,17 @@ def main():
|
||||
|
||||
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) 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:
|
||||
game_ui.move('x', -1)
|
||||
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:
|
||||
game_ui.move('y', -1)
|
||||
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):
|
||||
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))):
|
||||
game_ui.move()
|
||||
elif event.key == pg.K_SPACE:
|
||||
if env.field[agent.y][agent.x].mine:
|
||||
env.field[agent.y][agent.x] = factory.create_tile(
|
||||
|
Loading…
Reference in New Issue
Block a user