Esempio n. 1
0
    void ApplyVerticalVelocity()
    {
        float NewYDistance;

        NewYDistance = Velocity.y * WorldProperties.GetDeltaTime();

        NewYDistance = ConstrainVerticalVelocity(NewYDistance);

        transform.position += new Vector3(0, NewYDistance, 0);
    }
Esempio n. 2
0
    void ApplyHorizontalVelocity()
    {
        float NewXDistance;

        if (IsGrounded)
        {
            if (FacingRight && Velocity.x > MaximumGroundSpeed)
            {
                Velocity.x = MaximumGroundSpeed;
            }

            if (!FacingRight && Velocity.x < -MaximumGroundSpeed)
            {
                Velocity.x = -MaximumGroundSpeed;
            }
        }
        else
        {
            if (FacingRight && Velocity.x > MaximumAirSpeedForward)
            {
                Velocity.x = MaximumAirSpeedForward;
            }

            if (FacingRight && Velocity.x < -MaximumAirSpeedBackward)
            {
                Velocity.x = -MaximumAirSpeedBackward;
            }

            if (!FacingRight && Velocity.x < -MaximumAirSpeedForward)
            {
                Velocity.x = -MaximumAirSpeedForward;
            }

            if (!FacingRight && Velocity.x > MaximumAirSpeedBackward)
            {
                Velocity.x = MaximumAirSpeedBackward;
            }
        }

        NewXDistance = Velocity.x * WorldProperties.GetDeltaTime();

        NewXDistance = ConstrainHorizontalVelocity(NewXDistance);

        transform.position += new Vector3(NewXDistance, 0, 0);
    }
Esempio n. 3
0
    void ApplyHorizontalVelocity()
    {
        float NewXDistance;

        if (Velocity.x > MaximumSpeed)
        {
            Velocity.x = MaximumSpeed;
        }

        if (Velocity.x < -MaximumSpeed)
        {
            Velocity.x = -MaximumSpeed;
        }

        NewXDistance = Velocity.x * WorldProperties.GetDeltaTime();

        NewXDistance = ConstrainHorizontalVelocity(NewXDistance);

        transform.position += new Vector3(NewXDistance, 0, 0);
    }
Esempio n. 4
0
    void ApplyVerticalVelocity()
    {
        float NewYDistance;

        if (Velocity.y > MaximumSpeed)
        {
            Velocity.y = MaximumSpeed;
        }

        if (Velocity.y < -MaximumSpeed)
        {
            Velocity.y = -MaximumSpeed;
        }

        NewYDistance = Velocity.y * WorldProperties.GetDeltaTime();

        NewYDistance = ConstrainVerticalVelocity(NewYDistance);

        transform.position += new Vector3(0, NewYDistance, 0);
    }
Esempio n. 5
0
    public override void ProcessState()
    {
        bool PressingRight               = Input.GetAxis("Horizontal") > 0;
        bool PressingLeft                = Input.GetAxis("Horizontal") < 0;
        bool StillHoldingJump            = Input.GetButton("Action");
        bool ExceededMaximumJumpDuration = TotalJumpDuration >= Actor.MaximumJumpDuration;
        bool HasBonkedHead               = Actor.GenerateMaxOffset("UP") <= 0;


        if (Input.GetKeyDown("o"))
        {
            MyStateManager.SetNextState("PlayerState_Rotate");
            return;
        }

        if (!PressingLeft && !PressingRight)
        {
            if (Actor.FacingRight)
            {
                if (Actor.Velocity.x > 0f)
                {
                    Actor.Velocity.x -= Actor.AirDecelerationForward;
                    if (Actor.Velocity.x <= 0f)
                    {
                        Actor.Velocity.x = 0f;
                    }
                }
                else
                {
                    Actor.Velocity.x += Actor.AirDecelerationBackward;
                    if (Actor.Velocity.x >= 0f)
                    {
                        Actor.Velocity.x = 0f;
                    }
                }
            }

            if (!Actor.FacingRight)
            {
                if (Actor.Velocity.x < 0f)
                {
                    Actor.Velocity.x += Actor.AirDecelerationForward;
                    if (Actor.Velocity.x >= 0f)
                    {
                        Actor.Velocity.x = 0f;
                    }
                }
                else
                {
                    Actor.Velocity.x -= Actor.AirDecelerationBackward;
                    if (Actor.Velocity.x <= 0f)
                    {
                        Actor.Velocity.x = 0f;
                    }
                }
            }
        }


        if (PressingRight)
        {
            if (Actor.FacingRight)
            {
                Actor.Velocity.x += Actor.AirAccelerationForward;
            }
            else
            {
                Actor.Velocity.x += Actor.AirAccelerationBackward;
            }

            if (Actor.CanChangeDirectionInMidAir)
            {
                Actor.FacingRight = true;
            }
        }

        if (PressingLeft)
        {
            if (!Actor.FacingRight)
            {
                Actor.Velocity.x -= Actor.AirAccelerationForward;
            }
            else
            {
                Actor.Velocity.x -= Actor.AirAccelerationBackward;
            }

            if (Actor.CanChangeDirectionInMidAir)
            {
                Actor.FacingRight = false;
            }
        }

        if (StillHoldingJump && !ExceededMaximumJumpDuration && !HasBonkedHead)
        {
            Actor.Velocity.y   = Actor.JumpStrength;
            TotalJumpDuration += WorldProperties.GetDeltaTime();
        }
        else
        {
            if (HasBonkedHead)
            {
                Actor.Velocity.y = 0;
            }

            MyStateManager.SetNextState("PlayerState_Fall");
        }
    }