public IEnumerator Explosion(float delay = 0.5f) { //create explosion at origin CreateExplosion(new Point(( int )transform.position.x, ( int )transform.position.z)); var currentGrid = new Point(Mathf.Abs(( int )transform.position.x), Mathf.Abs(( int )transform.position.z)); //check for grid extrems or if the next block is indestructible var canMoveUp = (currentGrid.y - 1) >= 0 && mapData.GetValue(currentGrid.x, currentGrid.y - 1) != Constants.INDESTRUCTABLE_WALL_ID; var canMoveDown = (currentGrid.y + 1) < mapData.height && mapData.GetValue(currentGrid.x, currentGrid.y + 1) != Constants.INDESTRUCTABLE_WALL_ID; var canMoveRight = (currentGrid.x + 1) < mapData.width && mapData.GetValue(currentGrid.x + 1, currentGrid.y) != Constants.INDESTRUCTABLE_WALL_ID; var canMoveLeft = (currentGrid.x - 1) >= 0 && mapData.GetValue(currentGrid.x - 1, currentGrid.y) != Constants.INDESTRUCTABLE_WALL_ID; //add grids to be used for explosin and update for next block for (var i = 1; i <= range; i++) { //up if (canMoveUp) { var point = new Point(( int )transform.position.x, ( int )transform.position.z + i); var isCurrentBlockDestructibleWall = mapData.GetValue(point.x, point.AbsY) == Constants.DESTRUCTABLE_WALL_ID; DestroyCurrentBlockAndUpdateMapData(isCurrentBlockDestructibleWall, point); //check if next point is valid canMoveUp = point.y + 1 <= 0 && !isCurrentBlockDestructibleWall && mapData.GetValue(point.x, point.AbsY - 1) != Constants.INDESTRUCTABLE_WALL_ID; } //down if (canMoveDown) { var point = new Point(( int )transform.position.x, ( int )transform.position.z - i); var isCurrentBlockDestructibleWall = mapData.GetValue(point.x, point.AbsY) == Constants.DESTRUCTABLE_WALL_ID; DestroyCurrentBlockAndUpdateMapData(isCurrentBlockDestructibleWall, point); //check if next point is valid canMoveDown = point.AbsY + 1 < mapData.height && !isCurrentBlockDestructibleWall && mapData.GetValue(point.x, point.AbsY + 1) != Constants.INDESTRUCTABLE_WALL_ID; } //right if (canMoveRight) { var point = new Point(( int )transform.position.x + i, ( int )transform.position.z); var isCurrentBlockDestructibleWall = mapData.GetValue(point.x, point.AbsY) == Constants.DESTRUCTABLE_WALL_ID; DestroyCurrentBlockAndUpdateMapData(isCurrentBlockDestructibleWall, point); //check if next point is valid canMoveRight = point.x + 1 < mapData.width && !isCurrentBlockDestructibleWall && mapData.GetValue(point.x + 1, point.AbsY) != Constants.INDESTRUCTABLE_WALL_ID; } //left if (canMoveLeft) { var point = new Point(( int )transform.position.x - i, ( int )transform.position.z); var isCurrentBlockDestructibleWall = mapData.GetValue(point.x, point.AbsY) == Constants.DESTRUCTABLE_WALL_ID; DestroyCurrentBlockAndUpdateMapData(isCurrentBlockDestructibleWall, point); //check if next point is valid canMoveLeft = point.x - 1 >= 0 && !isCurrentBlockDestructibleWall && mapData.GetValue(point.x - 1, point.AbsY) != Constants.INDESTRUCTABLE_WALL_ID; } yield return(new WaitForSeconds(delay)); } //post explosion cleanup //explosion over, clear the grid DestroyExplosionEffect(); parent.OnBombDetonateEnd(); Destroy(gameObject); }
/// <summary> /// check if the controller can move to next available point /// </summary> protected bool IsValidMove(Point point) { return((point.x >= 0 && point.x < mapData.width && point.y <= 0 && point.AbsY < mapData.height) && (mapData.GetValue(point.AbsX, point.AbsY) == 0 || (mapData.GetValue(point.AbsX, point.AbsY)) > Constants.INDESTRUCTABLE_WALL_ID)); }