예제 #1
0
 public override void Revert(TileElement[,,] board)
 {
     tileElement.model = GameObject.Instantiate(Resources.Load("Models/" + tileElement.TileName())) as GameObject;
     tileElement.BindDataToModel();
     tileElement.WarpToPos();
     tileElement.AdjustRender();
     if (tileElement is Monocoord)
     {
         Monocoord monoTile = (Monocoord)tileElement;
         board[monoTile.GetPos().x, monoTile.GetPos().y, monoTile.GetPos().z] = tileElement;
         if (tileElement is Vine)
         {
             LevelManager.current.AdjustAvailableVinesUI(((Vine)tileElement).GetColor(), -1);
         }
     }
     else
     {
         Dicoord diTile = (Dicoord)tileElement;
         for (int x = diTile.GetPos1().x; x <= diTile.GetPos2().x; x++)
         {
             for (int y = diTile.GetPos1().y; y <= diTile.GetPos2().y; y++)
             {
                 for (int z = diTile.GetPos1().z; z <= diTile.GetPos2().z; z++)
                 {
                     board[x, y, z] = tileElement;
                 }
             }
         }
     }
 }
예제 #2
0
    public override void Revert(TileElement[,,] board)
    {
        if (tileElement is Monocoord)
        {
            Monocoord monocoord = (Monocoord)tileElement;

            if (board[monocoord.GetPos().x, monocoord.GetPos().y, monocoord.GetPos().z] is IMonoSpacious)
            {
                ((IMonoSpacious)board[monocoord.GetPos().x, monocoord.GetPos().y, monocoord.GetPos().z]).Expecting = true;
            }
            else
            {
                board[monocoord.GetPos().x, monocoord.GetPos().y, monocoord.GetPos().z] = null;
            }

            monocoord.SetCoords(new int[]
            {
                oldPos.x,
                oldPos.y,
                oldPos.z
            });

            if (board[monocoord.GetPos().x, monocoord.GetPos().y, monocoord.GetPos().z] != null && board[monocoord.GetPos().x, monocoord.GetPos().y, monocoord.GetPos().z] is IMonoSpacious)
            {
                ((IMonoSpacious)board[monocoord.GetPos().x, monocoord.GetPos().y, monocoord.GetPos().z]).Helper.Inhabitant = monocoord;
                ((IMonoSpacious)board[monocoord.GetPos().x, monocoord.GetPos().y, monocoord.GetPos().z]).TileEnters(monocoord);
            }
            else
            {
                board[monocoord.GetPos().x, monocoord.GetPos().y, monocoord.GetPos().z] = monocoord;
            }
        }
        else
        {
            Dicoord dicoord = ((Dicoord)tileElement);

            for (int x = dicoord.GetPos1().x; x <= dicoord.GetPos2().x; x++)
            {
                for (int y = dicoord.GetPos1().y; y <= dicoord.GetPos2().y; y++)
                {
                    for (int z = dicoord.GetPos1().z; z <= dicoord.GetPos2().z; z++)
                    {
                        if (board[x, y, z] is IMonoSpacious)
                        {
                            ((IMonoSpacious)board[x, y, z]).Expecting = true;
                        }
                        else
                        {
                            board[x, y, z] = null;
                        }
                    }
                }
            }

            dicoord.SetCoords(new int[]
            {
                oldPos.x,
                oldPos.y,
                oldPos.z
            },
                              new int[] {
                oldPos.x + (dicoord.GetPos2().x - dicoord.GetPos1().x),
                oldPos.y + (dicoord.GetPos2().y - dicoord.GetPos1().y),
                oldPos.z + (dicoord.GetPos2().z - dicoord.GetPos1().z)
            });

            for (int x = dicoord.GetPos1().x; x <= dicoord.GetPos2().x; x++)
            {
                for (int y = dicoord.GetPos1().y; y <= dicoord.GetPos2().y; y++)
                {
                    for (int z = dicoord.GetPos1().z; z <= dicoord.GetPos2().z; z++)
                    {
                        if (board[x, y, z] != null && board[x, y, z] is IMonoSpacious)
                        {
                            ((IMonoSpacious)board[x, y, z]).Helper.Inhabitant = dicoord;
                            ((IMonoSpacious)board[x, y, z]).TileEnters(dicoord);
                        }
                        else
                        {
                            board[x, y, z] = dicoord;
                        }
                    }
                }
            }
        }
        tileElement.WarpToPos();
    }
예제 #3
0
    // Returns the coords of the tile next to a selected block depending on which facet was clicked.
    public static Vector3Int GetAdjacentCoords(RaycastHit hit, bool additive)
    {
        int sideModifier = additive ? 1 : 0;

        if (hit.transform.parent.GetComponent <ModelTileBridge>().Data is Monocoord)
        {
            float xDist = hit.point.x - hit.transform.parent.position.x;
            float yDist = hit.point.y - hit.transform.parent.position.y;
            float zDist = hit.point.z - hit.transform.parent.position.z;

            if (Mathf.Abs(xDist) > Mathf.Abs(yDist) && Mathf.Abs(xDist) > Mathf.Abs(zDist))
            {
                return(new Vector3Int((int)(hit.transform.parent.position.x + (xDist > 0 ? 1 : -1) * sideModifier), (int)(hit.transform.parent.position.y), (int)(hit.transform.parent.position.z)));
            }
            else if (Mathf.Abs(yDist) > Mathf.Abs(xDist) && Mathf.Abs(yDist) > Mathf.Abs(zDist))
            {
                return(new Vector3Int((int)(hit.transform.parent.position.x), (int)(hit.transform.parent.position.y + (yDist > 0 ? 1 : -1) * sideModifier), (int)(hit.transform.parent.position.z)));
            }
            else
            {
                return(new Vector3Int((int)(hit.transform.parent.position.x), (int)(hit.transform.parent.position.y), (int)(hit.transform.parent.position.z + (zDist > 0 ? 1 : -1) * sideModifier)));
            }
        }
        else
        {
            Dicoord dicoord   = (Dicoord)hit.transform.parent.GetComponent <ModelTileBridge>().Data;
            float   upDist    = Mathf.Abs(hit.point.y - 0.5f - dicoord.GetPos2().y);
            float   downDist  = Mathf.Abs(hit.point.y + 0.5f - dicoord.GetPos1().y);
            float   westDist  = Mathf.Abs(hit.point.z - 0.5f - dicoord.GetPos2().z);
            float   eastDist  = Mathf.Abs(hit.point.z + 0.5f - dicoord.GetPos1().z);
            float   northDist = Mathf.Abs(hit.point.x - 0.5f - dicoord.GetPos2().x);
            float   southDist = Mathf.Abs(hit.point.x + 0.5f - dicoord.GetPos1().x);

            int xRounded = Mathf.RoundToInt(hit.point.x);
            int yRounded = Mathf.RoundToInt(hit.point.y);
            int zRounded = Mathf.RoundToInt(hit.point.z);

            if (upDist < downDist && upDist < westDist && upDist < eastDist && upDist < northDist && upDist < southDist)
            {
                return(new Vector3Int(xRounded, dicoord.GetPos2().y + sideModifier, zRounded));
            }
            else if (downDist < upDist && downDist < westDist && downDist < eastDist && downDist < northDist && downDist < southDist)
            {
                return(new Vector3Int(xRounded, dicoord.GetPos1().y - sideModifier, zRounded));
            }
            else if (westDist < upDist && westDist < downDist && westDist < eastDist && westDist < northDist && westDist < southDist)
            {
                return(new Vector3Int(dicoord.GetPos2().y + sideModifier, yRounded, zRounded));
            }
            else if (eastDist < upDist && eastDist < downDist && eastDist < westDist && eastDist < northDist && eastDist < southDist)
            {
                return(new Vector3Int(dicoord.GetPos1().y - sideModifier, yRounded, zRounded));
            }
            else if (northDist < upDist && northDist < downDist && northDist < westDist && northDist < eastDist && northDist < southDist)
            {
                return(new Vector3Int(xRounded, yRounded, dicoord.GetPos2().z + sideModifier));
            }
            else
            {
                return(new Vector3Int(xRounded, yRounded, dicoord.GetPos1().z - sideModifier));
            }
        }
    }
예제 #4
0
    public void LoadLevel(string levelPath, bool playing)
    {
        // Load LevelData and initialize the lists
        levelData = (LevelData)SerializationManager.LoadData(levelPath);
        TileElement tileModel = Constants.TILE_MODELS[(int)TileElementNames.Ground];

        availableVines = levelData.availableVines;

        // Create the Grounds
        board = new TileElement[levelData.grounds.GetLength(0), levelData.grounds.GetLength(1), levelData.grounds.GetLength(2)];
        for (int x = 0; x < board.GetLength(0); x++)
        {
            for (int y = 0; y < board.GetLength(1); y++)
            {
                for (int z = 0; z < board.GetLength(2); z++)
                {
                    if (levelData.grounds[x, y, z] != null)
                    {
                        board[x, y, z] = tileModel.LoadTileElement(new object[] {
                            new Vector3Int(x, y, z),
                            levelData.grounds[x, y, z]
                        });
                        board[x, y, z].model = Instantiate(Resources.Load("Models/Ground")) as GameObject;
                        board[x, y, z].BindDataToModel();
                        board[x, y, z].WarpToPos();
                        ((Ground)board[x, y, z]).ColorFacets(litBases);
                    }
                }
            }
        }

        // Create Bramble and save his position
        bramble = (Bramble)Constants.TILE_MODELS[(int)TileElementNames.Bramble].LoadTileElement(new object[]
        {
            new Vector3Int(levelData.brambleCoords[0], levelData.brambleCoords[1], levelData.brambleCoords[2]),
            levelData.brambleDirection
        });
        bramble.model = Instantiate(Resources.Load("Models/Bramble")) as GameObject;
        bramble.BindDataToModel();
        bramble.WarpToPos();
        board[bramble.GetPos().x, bramble.GetPos().y, bramble.GetPos().z] = bramble;

        // Create the Sigil
        board[levelData.sigilCoords[0], levelData.sigilCoords[1], levelData.sigilCoords[2]] = (Sigil)Constants.TILE_MODELS[(int)TileElementNames.Sigil].LoadTileElement(new object[]
        {
            new Vector3Int(levelData.sigilCoords[0], levelData.sigilCoords[1], levelData.sigilCoords[2]),
        });
        board[levelData.sigilCoords[0], levelData.sigilCoords[1], levelData.sigilCoords[2]].model = Instantiate(Resources.Load("Models/Sigil")) as GameObject;
        board[levelData.sigilCoords[0], levelData.sigilCoords[1], levelData.sigilCoords[2]].BindDataToModel();
        board[levelData.sigilCoords[0], levelData.sigilCoords[1], levelData.sigilCoords[2]].WarpToPos();

        // Convert the data arrays to Queues
        Queue <int> intQueue = new Queue <int>();

        for (int i = 0; i < levelData.dataInts.Length; i++)
        {
            intQueue.Enqueue(levelData.dataInts[i]);
        }
        Queue <Shade> shadeQueue = new Queue <Shade>();

        for (int i = 0; i < levelData.dataShades.Length; i++)
        {
            shadeQueue.Enqueue(levelData.dataShades[i]);
        }

        // Decompile all of the non-essential elements
        for (int i = 0; i < levelData.tileTypes.Length; i++)
        {
            TileElement tileBase       = Constants.TILE_MODELS[(int)levelData.tileTypes[i]];
            TileElement decompiledTile = tileBase.DecompileTileElement(ref intQueue, ref shadeQueue);
            decompiledTile.model = Instantiate(Resources.Load("Models/" + tileBase.TileName())) as GameObject;
            decompiledTile.BindDataToModel();
            decompiledTile.WarpToPos();
            decompiledTile.AdjustRender();
            if (tileBase is Monocoord)
            {
                Monocoord monoTile = (Monocoord)decompiledTile;
                board[monoTile.GetPos().x, monoTile.GetPos().y, monoTile.GetPos().z] = decompiledTile;
            }
            else
            {
                Dicoord diTile = (Dicoord)decompiledTile;
                for (int x = diTile.GetPos1().x; x <= diTile.GetPos2().x; x++)
                {
                    for (int y = diTile.GetPos1().y; y <= diTile.GetPos2().y; y++)
                    {
                        for (int z = diTile.GetPos1().z; z <= diTile.GetPos2().z; z++)
                        {
                            board[x, y, z] = decompiledTile;
                        }
                    }
                }
            }
        }

        CameraManager.current.CalibrateCamera(board);
    }