Exemplo n.º 1
0
 public RootMotionEventArgs(RootMotion rootMotion)
 {
     RootMotion = rootMotion;
 }
Exemplo n.º 2
0
 public SpriteFrame(Rectangle source, Rectangle dest, int duration = 1, string setAnim = null, bool despawn = false, FrameEventAction frameEvent = null, RootMotion rootMotion = new RootMotion(), Collider frameCollider = null)
 {
     Source        = source;
     Dest          = dest;
     Duration      = duration;
     SetAnim       = setAnim;
     Despawn       = despawn;
     FrameEvent    = frameEvent;
     RootMotion    = rootMotion;
     FrameCollider = frameCollider;
 }
Exemplo n.º 3
0
        public override void Update(GameTime gameTime, Map level)
        {
            ProcessInput();

            bool WasGrounded = IsGrounded;

            if (!Utils.DEBUG_FLY)
            {
                if (Grounded)
                {
                    if (HasAerialControl)
                    {
                        Velocity = GroundNormal.PerRight().Normalized() * walkVelocity;
                    }
                    else
                    {
                        Velocity = new Vector2();
                    }
                    if (walkVelocity != 0 && Velocity.X != 0)
                    {
                        Velocity /= Math.Abs(Velocity.X);
                    }
                }
                else if (HasAerialControl)
                {
                    Velocity.X = walkVelocity;
                }
            }

            // Apply gravity
            Velocity.Y += 0.3f;
            if (Utils.DEBUG_FLY)
            {
                Velocity = new Vector2(0, 0);
            }

            Grounded     = false;
            GroundNormal = new Vector2(0, -1);

            Vector2    pos = Position;
            RootMotion rm  = Animations[CurrentAnimation].RootMotion;

            Vector2 vel    = Velocity + rm.Motion * new Vector2(rm.IgnoreFlip ? 1 : Flipped ? -1 : 1, 1);
            float   motion = vel.Length();

            if (Utils.DEBUG_FLY)
            {
                if (InputsPressed[InputAction.Left])
                {
                    Position.X -= 1; Flipped = true;
                }
                if (InputsPressed[InputAction.Right])
                {
                    Position.X += 1; Flipped = false;
                }
                if (InputsPressed[InputAction.Up])
                {
                    Position.Y -= 1;
                }
                if (InputsPressed[InputAction.Down])
                {
                    Position.Y += 1;
                }
            }

            foreach (MapVolume volume in level.Volumes)
            {
                Utils.QueueDebugPoly(volume.Poly, volume.Position, new Color(0, 255, 0));
            }

            while (motion > PhysicsMaxStep)
            {
                motion -= PhysicsMaxStep;
                pos     = ProcessCollision(level, pos, vel, PhysicsMaxStep);
            }
            pos = ProcessCollision(level, pos, vel, motion);

            if (!Utils.DEBUG_FLY)
            {
                Position = pos;
                if (Math.Abs(Position.X - (int)Position.X) < 0.001)
                {
                    Position.X = (int)Position.X;
                }
                if (Math.Abs(Position.Y - (int)Position.Y) < 0.001)
                {
                    Position.Y = (int)Position.Y;
                }
            }

            if (Grounded)
            {
                coyoteTime = CoyoteTimeDuration;
                Jumps      = 0;
            }
            else
            {
                coyoteTime = (float)Math.Max(-1f, coyoteTime - gameTime.ElapsedGameTime.TotalSeconds);
            }

            PlayerState pstate = State;

RetestState:
            if (State != pstate)
            {
                if (State == PlayerState.Roll && IsGrounded)
                {
                    Audio.PlaySFX(SFX.Roll);
                }
                else if (pstate == PlayerState.Roll)
                {
                    Audio.StopSFX(SFX.Roll);
                }

                if (State == PlayerState.Jump || State == PlayerState.DoubleJump)
                {
                    Audio.PlaySFX(SFX.Jump);
                }
            }

            switch (State)
            {
            case PlayerState.Stand:
                SetAnimation("stand");
                if (walkVelocity != 0)
                {
                    State = PlayerState.Walk;
                    goto RetestState;
                }
                if (TryForState(PlayerState.Jump))
                {
                    goto RetestState;
                }
                if (TryForState(PlayerState.Roll))
                {
                    goto RetestState;
                }
                if (TryForState(PlayerState.Dash))
                {
                    goto RetestState;
                }
                if (!IsGrounded)
                {
                    State = PlayerState.Fall;
                    goto RetestState;
                }
                HasAerialControl = true;
                break;

            case PlayerState.Walk:
                SetAnimation("walk");
                if (walkVelocity == 0)
                {
                    State = PlayerState.Stand;
                    goto RetestState;
                }
                if (TryForState(PlayerState.Jump))
                {
                    goto RetestState;
                }
                if (TryForState(PlayerState.Roll))
                {
                    goto RetestState;
                }
                if (TryForState(PlayerState.Dash))
                {
                    goto RetestState;
                }
                if (!IsGrounded)
                {
                    State = PlayerState.Fall;
                    goto RetestState;
                }
                HasAerialControl = true;
                break;

            case PlayerState.Jump:
                SetAnimation("jump");
                //if (Velocity.Y < 0 && InputsUp[InputAction.Up]) {
                //    Velocity.Y = 0f;
                //}
                if (IsGrounded)
                {
                    if (TryForState(PlayerState.Stand))
                    {
                        goto RetestState;
                    }
                }
                if (TryForState(PlayerState.Dash))
                {
                    goto RetestState;
                }
                if (TryForState(PlayerState.DoubleJump))
                {
                    goto RetestState;
                }
                if (Velocity.Y > 0f)
                {
                    State = PlayerState.Fall;
                    goto RetestState;
                }
                HasAerialControl = true;
                break;

            case PlayerState.DoubleJump:
                SetAnimation("doublejump");
                HasAerialControl = true;
                break;

            case PlayerState.Fall:
                SetAnimation("fall");
                if (IsGrounded)
                {
                    State = PlayerState.Stand;
                    goto RetestState;
                }
                if (TryForState(PlayerState.Dash))
                {
                    goto RetestState;
                }
                if (TryForState(PlayerState.DoubleJump))
                {
                    goto RetestState;
                }
                HasAerialControl = true;
                break;

            case PlayerState.Roll:
                SetAnimation("roll");
                bool canstand = true;
                foreach (MapVolume v in InVolumes)
                {
                    if (v.Type == MapVolumeType.LowPassage)
                    {
                        canstand = false;
                    }
                }
                if (canstand && !InputsPressed[InputAction.Down] && TryForState(PlayerState.Stand))
                {
                    goto RetestState;
                }
                //if (Velocity.Y < 0 && InputsUp[InputAction.Up]) {
                //    Velocity.Y = 0f;
                //}
                TryForState(PlayerState.Jump);
                State            = PlayerState.Roll;
                HasAerialControl = false;
                if (!WasGrounded && IsGrounded)
                {
                    Audio.PlaySFX(SFX.Roll);
                }
                if (WasGrounded && !IsGrounded)
                {
                    Audio.StopSFX(SFX.Roll);
                }
                break;

            case PlayerState.Dash:
                SetAnimation("dash");
                HasAerialControl = false;
                if (TryForState(PlayerState.DoubleJump))
                {
                    goto RetestState;
                }
                break;
            }

            // Reset momentary input storage for the next update.
            foreach (InputAction key in Enum.GetValues(typeof(InputAction)))
            {
                InputsUp[key] = false;
            }
            foreach (InputAction key in Enum.GetValues(typeof(InputAction)))
            {
                InputsDown[key] = false;
            }

            base.Update(gameTime);
        }