Exemple #1
0
        private void HandleCollisons()
        {
            if (!PlayerInstance.CanClimb)
            {
                foreach (var collison in collisionCollection.Rectangles)
                {
                    var thisMass  = 10;
                    var otherMass = 0;
                    collison.CollideAgainstMove(PlayerInstance.AxisAlignedRectangleInstance, thisMass, otherMass);
                }
            }
            else
            {
                foreach (var collison in collisionCollection.Rectangles)
                {
                    if (collison.CollideAgainst(PlayerInstance.AxisAlignedRectangleInstance))
                    {
                        PlayerInstance.Y            = (collison.Y + collison.Height / 2) + PlayerInstance.Height / 2;
                        PlayerInstance.currentState = Entities.Player.State.STATE_IDLE;

                        PlayerInstance.CanJump = true;
                    }
                    else
                    {
                        PlayerInstance.CanJump = false;
                    }
                }
            }

            foreach (var climbableCollision in climbableCollection.Rectangles)
            {
                if (climbableCollection.CollideAgainst(PlayerInstance.AxisAlignedRectangleInstance))
                {
                    if (PlayerInstance.YVelocity != 0)
                    {
                        PlayerInstance.currentState = Entities.Player.State.STATE_CLIMB;
                    }
                    else
                    {
                        PlayerInstance.currentState = Entities.Player.State.STATE_CLIMB_IDLE;
                    }

                    PlayerInstance.CanClimb = true;
                }
                else
                {
                    PlayerInstance.CanClimb = false;
                }
            }

            foreach (var damageCollision in damagingCollection.Rectangles)
            {
                if (damageCollision.CollideAgainst(PlayerInstance.AxisAlignedRectangleInstance))
                {
                    if (!PlayerInstance.RecentlyDamaged)
                    {
                        PlayerInstance.DoDamage();
                    }
                }
                else
                {
                    if (PlayerInstance.RecentlyDamaged)
                    {
                        PlayerInstance.RecentlyDamaged = false;
                    }
                }
            }
        }