Beispiel #1
0
    /// <summary>
    /// Push the eggs over if not falling
    /// </summary>
    /// <param name="direction"></param>
    /// <param name="grid"></param>
    public void Toss(BumpDirection direction, Vector2 grid)
    {
        //if (eggState != EggState.Falling && eggState != EggState.Resting)
        //{
            if (direction == BumpDirection.Left)
            {
                //While the slot left of me isn't the edge
                while ((grid.x) > 0)
                {
                    trappedLeft = false; atEdge = false;

                    //Slide if there isn't anything to the left of me
                    if (!IsSomethingLeftOfMe(grid) && !trappedLeft)
                    {
                        //And either there isn't anything under and I'm not at the bottom
                        if (!CheckIfGrounded())
                        {
                            eggState = EggState.Falling;
                            break;
                        }
                        else
                        //If I'm at the bottom of the grid
                        if (CheckIfGrounded())
                        {
                            //eggState = EggState.Resting;
                            PositionToGrid(new Vector2(grid.x - 1, grid.y));
                            break;
                        }

                        //Start sliding me over to the left
                        //PositionToGrid(new Vector2(grid.x - 1, grid.y));
                        break;
                    }
                    else if (IsSomethingLeftOfMe(grid))//If I bumped into something on the left
                    {
                        if (!nLeft.trappedLeft)
                        {
                            nLeft.bumpDirection = BumpDirection.Left;
                            nLeft.eggState = EggState.Bumped;
                            eggState = EggState.Bumped;
                        }
                        else
                        {
                            //eggState = EggState.Resting;
                        }
                        break;
                    }
                }

                //If I'm on the left edge
                if (grid.x == 0)
                {
                    //bumpDirection = BumpDirection.Down;
                    trappedLeft = true;
                    atEdge = true;
                    //eggState = EggState.Resting;
                }
                else
                {
                    trappedLeft = false;
                    atEdge = false;
                }
            }
            else
                if (direction == BumpDirection.Right)
                {
                    //While the slot right of me isn't the edge
                    while ((grid.x) < GameMain.colCount - 1)
                    {
                        trappedRight = false; atEdge = false;

                        //If there isn't anything to the right of me
                        if (!IsSomethingRightOfMe(grid))
                        {
                            //And either there isn't anything under and I'm not at the bottom
                            if (!IsSomethingUnderneath(gridCoord) && grid.y != 0)
                            {
                                eggState = EggState.Falling;
                                break;
                            }
                            //If I'm at the bottom of the grid
                            if (gridCoord.y == 0)
                            {
                                PositionToGrid(new Vector2(grid.x + 1, grid.y));
                                break;
                            }

                            //Start sliding me over to the right
                            PositionToGrid(new Vector2(grid.x + 1, grid.y));
                            break;
                        }
                        else //If I bumped into something on the right
                        {
                            if (!nRight.atEdge)
                            {
                                nRight.bumpDirection = BumpDirection.Right;
                                nRight.eggState = EggState.Bumped;
                            }
                            eggState = EggState.Falling;
                            break;
                        }
                    }
                    //If I'm on the right edge
                    if (grid.x == GameMain.colCount - 1)
                    {
                        bumpDirection = BumpDirection.Down;
                        trappedRight = true;
                        eggState = EggState.Resting;
                        atEdge = true;
                    }
                    else
                    {
                        trappedRight = false;
                        atEdge = false;
                    }
          //      }
        }
    }
Beispiel #2
0
    /// <summary>
    /// Drop the egg down like gravity
    /// </summary>
    /// <param name="grid"></param>
    /// <returns></returns>
    /// 
    void Drop(Vector2 grid)
    {
        //eggState = EggState.Falling;

        //Move the cube drown
        while (!CheckIfGrounded())
        {
            //yield return new WaitForSeconds(0.05f);

            //Make sure I'm not in the last row
            if (!CheckIfOnLastRow())
            {
                //I landed on something
                if (CheckIfGrounded())
                {
                    eggState = EggState.Resting;
                    break;
                }
                //Falling
                else if (!CheckIfGrounded())
                {
                    PositionToGrid(new Vector2(gridCoord.x, gridCoord.y - 1));
                }
            }
            else if (CheckIfGrounded())
            {
                eggState = EggState.Resting;

                if (IsSomethingAbove(gridCoord))
                {
                    break;
                }
                else if (!CheckIfGrounded())
                {
                    PositionToGrid(new Vector2(gridCoord.x, gridCoord.y));
                    break;
                }
                break;
            }

            //If I'm on the very top and nothing is under me
            else if (CheckIfOnLastRow())
            {
                if (CheckIfGrounded())
                {
                    PositionToGrid(new Vector2(gridCoord.x, gridCoord.y));
                    bumpDirection = BumpDirection.Down;
                    eggState = EggState.Resting;
                    break;
                }
                PositionToGrid(new Vector2(gridCoord.x, gridCoord.y - 1));
            }
        }
    }
Beispiel #3
0
    /// <summary>
    /// An event called when the user unselects the mouse buttom
    /// </summary>
    public void OnMouseUp()
    {
        //If this egg is the selected one...
        if (eggState == EggState.Selected)
        {
            //Get the slot that the egg should be dropping into
            var gridInt = GameMain.GetGridSlotIndex(GameMain.currentEggDropCoords);
            gridCoord = GameMain.GetGridCoord(gridInt);

            //Set the grid coord to the position we are wanting to get in
            PositionToGrid(new Vector2(gridCoord.x, gridCoord.y));

            //Check to see if there is an egg in the slot we are trying to place
            //this egg in
            if (EggUtility.IsEggInSlot(gridCoord))
            {
                ReturnToCurrentSlot();
                return;
            }

            //Tag the egg
            tag = "Egg";

            bumpDirection = BumpDirection.Down;

            //Check to see if we are on the left side or the right side
            if (gridCoord.x == 0)
            {
                trappedLeft = true; trappedRight = false;
                bumpDirection = BumpDirection.Right;
                eggState = EggState.Bumped;
            }

            if (gridCoord.x == GameMain.colCount - 1)
            {
                trappedRight = true; trappedLeft = false;
                bumpDirection = BumpDirection.Left;
                eggState = EggState.Bumped;
            }
            else
            {
                trappedRight = false; trappedLeft = false;
                eggState = EggState.Falling;
            }

            //Change the egg to the state of resting
            //if (!IsSomethingUnderneath(gridCoord))

            //else
            //    eggState = EggState.Falling;

            //Replace the current egg with the one in the next egg pool
            GameMain.currentEgg = GameMain.nextEgg;

            //Create a new next egg
            GameMain.nextEgg = Instantiate(EggUtility.CreateNewEgg()) as SimpleEgg;

            //Place all the eggs in the right position
            GameMain.currentEgg.transform.position = new Vector3(GameMain.currentEggHolder.transform.position.x, GameMain.currentEggHolder.transform.position.y, -3);
            GameMain.nextEgg.transform.position = new Vector3(GameMain.nextEggHolder.transform.position.x, GameMain.nextEggHolder.transform.position.y, -3);
        }
    }