示例#1
0
 public BasicEnemy(int xPosition, int yPosition)
 {
     currentHP = HP;
     position  = new Vector2(xPosition, yPosition);
     direction = new Vector2(-1, 0);
     speed     = 200;
     visual    = new AnimatedSprite(Renderer.Instance.enemy, 4, 4, 16, 1000, true);
     collider  = new AABBCollider((int)position.X + 6, (int)position.Y + 7, 50, 50);
 }
示例#2
0
        private static bool AABBCircle(AABBCollider a, CircleCollider c)
        {
            List <Vector2> AABBVerts = new List <Vector2>();

            AABBVerts.Add(new Vector2(0, 0));
            AABBVerts.Add(new Vector2(a.Width, 0));
            AABBVerts.Add(new Vector2(a.Width, a.Height));
            AABBVerts.Add(new Vector2(0, a.Height));
            PolygonCollider hax = new PolygonCollider(a.position.X, a.position.Y, AABBVerts);

            return(PolygonCircle(hax, c));
        }
示例#3
0
 public BugEnemy(int xPosition, int yPosition)
 {
     position  = new Vector2(xPosition, yPosition);
     currentHP = HP;
     speed     = 150;
     visual    = new AnimatedSprite(Renderer.Instance.bug, 4, 4, 16, 1000, true);
     collider  = new AABBCollider((int)position.X + 6, (int)position.Y + 2, 52, 60);
     if (Exodos.Instance.random.Next(0, 2) == 1)
     {
         direction = new Vector2(-1, 1);
     }
     else
     {
         direction = new Vector2(1, 1);
     }
     direction.Normalize();
     directionTimer = directionTime;
 }
示例#4
0
 private static bool AABBHalfPlane(AABBCollider a, HalfPlaneCollider hp)
 {
     // Check if any of the AABB's vertices satisfies the half-plane's equation.
     if (hp.A * a.position.X + hp.B * a.position.Y <= hp.C)
     {
         return(true);
     }
     if (hp.A * a.position.X + hp.B * (a.position.Y + a.Height) <= hp.C)
     {
         return(true);
     }
     if (hp.A * (a.position.X + a.Width) + hp.B * a.position.Y <= hp.C)
     {
         return(true);
     }
     if (hp.A * (a.position.X + a.Width) + hp.B * (a.position.Y + a.Height) <= hp.C)
     {
         return(true);
     }
     return(false);
 }
示例#5
0
 // Check for collision between two Axis-Aligned Bounding Boxes.
 private static bool AABB(AABBCollider a, AABBCollider b)
 {
     // This is a special case of the Separating Axis Theorem for AABBs.
     if (a.position.X > b.position.X + b.Width)
     {
         return(false);
     }
     if (a.position.X + a.Width < b.position.X)
     {
         return(false);
     }
     if (a.position.Y > b.position.Y + b.Height)
     {
         return(false);
     }
     if (a.position.Y + a.Height < b.position.Y)
     {
         return(false);
     }
     return(true);
 }
示例#6
0
        // Uses the Separating Axis Theorem, but accounts for one of the colliders being an AABB and thus described in a different way.
        private static bool AABBPolygon(AABBCollider a, PolygonCollider p)
        {
            // Get the AABB's vertices in a format suitable for GatherPolygonProjectionExtents.
            List <Vector2> AABBVerts = new List <Vector2>();

            AABBVerts.Add(new Vector2(a.position.X, a.position.Y));
            AABBVerts.Add(new Vector2(a.position.X + a.Width, a.position.Y));
            AABBVerts.Add(new Vector2(a.position.X + a.Width, a.position.Y + a.Height));
            AABBVerts.Add(new Vector2(a.position.X, a.position.Y + a.Height));

            for (int i = 0; i < p.vertices.Count; i++)
            {
                Vector2 edge;
                if (i != p.vertices.Count - 1)
                {
                    edge = p.vertices[i + 1] - p.vertices[i];
                }
                else
                {
                    edge = p.vertices[0] - p.vertices[i];
                }
                Vector2 axis = new Vector2(edge.Y, -edge.X);
                axis.Normalize();

                float aMin, aMax, bMin, bMax;
                GatherPolygonProjectionExtents(axis, p.vertices, out aMin, out aMax);
                GatherPolygonProjectionExtents(axis, AABBVerts, out bMin, out bMax);

                if (aMin > bMax)
                {
                    return(false);
                }
                if (aMax < bMin)
                {
                    return(false);
                }
            }

            for (int i = 0; i < AABBVerts.Count; i++)
            {
                Vector2 edge;
                if (i != AABBVerts.Count - 1)
                {
                    edge = AABBVerts[i + 1] - AABBVerts[i];
                }
                else
                {
                    edge = AABBVerts[0] - AABBVerts[i];
                }
                Vector2 axis = new Vector2(edge.Y, -edge.X);
                axis.Normalize();

                float aMin, aMax, bMin, bMax;
                GatherPolygonProjectionExtents(axis, p.vertices, out aMin, out aMax);
                GatherPolygonProjectionExtents(axis, AABBVerts, out bMin, out bMax);

                if (aMin > bMax)
                {
                    return(false);
                }
                if (aMax < bMin)
                {
                    return(false);
                }
            }

            return(true);
        }