private void Update()
    {
        if (_spriterAnimator == null)
        {
            _spriterAnimator = GetComponent <SpriterDotNetBehaviour>().Animator;
            _animationList   = _spriterAnimator.GetAnimations().ToList();
        }

        if (_collisionState.OnSolidGround)
        {
            if (Time.time - _timer > 1.0f)
            {
                _controller.SetButtonPressTime(Buttons.MoveRight);
                _walkingMovementRequest.RequestMovement(Buttons.MoveRight);
                if (_currentIndex != _previousIndex)
                {
                    Play(_currentIndex);
                    _previousIndex = _currentIndex;
                }
            }
        }
        else
        {
            _timer = Time.time;
        }
    }
Exemplo n.º 2
0
 private void Lift()
 {
     if (_canLift && _controller.GetButtonPress(Buttons.AimDown) && _direction.y == -1.0f)
     {
         _initialMoveRequest.RequestMovement();
         _canLift = false;
     }
 }
Exemplo n.º 3
0
    private void OnButton(Buttons button)
    {
        /*
         * PLAYER WALKING
         */
        //AS LONG AS THE PLAYER IS NOT AIMING IN A DOWN DIRECTION AND FIRING, THEY CAN WALK
        // THIS IS TO PREVENT THE WALKING SCRIPT FROM OVERRIDING THE WEAPON RECOIL MOVEMENT
        if (_controller.GetButtonPress(Buttons.AimDown) && _controller.GetButtonPress(Buttons.Shoot) && _controller.GetButtonPressTime(Buttons.Shoot) < 0.25f)
        {
        }
        else
        {
            if (button == Buttons.MoveRight || button == Buttons.MoveLeft)
            {
                _moveRequest.RequestMovement(button);

                if (button == Buttons.MoveRight)
                {
                    _controller.SetAimDirection(0);
                }
                else if (button == Buttons.MoveLeft)
                {
                    _controller.SetAimDirection(4);
                }
            }
        }

        /*
         * FACING DIRECTION
         */
        switch (button)
        {
        case Buttons.MoveRight:
        case Buttons.AimRight:
            _controller.FacingDirection = Facing.Right;
            break;

        case Buttons.MoveLeft:
        case Buttons.AimLeft:
            _controller.FacingDirection = Facing.Left;
            break;

        default:
            break;
        }

        // In 2D games, to get the characters to chagnes directions, all we have to do is
        // to change the 'x' localScale from 1 or -1. This will flip the sprite.
        // Note: even though we are working in 2D, if we were to call Vector2, it might set the z
        // axis to 0, which would cause the sprite to disappear entirely.
        if (button == Buttons.MoveLeft || button == Buttons.MoveRight ||
            button == Buttons.AimLeft || button == Buttons.AimRight)
        {
            if (_controller.FacingDirection == Facing.Right && transform.localScale.x < 0)
            {
                transform.localScale = new Vector3(-transform.localScale.x,
                                                   transform.localScale.y, transform.localScale.z);
            }
            else if (_controller.FacingDirection == Facing.Left && transform.localScale.x > 0)
            {
                transform.localScale = new Vector3(-transform.localScale.x,
                                                   transform.localScale.y, transform.localScale.z);
            }
        }

        /*
         * SET AIM DIRECTION
         */
        // Check the incoming button and see if it is any of the aiming directions.
        // For the appropriate direction, set the correct value and update the controller.
        if (button == Buttons.AimDown || button == Buttons.AimLeft ||
            button == Buttons.AimRight || button == Buttons.AimUp)
        {
            if (_controller.GetButtonPress(Buttons.AimDown))
            {
                if (_controller.GetButtonPress(Buttons.AimRight))
                {
                    value = 7;
                }
                else if (_controller.GetButtonPress(Buttons.AimLeft))
                {
                    value = 5;
                }
                else
                {
                    value = 6;
                }
            }
            else if (_controller.GetButtonPress(Buttons.AimUp))
            {
                if (_controller.GetButtonPress(Buttons.AimRight))
                {
                    value = 1;
                }
                else if (_controller.GetButtonPress(Buttons.AimLeft))
                {
                    value = 3;
                }
                else
                {
                    value = 2;
                }
            }
            else if (_controller.GetButtonPress(Buttons.AimLeft))
            {
                value = 4;
            }
            else if (_controller.GetButtonPress(Buttons.AimRight))
            {
                value = 0;
            }

            _controller.SetAimDirection(value);
        }


        // THIS STATEMENT IS TO MITIGATE A SMALL DELAY BETWEEN WHEN THE PLAYER SHOOTS AND THE CHARACTER MOVING INTO A AIMING POSITION
        // WITHOUT THE PLAYER ACTUALLY AIMING.
        if (button == Buttons.Shoot && !_controller.GetButtonPress(Buttons.AimDown) && !_controller.GetButtonPress(Buttons.AimUp) &&
            !_controller.GetButtonPress(Buttons.AimLeft) && !_controller.GetButtonPress(Buttons.AimRight))
        {
            if (_controller.FacingDirection == Facing.Right)
            {
                _controller.SetButtonPressed(Buttons.AimRight);
            }
            else if (_controller.FacingDirection == Facing.Left)
            {
                _controller.SetButtonPressed(Buttons.AimLeft);
            }

            StartCoroutine(PersuaderDelay());
        }
        // IF THE PLAYER IS AIMING, THEN THERE IS NO NEED FOR THE SMALL DELAY AND FIRE IMMEDIATELY.
        else if (button == Buttons.Shoot && (_controller.GetButtonPress(Buttons.AimDown) || _controller.GetButtonPress(Buttons.AimUp) ||
                                             _controller.GetButtonPress(Buttons.AimLeft) || _controller.GetButtonPress(Buttons.AimRight)))
        {
            if (ButtonHeld != null)
            {
                ButtonHeld(Buttons.Shoot);
            }
        }
    }