Example #1
0
 public void TopCollision(Collider other)
 {
     if (other is T)
     {
         Parent.Y = other.Bottom()
                    + World.SPACE_BETWEEN_THINGS;
         Parent.VerticalSpeed = 0;
     }
 }
Example #2
0
 public void Top(Collider Source, Collider target)
 {
     if (target.Parent is Block)
     {
         //TODO: - offsetY
         Source.Parent.Position.Y = target.Bottom() + target.Height + 1;
         Source.Parent.Velocity.Y = 0;
     }
 }
Example #3
0
 public static void IsCollidingVertically(
     this Collider a,
     Collider b)
 {
     if (a.Left() <= b.Right() &&
         b.Left() <= a.Right() &&
         a.Top() <= b.Bottom() &&
         b.Top() <= a.Bottom())
     {
         if (a.Bottom() - b.Bottom() > 0)
         {
             a.Collision.Collide(a, CollisionDirection.Top, b);
         }
         else if (a.Bottom() - b.Bottom() < 0)
         {
             a.Collision.Collide(a, CollisionDirection.Bot, b);
         }
     }
 }
Example #4
0
        public void Collide(Collider Source, CollisionDirection direction, Collider Target)
        {
            if (Target.Parent is Block == false)
            {
                return;
            }

            if (direction == CollisionDirection.Bot)
            {
                var newY = Target.Top() - Source.Height - Source.OffsetY - 1;
                //var diff = newY - Source.Parent.Position.Y;
                //if (diff > Target.Height || diff < -Target.Height)
                //    return;

                Source.Parent.Position.Y = newY;
                Source.Parent.Velocity.Y = 0;
                return;
            }

            if (direction == CollisionDirection.Top)
            {
                var newY = Target.Bottom() - Source.OffsetY + 1;
                //var diff = newY - Source.Parent.Position.Y;
                //if (diff > Target.Height || diff < -Target.Height)
                //    return;

                Source.Parent.Position.Y = newY;
                Source.Parent.Velocity.Y = 0;
                return;
            }

            if (direction == CollisionDirection.Left)
            {
                var newX = Target.Right() - Source.OffsetX + 1;
                //var diff = newX - Source.Parent.Position.X;
                //if (diff > Target.Width || diff < -Target.Width)
                //    return;

                Source.Parent.Position.X = newX;
                Source.Parent.Velocity.X = 0;
                return;
            }

            if (direction == CollisionDirection.Right)
            {
                var newX = Target.Left() - Source.OffsetX - Source.Width - 1;
                //var diff = newX - Source.Parent.Position.X;
                //if (diff > Target.Width || diff < -Target.Width)
                //    return;

                Source.Parent.Position.X = newX;
                Source.Parent.Velocity.X = 0;
                return;
            }
        }
Example #5
0
 public static void IsCollidingV(
     this Collider a,
     Collider b)
 {
     if (a.Left() <= b.Right() &&
         b.Left() <= a.Right() &&
         a.Top() <= b.Bottom() &&
         b.Top() <= a.Bottom())
     {
         if (a.Bottom() - b.Bottom() > 0)
         {
             a.Collision.Top(a, b);
             //b.Collision.Bot(b,a);
         }
         else if (a.Bottom() - b.Bottom() < 0)
         {
             a.Collision.Bot(a, b);
             //b.Collision.Top(b,a);
         }
     }
 }
Example #6
0
 private static void Top(Collider Source, Collider target)
 {
     if (target.Parent.Identifier == Identifier.Block)
     {
         //TODO: - offsetY
         Source.Parent.Position.Y =
             target.Bottom()
             - Source.Area.Y
             + 1;
         //Source.Parent.Velocity.Y = 0;
     }
 }
Example #7
0
 public static void IsCollidingH(
     this Collider a,
     Collider b)
 {
     if (a.Left() <= b.Right() &&
         b.Left() <= a.Right() &&
         a.Top() <= b.Bottom() &&
         b.Top() <= a.Bottom())
     {
         if (a.Right() - b.Right() > 0)
         {
             a.Handler.Left(a, b);
             b.Handler.Right(b, a);
         }
         else if (a.Right() - b.Right() < 0)
         {
             a.Handler.Right(a, b);
             b.Handler.Left(b, a);
         }
     }
 }
Example #8
0
 public static float CenterY(this Collider collider)
 {
     return((collider.Top() + collider.Bottom()) * 0.5f);
 }
Example #9
0
 public static int CenterY(this Collider collider) => (collider.Top() + collider.Bottom()) / 2;