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;
     }
 }
Esempio n. 2
0
        public Boolean collidesUpWithCollisionBox(CollisionBox box)
        {
            Vector2 playerPoint = upPoint();

            return(box.collidesWithMovingPoint(playerPoint, getMovingVector()));
        }
        // 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);
        }
Esempio n. 4
0
        public Boolean collidesDownWithCollisionBox(CollisionBox box)
        {
            Vector2 playerPoint = downPoint() + WorldInfo.gravity * 0.1f;

            return(box.collidesWithMovingPoint(playerPoint, getMovingVector()));
        }