Example #1
0
    B_Jump CheckIfTileIsJumpBonus(int Tile) //Check if the TileID is a Bonus Jump Tile
    {
        B_Jump TempSE0 = new B_Jump();

        TempSE0.TileID    = Tile;
        TempSE0.Direction = B_Jump_Direction.Up;

        if (B_JumpArray.Contains <B_Jump>(TempSE0))
        {
            return(TempSE0);
        }

        else
        {
            TempSE0.Direction = B_Jump_Direction.Down;
            if (B_JumpArray.Contains <B_Jump>(TempSE0))
            {
                return(TempSE0);
            }

            else
            {
                TempSE0.Direction = B_Jump_Direction.Left;
                if (B_JumpArray.Contains <B_Jump>(TempSE0))
                {
                    return(TempSE0);
                }

                else
                {
                    TempSE0.Direction = B_Jump_Direction.Right;
                    if (B_JumpArray.Contains <B_Jump>(TempSE0))
                    {
                        return(TempSE0);
                    }
                }
            }
        }
        return(TempSE0);;
    }
Example #2
0
    void SpawnFromPositions() //Spawn all tiles on positions in CubePositions[]
    {
        if (PositionsCalculated)
        {
            if (!TilesSpawned)
            {
                if (EnableLog)
                {
                    Debug.Log("Starting spawning cubes ...");
                }
                int CurrentTileSpawned = 0;

                foreach (Vector3 TilePosition in CubePositions)
                {
                    //Spawns the tile, sets its parent and its name
                    GameObject SpawnedTile = Instantiate(Cube, gameObject.transform.localPosition + TilePosition, gameObject.transform.rotation);
                    SpawnedTile.transform.SetParent(gameObject.transform);
                    SpawnedTile.gameObject.name = "Tile " + CurrentTileSpawned;

                    //Check if tile is a Bonus Tile and if so set the tile as bonus tile
                    //Double Walk Bonus
                    if (B_DoubleWalk.Count > 0)
                    {
                        if (B_DoubleWalk.Contains(CurrentTileSpawned))
                        {
                            SpawnedTile.GetComponent <Tile_Interactions>().SetTileBonus(TileBonus.DoubleWalk);
                        }
                    }

                    //Jump bonus
                    if (B_JumpArray.Length > 0)
                    {
                        B_Jump TempBJump = CheckIfTileIsJumpBonus(CurrentTileSpawned);

                        if (B_JumpArray.Contains <B_Jump>(TempBJump))
                        {
                            SpawnedTile.GetComponent <Tile_Interactions>().SetTileBonus(TileBonus.Jump);


                            switch (B_JumpArray[System.Array.IndexOf(B_JumpArray, TempBJump)].Direction)
                            {
                            case B_Jump_Direction.Up:
                                if (CurrentTileSpawned + 2 >= 0 && CurrentTileSpawned + 2 <= XSize * YSize && !ToDelete.Contains <int>(CurrentTileSpawned + 2))
                                {
                                    SpawnedTile.GetComponent <Tile_Interactions>().BJumpToTileID  = CurrentTileSpawned + 2;
                                    SpawnedTile.transform.Find("BonusSprite").transform.rotation *= new Quaternion(0, 1, 0, 0);
                                }
                                break;

                            case B_Jump_Direction.Down:
                                if (CurrentTileSpawned - 2 >= 0 && CurrentTileSpawned - 2 <= XSize * YSize && !ToDelete.Contains <int>(CurrentTileSpawned - 2))
                                {
                                    SpawnedTile.GetComponent <Tile_Interactions>().BJumpToTileID  = CurrentTileSpawned - 2;
                                    SpawnedTile.transform.Find("BonusSprite").transform.rotation *= new Quaternion(0, 0, 0, 1);
                                }
                                break;

                            case B_Jump_Direction.Left:
                                if (CurrentTileSpawned + YSize >= 0 && CurrentTileSpawned + YSize <= XSize * YSize && !ToDelete.Contains <int>(CurrentTileSpawned + YSize))
                                {
                                    SpawnedTile.transform.Find("BonusSprite").transform.rotation *= new Quaternion(0, 0, 0.7071f, -0.7071f);
                                    SpawnedTile.GetComponent <Tile_Interactions>().BJumpToTileID  = CurrentTileSpawned + YSize;
                                }
                                break;

                            case B_Jump_Direction.Right:
                                if (CurrentTileSpawned - YSize >= 0 && CurrentTileSpawned - YSize <= XSize * YSize && !ToDelete.Contains <int>(CurrentTileSpawned - YSize))
                                {
                                    SpawnedTile.GetComponent <Tile_Interactions>().BJumpToTileID  = CurrentTileSpawned - YSize;
                                    SpawnedTile.transform.Find("BonusSprite").transform.rotation *= new Quaternion(0, 0, 0.7071f, 0.7071f);
                                }
                                break;
                            }
                        }
                    }

                    //Sets falling animation time
                    SpawnedTile.GetComponent <Animation_MoveInDirection>().StartDelay           = (Mathf.Round(CurrentTileSpawned) + 0.01f) / 10;
                    SpawnedTile.GetComponent <Animation_MoveInDirection>().AnimationSpeedInS    = 0.8f;
                    SpawnedTile.GetComponent <Animation_MoveInDirection>().KeepOriginalPosition = true;
                    SpawnedTile.GetComponent <Animation_MoveInDirection>().KeepOriginalScale    = true;
                    SpawnedTile.GetComponent <Animation_MoveInDirection>().ScaleAnimation       = Animation_MoveInDirection.ScaleAnim.Scale_Up;
                    SpawnedTile.GetComponent <Animation_MoveInDirection>().ActivateAnimation();

                    //Displays or not the TileID in 3D world
                    if (ShowTileID)
                    {
                        SpawnedTile.transform.GetComponentInChildren <TextMesh>().text = CurrentTileSpawned.ToString();
                    }
                    else
                    {
                        SpawnedTile.transform.GetComponentInChildren <TextMesh>().text = " ";
                    }

                    //Hides the tile if EditMode is false
                    if (!EditMode)
                    {
                        SpawnedTile.GetComponent <MeshRenderer>().enabled = false; SpawnedTile.GetComponentInChildren <SpriteRenderer>().enabled = false;
                    }

                    CubeArray[CurrentTileSpawned] = SpawnedTile;

                    //Sets variable for next tile and check if last tile was spawned
                    CurrentTileSpawned++;

                    //Finalise cube spawning
                    if (CurrentTileSpawned >= CubePositions.Length)
                    {
                        transform.rotation = TempRotation;
                        SpawnedTileList    = new List <GameObject>(CubeArray);

                        DeleteSelectedTiles();
                        SetEndTile();
                        SpawnUnits();

                        if (EnableLog)
                        {
                            Debug.Log("Finished spawning cubes.");
                        }
                    }
                }
            }
            else
            {
                if (EnableLog)
                {
                    Debug.Log("Tiles are already spawned.");
                }
            }
        }

        else
        {
            if (EnableLog)
            {
                Debug.Log("Positions seems not be calculated (PositionsCalculated=false).");
            }
        }
    }