Scal SuperSaperTestowy #1
@ -5,5 +5,6 @@ class Agent:
|
|||||||
def __init__(self, x: int = 0, y: int = 0):
|
def __init__(self, x: int = 0, y: int = 0):
|
||||||
self.name = "Kapitan Bomba"
|
self.name = "Kapitan Bomba"
|
||||||
self.img = SAPPER_IDLE
|
self.img = SAPPER_IDLE
|
||||||
|
self.dir = 1
|
||||||
self.x = x
|
self.x = x
|
||||||
self.y = y
|
self.y = y
|
||||||
|
@ -12,7 +12,10 @@ class GameUi:
|
|||||||
self.clock = pg.time.Clock()
|
self.clock = pg.time.Clock()
|
||||||
self.screen = pg.display.set_mode((WIDTH, HEIGHT))
|
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):
|
for x in range(8):
|
||||||
setattr(
|
setattr(
|
||||||
self.agent,
|
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(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))
|
self.screen.blit(self.agent.img, (self.agent.x * 80, self.agent.y * 80))
|
||||||
pg.display.update()
|
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:
|
while running:
|
||||||
for event in pg.event.get():
|
for event in pg.event.get():
|
||||||
|
# print(agent.x*80)
|
||||||
if event.type == pg.QUIT:
|
if event.type == pg.QUIT:
|
||||||
running = False
|
running = False
|
||||||
elif event.type == pg.KEYDOWN:
|
elif event.type == pg.KEYDOWN:
|
||||||
if (event.key == pg.K_d or event.key == pg.K_RIGHT) and agent.x*80 < 700:
|
if (event.key == pg.K_d or event.key == pg.K_RIGHT):
|
||||||
game_ui.move('x', 1)
|
game_ui.rotate(1)
|
||||||
elif (event.key == pg.K_a or event.key == pg.K_LEFT) and agent.x*80 > 5:
|
elif (event.key == pg.K_a or event.key == pg.K_LEFT):
|
||||||
game_ui.move('x', -1)
|
game_ui.rotate(-1)
|
||||||
elif (event.key == pg.K_s or event.key == pg.K_DOWN) and agent.y*80 < 700:
|
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
|
||||||
game_ui.move('y', 1)
|
(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.y*80 > 0:
|
game_ui.move()
|
||||||
game_ui.move('y', -1)
|
|
||||||
elif event.key == pg.K_SPACE:
|
elif event.key == pg.K_SPACE:
|
||||||
if env.field[agent.y][agent.x].mine:
|
if env.field[agent.y][agent.x].mine:
|
||||||
env.field[agent.y][agent.x] = factory.create_tile(
|
env.field[agent.y][agent.x] = factory.create_tile(
|
||||||
|
Loading…
Reference in New Issue
Block a user