Example #1
0
        public void RemoveFromCollisions(Sprite d)
        {
            Remove(d);
            SortedList <Point, List <Sprite> > list = d.Static ? allStatic : perTile;

            if (list == null)
            {
                SortForCollisions();
                return;
            }
            TileEnumerator te = new TileEnumerator(new RectangleF(d.X, d.Y, d.Width, d.Height));

            do
            {
                if (list.ContainsKey(te.Current))
                {
                    list[te.Current].Remove(d);
                }
            } while (te.MoveNext());
            if (d.MultiplePositions)
            {
                for (int i = 0; i < d.Offsets.Count; i++)
                {
                    te = new TileEnumerator(new RectangleF(d.X + d.Offsets[i].X, d.Y + d.Offsets[i].Y, d.Width, d.Height));
                    do
                    {
                        if (list.ContainsKey(te.Current))
                        {
                            list[te.Current].Remove(d);
                        }
                    } while (te.MoveNext());
                }
            }
        }
Example #2
0
        public List <Sprite> GetPotentialColliders(float x, float y, float w = 8, float h = 8)
        {
            if (perTile == null)
            {
                SortForCollisions();
            }

            List <Sprite> colliders = new List <Sprite>();

            SortedList <Point, List <Sprite> > lookIn = perTile;
            TileEnumerator te = new TileEnumerator(new RectangleF(x, y, w, h));

            for (int i = 0; i < 2; i++)
            {
                do
                {
                    if (lookIn.ContainsKey(te.Current))
                    {
                        colliders.AddRange(lookIn[te.Current].Where((item) => !colliders.Contains(item)));
                    }
                } while (te.MoveNext());
                te.Reset();
                lookIn = allStatic;
            }
            return(colliders);
        }
Example #3
0
 private void SortInto(SortedList <Point, List <Sprite> > into, List <Sprite> toSort)
 {
     for (int i1 = 0; i1 < toSort.Count; i1++)
     {
         Sprite         d  = toSort[i1];
         TileEnumerator te = new TileEnumerator(new RectangleF(d.X, d.Y, d.Width, d.Height));
         do
         {
             if (!into.ContainsKey(te.Current))
             {
                 into.Add(te.Current, new List <Sprite>());
             }
             into[te.Current].Add(d);
         } while (te.MoveNext());
         if (d.MultiplePositions)
         {
             for (int i = 0; i < d.Offsets.Count; i++)
             {
                 te = new TileEnumerator(new RectangleF(d.X + d.Offsets[i].X, d.Y + d.Offsets[i].Y, d.Width, d.Height));
                 do
                 {
                     if (!into.ContainsKey(te.Current))
                     {
                         into.Add(te.Current, new List <Sprite>());
                     }
                     into[te.Current].Add(d);
                 } while (te.MoveNext());
             }
         }
     }
 }
Example #4
0
            public bool MoveNext()
            {
                while (true)
                {
                    while (_entryEnum == null || !_entryEnum.MoveNext())
                    {
                        if (!_tileEnum.MoveNext())
                        {
                            return(false);
                        }

                        BoxTile tile = Assert.NotNull(_tileEnum.Current);

                        _entryEnum = _tree.GetTileEnumerator(this, tile.EnumElems());
                    }

                    if (_searchBox == null)
                    {
                        return(true);
                    }

                    if (Assert.NotNull(Current).Box.Intersects(_searchBox))
                    {
                        return(true);
                    }
                }
            }
Example #5
0
        public List <Sprite> GetPotentialColliders(Sprite d)
        {
            List <Sprite> colliders = new List <Sprite>();

            if (perTile is null)
            {
                SortForCollisions();
            }

            SortedList <Point, List <Sprite> > lookIn = perTile;
            TileEnumerator te = new TileEnumerator(new RectangleF(d.X, d.Y, d.Width, d.Height));

            for (int i2 = 0; i2 < 2; i2++)
            {
                do
                {
                    if (lookIn.ContainsKey(te.Current))
                    {
                        colliders.AddRange(lookIn[te.Current].Where((item) => item != d && !colliders.Contains(item)));
                    }
                } while (te.MoveNext());
                if (d.MultiplePositions)
                {
                    for (int i = 0; i < d.Offsets.Count; i++)
                    {
                        te = new TileEnumerator(new RectangleF(d.X + d.Offsets[i].X, d.Y + d.Offsets[i].Y, d.Width, d.Height));
                        do
                        {
                            if (lookIn.ContainsKey(te.Current))
                            {
                                colliders.AddRange(lookIn[te.Current].Where((item) => item != d && !colliders.Contains(item)));
                            }
                        } while (te.MoveNext());
                    }
                }
                te     = new TileEnumerator(new RectangleF(d.X, d.Y, d.Width, d.Height));
                lookIn = allStatic;
            }


            return(colliders);
        }