Exemplo n.º 1
0
        private static bool IsWalkable(Level level, Vector2Int destination, Vector2Int origin)
        {
            bool isTileWalkable = IsWalkable(level, destination);

            if (isTileWalkable == false)
            {
                return(false);
            }

            Vector3Int wallBetweenTiles = GetWallBetweenTiles(origin, destination);
            GameObject wallGo           = level.GetWallGameObject(wallBetweenTiles);

            if (wallGo == null)
            {
                return(level.data.GetWall(wallBetweenTiles) == (int)WallIndex.Empty);
            }

            WalkableState wallWalkableState = wallGo.GetComponent <WalkableState>();

            if (wallWalkableState == null)
            {
                Debug.LogFormat("Wall {0},{1},{2} is {3}", wallBetweenTiles.x, wallBetweenTiles.y, wallBetweenTiles.z, level.data.GetWall(wallBetweenTiles) == (int)WallIndex.Empty);
                return(level.data.GetWall(wallBetweenTiles) == (int)WallIndex.Empty);
            }
            else
            {
                return(wallWalkableState.isWalkable);
            }
        }
Exemplo n.º 2
0
        private static bool IsWalkable(Level level, Vector2Int destination)
        {
            // Is destination inside boundaries?
            bool insideBoundaries = level.data.IsFloorInBounds(destination);

            if (insideBoundaries == false)
            {
                return(false);
            }

            // Is the floor walkable?
            bool          isFloorWalkable    = true;
            GameObject    floorGO            = level.GetFloorGameObject(destination);
            WalkableState floorWalkableState = floorGO.GetComponent <WalkableState>();

            if (floorWalkableState == null)
            {
                isFloorWalkable = level.data.GetFloor(destination.x, destination.y) != (int)FloorIndex.Empty;
            }
            else
            {
                isFloorWalkable = floorWalkableState.isWalkable;
            }

            if (isFloorWalkable == false)
            {
                return(false);
            }

            // Is the item walkable?
            bool          isItemWalkable    = true;
            GameObject    itemGO            = level.GetItemGameObject(destination);
            WalkableState itemWalkableState = itemGO.GetComponent <WalkableState>();

            if (itemWalkableState == null)
            {
                isItemWalkable = level.data.GetItem(destination).x == (int)ItemIndex.Empty;
            }
            else
            {
                isItemWalkable = itemWalkableState.isWalkable;
            }

            return(isItemWalkable);
        }