예제 #1
0
    // Update is called once per frame
    void Update()
    {
        Vector2       playerInput;
        bool          rotate;
        DirectionType shapeDir = DirectionType.NONE;

        //Get key inputs
        playerInput.x = Input.GetAxis("Horizontal");
        playerInput.y = Input.GetAxis("Vertical");

        playerInput = new Vector2(playerInput.x, playerInput.y).normalized;

        //Check for 'rotate' key and rotate the shape
        rotate = Input.GetKeyDown(KeyCode.R);

        //Assign a direction based on the input
        if (playerInput.x == 1)
        {
            shapeDir = DirectionType.RIGHT;
        }
        else if (playerInput.x == -1)
        {
            shapeDir = DirectionType.LEFT;
        }
        else if (playerInput.y == -1)
        {
            shapeDir = DirectionType.DOWN;
        }

        //BRP TODO: See if this logic can be simplified between the player input
        //and requested direction
        if (gridBehavior.IsMoveLegal((int)transform.position.x, (int)transform.position.y, shapeDir))
        {
            if (playerInput.x != 0 &&
                Time.time > (lastTimePressedX + CooldownTimeX))
            {
                updatePosition(shapeDir);
                lastTimePressedX = Time.time;
            }

            if (playerInput.y == -1 &&
                Time.time > (lastTimePressedY + CooldownTimeY))
            {
                updatePosition(shapeDir);
                lastTimePressedY = Time.time;
            }
        }

        if (playerInput.y == 0 && Time.time > (lastMove + MoveTime) &&
            gridBehavior.IsMoveLegal((int)transform.position.x, (int)transform.position.y, DirectionType.DOWN))
        {
            updatePosition(DirectionType.DOWN);
            lastMove = Time.time;
        }
    }