Exemple #1
0
 public static List<Entity> All(Collider a, List<Entity> b, List<Entity> into, Vector2 aPos)
 {
     Vector2 old = a.Position;
     a.Position = aPos;
     List<Entity> ret = All(a, b, into);
     a.Position = old;
     return ret;
 }
Exemple #2
0
        public static List<Entity> All(Collider a, List<Entity> b, List<Entity> into)
        {
            foreach (var e in b)
            {
                if (a.Collide(e))
                    into.Add(e);
            }

            return into;
        }
        private void DisplayBounds(Collider c, int bx, int by, int bw, int bh, Color color)
        {
            Rectangle rect;

            rect.Width  = 1;
            rect.Height = 1;
            for (int x = bx; x < bx + bw; x++)
            {
                rect.X = x;
                for (int y = by; y < by + bh; y++)
                {
                    rect.Y = y;
                    if (c.Collide(rect))
                    {
                        Draw.SpriteBatch.Draw(Draw.Pixel.Texture.Texture, rect, Draw.Pixel.ClipRect, color);
                        break;
                    }
                }
                for (int y = by + bh - 1; y >= by; y--)
                {
                    rect.Y = y;
                    if (c.Collide(rect))
                    {
                        Draw.SpriteBatch.Draw(Draw.Pixel.Texture.Texture, rect, Draw.Pixel.ClipRect, color);
                        break;
                    }
                }
            }
            for (int y = by; y < by + bh; y++)
            {
                rect.Y = y;
                for (int x = bx; x < bx + bw; x++)
                {
                    rect.X = x;
                    if (c.Collide(rect))
                    {
                        Draw.SpriteBatch.Draw(Draw.Pixel.Texture.Texture, rect, Draw.Pixel.ClipRect, color);
                        break;
                    }
                }
                for (int x = bx + bw - 1; x > bx; x--)
                {
                    rect.X = x;
                    if (c.Collide(rect))
                    {
                        Draw.SpriteBatch.Draw(Draw.Pixel.Texture.Texture, rect, Draw.Pixel.ClipRect, color);
                        break;
                    }
                }
            }
        }
Exemple #4
0
        public override void Update()
        {
            base.Update();

            //if ((this.sprite.CurrentAnimID == "normal") && (hasArrow))
            //	this.sprite.Play("happy", false);

            if (this.Collidable)
            {
                Monocle.Collider collider = base.Collider;
                base.Collider = collider;
                base.Collider = this.arrowPickupHitbox;
                Monocle.Entity entity = base.CollideFirst(Monocle.GameTags.Arrow);
                if ((entity != null) && (entity as Arrow))
                {
                    ((MyArrow)entity).OnGhostCollect(this, false);
                }
                base.Collider = collider;
            }
        }
Exemple #5
0
 public static List<Entity> All(Collider a, List<Entity> b, Vector2 aPos)
 {
     return All(a, b, new List<Entity>(), aPos);
 }
Exemple #6
0
 public static List<Entity> All(Collider a, List<Entity> b)
 {
     return All(a, b, new List<Entity>());
 }
Exemple #7
0
 public static List<Entity> All(Collider a, List<Entity> b, List<Entity> into, float aX, float aY)
 {
     return All(a, b, into, new Vector2(aX, aY));
 }
Exemple #8
0
        public override Collider Clone()
        {
            Collider[] clones = new Collider[colliders.Length];
            for (int i = 0; i < colliders.Length; i++)
                clones[i] = colliders[i].Clone();

            return new ColliderList(clones);
        }
 public bool Collide(Collider collider)
 {
     if (collider is Hitbox)
     {
         return Collide(collider as Hitbox);
     }
     else if (collider is Grid)
     {
         return Collide(collider as Grid);
     }
     else if (collider is ColliderList)
     {
         return Collide(collider as ColliderList);
     }
     else if (collider is Circle)
     {
         return Collide(collider as Circle);
     }
     else
         throw new Exception("Collisions against the collider type are not implemented!");
 }
Exemple #10
0
        public static Entity First(Collider a, List<Entity> b)
        {
            foreach (var e in b)
            {
                if (a.Collide(e))
                    return e;
            }

            return null;
        }
Exemple #11
0
 public static bool Check(Collider a, List<Entity> b, float aX, float aY)
 {
     return Check(a, b, new Vector2(aX, aY));
 }
Exemple #12
0
 public static bool Check(Collider a, List<Entity> b, Vector2 aPos)
 {
     Vector2 old = a.Position;
     a.Position = aPos;
     bool ret = Check(a, b);
     a.Position = old;
     return ret;
 }
Exemple #13
0
        public static bool Check(Collider a, List<Entity> b)
        {
            foreach (var e in b)
            {
                if (a.Collide(e))
                    return true;
            }

            return false;
        }
Exemple #14
0
        public void Remove(params Collider[] toRemove)
        {
            #if DEBUG
            foreach (var c in toRemove)
            {
                if (!colliders.Contains(c))
                    throw new Exception("Removing a Collider from a ColliderList that does not contain it!");
                else if (c == null)
                    throw new Exception("Cannot remove a null Collider from a ColliderList.");
            }
            #endif

            Collider[] newColliders = new Collider[colliders.Length - toRemove.Length];
            int at = 0;
            foreach (var c in colliders)
            {
                if (!toRemove.Contains(c))
                {
                    newColliders[at] = c;
                    at++;
                }
            }
            colliders = newColliders;
        }
Exemple #15
0
 public static List<Entity> All(Collider a, List<Entity> b, float aX, float aY)
 {
     return All(a, b, new List<Entity>(), aX, aY);
 }
Exemple #16
0
 public static Entity First(Collider a, List<Entity> b, Vector2 aPos)
 {
     Vector2 old = a.Position;
     a.Position = aPos;
     Entity ret = First(a, b);
     a.Position = old;
     return ret;
 }
Exemple #17
0
 public static Entity First(Collider a, List<Entity> b, float aX, float aY)
 {
     return First(a, b, new Vector2(aX, aY));
 }
Exemple #18
0
 public static void Rect(Collider collider, Color color)
 {
     Rect(collider.AbsoluteLeft, collider.AbsoluteTop, collider.Width, collider.Height, color);
 }
Exemple #19
0
        public void Add(params Collider[] toAdd)
        {
            #if DEBUG
            foreach (var c in toAdd)
            {
                if (colliders.Contains(c))
                    throw new Exception("Adding a Collider to a ColliderList that already contains it!");
                else if (c == null)
                    throw new Exception("Cannot add a null Collider to a ColliderList.");
            }
            #endif

            Collider[] newColliders = new Collider[colliders.Length + toAdd.Length];
            for (int i = 0; i < colliders.Length; i++)
                newColliders[i] = colliders[i];
            for (int i = 0; i < toAdd.Length; i++)
            {
                newColliders[i + colliders.Length] = toAdd[i];
                toAdd[i].Added(Entity);
            }
            colliders = newColliders;
        }