Beispiel #1
0
        /// If skill not recognized - returns FALSE.
        public bool ChkSkillActivationInput(SkillType skillType)
        {
            switch (skillType)
            {
            case SkillType.First:
                return(RuyoInputReceiver.GetInstance().GetKeyDown(RuyoInputReceiver.FirstSkillKey));

            case SkillType.Second:
                return(RuyoInputReceiver.GetInstance().GetKeyDown(RuyoInputReceiver.SecondSkillKey));

            case SkillType.Third:
                return(RuyoInputReceiver.GetInstance().GetKeyDown(RuyoInputReceiver.ThirdSkillKey));

            default:
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Determines, basing only on the state of Y axis, whether is the character climbing up or down.
        /// </summary>
        void ClimbingUpOrDown()
        {
            Vector2 input = RuyoInputReceiver.GetInstance().RetrieveInput();

            if (input.y > 0)
            {
                movement.climbUp   = true;
                movement.climbDown = false;
            }
            else if (input.y < 0)
            {
                movement.climbUp   = false;
                movement.climbDown = true;
            }
            else
            {
                movement.climbUp = movement.climbDown = false;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Checks the inputs of special movement keys (jump, climbing)
        /// and raw input. These need special care since current collision status has
        /// influence on these and vice-versa.
        /// </summary>
        /// <param name="input">Raw input from X and Y axes (Input.GetAxes).</param>
        /// <param name="currentGravity">Current gravity (NOT(!!!!!!!!!!!) scaled by lastFrameTime).</param>
        void ChkInputs(ref Vector3 currentVelocity, Vector2 input, float currentGravity)
        {
            if (input.y > 0)
            {
                movement.climbUp   = true;
                movement.climbDown = false;
            }
            else if (input.y < 0)
            {
                movement.climbUp   = false;
                movement.climbDown = true;
            }
            else
            {
                movement.climbUp = movement.climbDown = false;
            }

            movement.climbKeyOn = RuyoInputReceiver.GetInstance().GetKey(RuyoInputReceiver.ClimbKey);

            if (RuyoInputReceiver.GetInstance().GetKeyDown(RuyoInputReceiver.JumpKey))
            {
                if (collisions.below)
                {
                    currentVelocity.y = _currJumpVelocity;
                }
                else if (CanDoubleJump())
                {
                    currentVelocity.y      = _currJumpVelocity * _currDoubleJumpFactor;
                    movement.canDoubleJump = false;
                }
            }
            else if (movement.climbKeyOn && ((collisions.left || collisions.right) && IsClimbingWall()))
            {
                // float targetVelocityY = input.y * _currClimbMoveSpeed;
                //velocity.y = Mathf.SmoothDamp(velocity.y, targetVelocityY, ref velocityYSmoothing, accelerationTimeGrounded);
                currentVelocity.y = input.y * _currClimbMoveSpeed;
            }
            else
            {
                currentVelocity.y += currentGravity;
            }
        }
Beispiel #4
0
        /// <summary>
        /// Ensures movement of the player. Calls IController2D to check the collisions and input.
        /// Checks raw input.
        /// </summary>
        /// <param name="lastFrameTime">The time it took to calculate through last frame.</param>
        private void MovePlayer(float lastFrameTime)
        {
            Vector2 input        = RuyoInputReceiver.GetInstance().RetrieveInput();
            float   desiredSpeed = input.x * _myCharacter.MoveSpeed;


            _currentVelocity.x = Mathf.SmoothDamp(_currentVelocity.x, desiredSpeed, ref _storeVelocitySmoothing,
                                                  _controller2D.Collisions.below? _myCharacter.AccelTimeGrounded : _myCharacter.AccelTimeAirborne);


            //Assign modified speed to another vector - we need to preserve the original, unaffected by time speed.
            Vector3 preparedVelocity = _controller2D.PrepareMove(ref _currentVelocity, input, _myCharacter.JumpVelocity,
                                                                 _myCharacter.DoubleJumpFactor, _myCharacter.ClimbingMoveSpeed, _myCharacter.Gravity, lastFrameTime);


            //Move the player...
            transform.Translate(new Vector3(preparedVelocity.x, preparedVelocity.y, 0.0f));
            //...and the camera after the player.
            _cameraWorks.MoveCamera(transform.position);
        }
Beispiel #5
0
 public bool IsShooting()
 {
     return(RuyoInputReceiver.GetInstance().GetKey(RuyoInputReceiver.LeftMouseButton));
 }
Beispiel #6
0
        /* public void RotateClimbingCharacter(Vector3 currentVelocity)
         * {
         *   transform.localScale = new Vector3(Mathf.Abs(transform.localScale.x) * Mathf.Sign(currentVelocity.x), transform.localScale.y, transform.localScale.z);
         * }*/
        public Vector3 PrepareMove(ref Vector3 velocity, Vector2 rawInput, float currJumpVelocity,
                                   float currDoubleJumpFactor, float currClimbMoveSpeed, float currGravity, float lastFrameTime)
        {
            Vector3 timeScaledVelocity;

            //Check if the player is climbing or standing on ground or colliding with ceiling.
            //If yes - set their Y velocity to 0
            velocity.y = ChkVerticalCollisions(velocity.y);

            _currClimbMoveSpeed   = currClimbMoveSpeed;
            _currDoubleJumpFactor = currDoubleJumpFactor;
            _currJumpVelocity     = currJumpVelocity;

            currGravity *= lastFrameTime;

            ChkInputs(ref velocity, rawInput, currGravity);
            timeScaledVelocity = new Vector3(velocity.x, velocity.y, velocity.z);
            //Finished checking input. Multiply the velocity and gravity by last frame time.
            timeScaledVelocity *= lastFrameTime;

            SetClimbingYProjectionLength(currGravity);

            if (Mathf.Abs(timeScaledVelocity.x) < InputPadding)
            {
                timeScaledVelocity.x = 0;
            }
            collisions.Reset();

            bool isClimbingUpKeyPressed = RuyoInputReceiver.GetInstance().GetKey(RuyoInputReceiver.ClimbKey);

            ClimbingUpOrDown();
            movement.SetIsClimbing(isClimbingUpKeyPressed);
            UpdateRayCastOrigins();


            collisions.velocityOld = timeScaledVelocity;

            if (timeScaledVelocity.y < 0 && !IsClimbingWall())
            {
                DescendSlope(ref timeScaledVelocity);
            }

            if (IsFloatZero(timeScaledVelocity.x) == false)
            {
                HorizontalCollisions(ref timeScaledVelocity);
            }

            if (IsClimbingWall() && !(collisions.below || collisions.above))
            {
                ChkWallCollisions(ref timeScaledVelocity);//TODO repair the x velocity when shift pressed bug in here
            }

            if (IsFloatZero(timeScaledVelocity.y) == false)
            {
                VerticalCollisions(ref timeScaledVelocity);
            }

            movement.ResetDoubleJump(collisions);

            //transform.Translate(velocity);

            NotifyObservers();

            return(timeScaledVelocity);
        }