コード例 #1
0
    public void Move(InputManager.MoveDirection md)
    {
        Debug.Log(md.ToString() + " move");
        moveMade = false;
        ResetMergeFlags();
        if (delay > 0)
        {
            StartCoroutine(MoveCoroutine(md));
        }
        else
        {
            for (int i = 0; i < rows.Count; i++)
            {
                switch (md)
                {
                case InputManager.MoveDirection.Down:
                    while (MakeOneMoveUpIndex(colums [i]))
                    {
                        moveMade = true;
                    }
                    break;

                case InputManager.MoveDirection.Left:
                    while (MakeOneMoveDownIndex(rows [i]))
                    {
                        moveMade = true;
                    }
                    break;

                case InputManager.MoveDirection.Right:
                    while (MakeOneMoveUpIndex(rows [i]))
                    {
                        moveMade = true;
                    }
                    break;

                case InputManager.MoveDirection.Up:
                    while (MakeOneMoveDownIndex(colums [i]))
                    {
                        moveMade = true;
                    }
                    break;
                }
            }

            if (moveMade)
            {
                UpdateEmptyTiles();
                Generate();

                if (!CanMove())
                {
                    GameOver();
                }
            }
        }
    }
コード例 #2
0
    IEnumerator MoveCoroutine(InputManager.MoveDirection md)
    {
        State = GameState.WaitingForMoveToEnd;

        //start moving each line with delays depending on InputManager.MoveDirection md
        switch (md)
        {
        case InputManager.MoveDirection.Down:
            for (int i = 0; i < colums.Count; i++)
            {
                StartCoroutine(MoveOneLineUpIndexCoroutine(colums [i], i));
            }
            break;

        case InputManager.MoveDirection.Left:
            for (int i = 0; i < rows.Count; i++)
            {
                StartCoroutine(MoveOneLineDownIndexCoroutine(rows [i], i));
            }
            break;

        case InputManager.MoveDirection.Right:
            for (int i = 0; i < rows.Count; i++)
            {
                StartCoroutine(MoveOneLineUpIndexCoroutine(rows [i], i));
            }
            break;

        case InputManager.MoveDirection.Up:
            for (int i = 0; i < colums.Count; i++)
            {
                StartCoroutine(MoveOneLineDownIndexCoroutine(colums [i], i));
            }
            break;
        }


        //Wait until the move is over in all the lines
        while (!(lineMoveComplete[0] && lineMoveComplete[1] && lineMoveComplete[2] && lineMoveComplete[3]))
        {
            yield return(null);
        }

        if (moveMade)
        {
            UpdateEmptyTiles();
            Generate();

            if (!CanMove())
            {
                GameOver();
            }
        }
        State = GameState.Playing;
    }
コード例 #3
0
ファイル: PlayerScript.cs プロジェクト: ToaLetan/GGJ2014
    private void PlayerMove(InputManager.MoveDirection movementdir)
    {
        Vector2 newPlayerPos = gameObject.transform.position;

        int directionModifier = 0;

        currentDirection = movementdir;

        if (movementdir == InputManager.MoveDirection.Up || movementdir == InputManager.MoveDirection.Down)
        {
            if(movementdir == InputManager.MoveDirection.Up)
                directionModifier = 1;
            else
                directionModifier = -1;

            if (currentvelocityY <= MAXVELOCITY)
                currentvelocityY += acceleration * Time.deltaTime;

            newPlayerPos.y += currentvelocityY * directionModifier;
        }

        if (movementdir == InputManager.MoveDirection.Left || movementdir == InputManager.MoveDirection.Right)
        {
            if(movementdir == InputManager.MoveDirection.Left)
                directionModifier = -1;
            else
                directionModifier = 1;

            if (currentvelocityX <= MAXVELOCITY)
                currentvelocityX += acceleration * Time.deltaTime;

            newPlayerPos.x += currentvelocityX * directionModifier;
        }

        gameObject.transform.position = newPlayerPos;
    }