add usage of ROCK_INDEXES, add kaboom func

This commit is contained in:
matixezor 2021-05-18 15:15:21 +02:00
parent 1849cdad46
commit 84b7ae9b9c
2 changed files with 13 additions and 5 deletions

View File

@ -2,7 +2,7 @@ import pygame as pg
from agent import Agent
from environment import Environment
from const import WIDTH, HEIGHT, IMAGES, SAPPER_IDLE
from const import WIDTH, HEIGHT, IMAGES, SAPPER_IDLE, ROCK_INDEXES, SAPPER_KABOOM
class GameUi:
@ -17,10 +17,10 @@ class GameUi:
shift = -1 if self.agent.direction in (0, 3) else 1
if coord == 'x':
if self.env.field[self.agent.y][self.agent.x+shift].number in (2, 3):
if self.env.field[self.agent.y][self.agent.x+shift].number in ROCK_INDEXES:
return
elif coord == 'y':
if self.env.field[self.agent.y+shift][self.agent.x].number in (2, 3):
if self.env.field[self.agent.y+shift][self.agent.x].number in ROCK_INDEXES:
return
for x in range(8):
@ -46,3 +46,10 @@ class GameUi:
self.agent.direction = (self.agent.direction + direction) % 4
self.agent.img = SAPPER_IDLE[self.agent.direction]
self.update()
def kaboom(self):
self.agent.img = SAPPER_KABOOM[self.agent.direction]
self.update()
pg.time.delay(500)
self.agent.img = SAPPER_IDLE[self.agent.direction]
self.update()

View File

@ -3,6 +3,7 @@ from typing import List, Tuple
import pygame as pg
from src.tile import Tile
from const import ROCK_INDEXES
from search_algoritms.node import Node
@ -30,9 +31,9 @@ def successor(field: List[List[Tile]], x: int, y: int, direction: int):
neighbours.append((x, y, (direction - 1) % 4, pg.K_a))
neighbours.append((x, y, (direction + 1) % 4, pg.K_d))
if coord == 'x' and 0 <= x + shift <= 9 and field[y][x + shift].number not in (2, 3):
if coord == 'x' and 0 <= x + shift <= 9 and field[y][x + shift].number not in ROCK_INDEXES:
neighbours.append((x + shift, y, direction, pg.K_w))
elif coord == 'y' and 0 <= y + shift <= 9 and field[y + shift][x].number not in (2, 3):
elif coord == 'y' and 0 <= y + shift <= 9 and field[y + shift][x].number not in ROCK_INDEXES:
neighbours.append((x, y + shift, direction, pg.K_w))
return neighbours