예제 #1
0
        public bool CollisionBottom(Collideable otherObj)
        {
            Rectangle collisionRect = Rectangle.Intersect(CollisionBox(), otherObj.CollisionBox());

            //Top collision
            if (otherObj.CollisionBox().Top < CollisionBox().Bottom
                && otherObj.CollisionBox().Top >= prevDestinationBox.Bottom)
            {
                position = new Vector2(position.X, (float)collisionRect.Top - destinationBox.Height);
                velocity = new Vector2(velocity.X, 0);
                return true;
            }
            return false;
        }
예제 #2
0
        /// <summary>
        /// Handles collision logic for top collision.
        /// </summary>
        /// <param name="otherObj">the other object</param>
        /// <returns>true if it was a collision, false otherwise</returns>
        public override bool CollisionTop(Collideable otherObj)
        {
            Rectangle collisionRect = Rectangle.Intersect(CollisionBox(), otherObj.CollisionBox());
            //check otherObj's Bottom side

            if (otherObj.CollisionBox().Bottom > CollisionBox().Top
                && otherObj.CollisionBox().Bottom <= prevDestinationBox.Top)
            {
                position = new Vector2(position.X, position.Y + (float)collisionRect.Height);
                velocity = new Vector2(velocity.X, 0);
            }
            return false;
        }
예제 #3
0
        /// <summary>
        /// Handles collision logic for right collision.
        /// This method can be overwritten to apply additional logic
        /// to happen.
        /// </summary>
        /// <param name="otherObj">the other object</param>
        /// <returns>true if it was a collision, false otherwise</returns>
        public virtual bool CollisionTop(Collideable otherObj)
        {
            Rectangle collisionRect = Rectangle.Intersect(CollisionBox(), otherObj.CollisionBox());
            //check otherObj's Bottom side

            if (otherObj.CollisionBox().Bottom > CollisionBox().Top
                && otherObj.CollisionBox().Bottom <= prevDestinationBox.Top)
            {
                position = new Vector2(position.X, position.Y + (float)collisionRect.Height);
                velocity = new Vector2(velocity.X, 0);
                //Debug.WriteLine(otherObj.CollisionBox().Height + " " + otherObj.CollisionBox().Width);
                return true;
            }
            return false;
        }
예제 #4
0
 /// <summary>
 /// Handles collision logic for right collision.
 /// This method can be overwritten to apply additional logic
 /// to happen.
 /// </summary>
 /// <param name="otherObj">the other object</param>
 /// <returns>true if it was a collision, false otherwise</returns>
 public virtual bool CollisionRight(Collideable otherObj)
 {
     Rectangle collisionRect = Rectangle.Intersect(CollisionBox(), otherObj.CollisionBox());
     // Check otherObj's left side.
     if (otherObj.CollisionBox().Left < CollisionBox().Right
         && otherObj.CollisionBox().Left >= prevDestinationBox.Right)
     {
         velocity = new Vector2(0, velocity.Y);
         position = new Vector2(position.X - (float)collisionRect.Width, position.Y);
         return true;
     }
     return false;
 }
예제 #5
0
 /// <summary>
 /// Handles collision logic for right collision.
 /// This method can be overwritten to apply additional logic
 /// to happen.
 /// </summary>
 /// <param name="otherObj">the other object</param>
 /// <returns>true if it was a collision, false otherwise</returns>
 public virtual bool CollisionBottom(Collideable otherObj)
 {
     Rectangle collisionRect = Rectangle.Intersect(CollisionBox(), otherObj.CollisionBox());
     //check otherObj's Top side
     if (otherObj.CollisionBox().Top < CollisionBox().Bottom
         && otherObj.CollisionBox().Top >= prevDestinationBox.Bottom)
     {
         position = new Vector2(position.X, (float)otherObj.CollisionBox().Top - destinationBox.Height);
         velocity = new Vector2(velocity.X, 0);
         inAir = false;
         return true;
     }
     return false;
 }
예제 #6
0
 public bool CollisionLeft(Collideable otherObj)
 {
     Rectangle collisionRect = Rectangle.Intersect(destinationBox, otherObj.CollisionBox());
     // Check otherObj's right side.
     if (otherObj.CollisionBox().Right > CollisionBox().Left
         && otherObj.CollisionBox().Right <= prevDestinationBox.Left)
     {
         velocity = new Vector2(0, velocity.Y);
         position = new Vector2((float)collisionRect.Width + position.X, position.Y);
         return true;
     }
     return false;
 }