Пример #1
0
 public void ResolveCollision(Sprite collidingSprite)
 {
     //player is colliding with top side
     if (CollisionBox.GetAABBmin().Y > collidingSprite.CollisionBox.GetAABBmax().Y&& CollisionBox.GetAABBmin().Y < collidingSprite.CollisionBox.GetAABBmin().Y)
     {
         position.Y = collidingSprite.position.Y - GetFrameSize.Y;
         return;
     }
     // player is colliding with down side
     if (CollisionBox.GetAABBmax().Y < collidingSprite.CollisionBox.GetAABBmin().Y&& CollisionBox.GetAABBmax().Y > collidingSprite.CollisionBox.GetAABBmax().Y)
     {
         position.Y = collidingSprite.position.Y + GetFrameSize.Y;
         return;
     }
     //// player is colliding with right side
     if (CollisionBox.GetAABBmin().X > collidingSprite.CollisionBox.GetAABBmax().X&& CollisionBox.GetAABBmin().X < collidingSprite.CollisionBox.GetAABBmin().X)
     {
         position.X = collidingSprite.position.X - GetFrameSize.X;
         return;
     }
     // player is colliding with left side
     if (CollisionBox.GetAABBmax().X < collidingSprite.CollisionBox.GetAABBmin().X&& CollisionBox.GetAABBmax().X > collidingSprite.CollisionBox.GetAABBmax().X)
     {
         position.X = collidingSprite.position.X + collidingSprite.GetFrameSize.X;
         return;
     }
 }
Пример #2
0
        // AABB test
        public bool IsOverlaping(Sprite spriteToTest)
        {
            // Monogame uses different coordinates system so AABB test will be slightly different than usual
            if (CollisionBox.GetAABBmax().X > spriteToTest.CollisionBox.GetAABBmin().X || CollisionBox.GetAABBmin().X < spriteToTest.CollisionBox.GetAABBmax().X)
            {
                return(false);
            }

            if (CollisionBox.GetAABBmax().Y > spriteToTest.CollisionBox.GetAABBmin().Y || CollisionBox.GetAABBmin().Y < spriteToTest.CollisionBox.GetAABBmax().Y)
            {
                return(false);
            }
            return(true);
        }