Exemplo n.º 1
0
 public CollisionMap(byte type, int w, int h)
 {
     this.type = type;
     chunks    = new CollisionNode <T> [cW = (w + CHUNK_SIZE - 1) / CHUNK_SIZE, cH = (h + CHUNK_SIZE - 1) / CHUNK_SIZE];
     this.w    = w;
     this.h    = h;
 }
Exemplo n.º 2
0
        public void InsertAfter(CollisionNode <T> node)
        {
            if (Next != null)
            {
                node.Next     = Next;
                Next.Previous = node;
            }
            else
            {
                node.Next = null;
            }

            node.Previous = this;
            Next          = node;
        }
Exemplo n.º 3
0
        public IEnumerable <T> HitTest(double _x, double _y)
        {
            if (_x < 0 || _x >= w || _y <= 0 || _y >= h)
            {
                yield break;
            }
            int x = (int)_x / CHUNK_SIZE;
            int y = (int)_y / CHUNK_SIZE;
            CollisionNode <T> node = chunks[x, y];

            while (node != null)
            {
                yield return((T)node.Parent);

                node = node.Next;
            }
        }
Exemplo n.º 4
0
        public CollisionNode <T> Remove()
        {
            CollisionNode <T> ret = null;

            if (Previous != null)
            {
                ret           = Previous;
                Previous.Next = Next;
            }
            if (Next != null)
            {
                ret           = Next;
                Next.Previous = Previous;
            }
            Previous = null;
            Next     = null;
            return(ret);
        }
Exemplo n.º 5
0
        public CollisionNode <T> Remove()
        {
            CollisionNode <T> ret = null;

            if (this.Previous != null)
            {
                ret = this.Previous;
                this.Previous.Next = this.Next;
            }
            if (this.Next != null)
            {
                ret = this.Next;
                this.Next.Previous = this.Previous;
            }
            this.Previous = null;
            this.Next     = null;
            return(ret);
        }
Exemplo n.º 6
0
        public IEnumerable <T> HitTest(double _x, double _y, float radius)
        {
            int xl = Math.Max(0, (int)(_x - radius) / CHUNK_SIZE);
            int xh = Math.Min(cW - 1, (int)(_x + radius) / CHUNK_SIZE);
            int yl = Math.Max(0, (int)(_y - radius) / CHUNK_SIZE);
            int yh = Math.Min(cH - 1, (int)(_y + radius) / CHUNK_SIZE);

            for (int y = yl; y <= yh; y++)
            {
                for (int x = xl; x <= xh; x++)
                {
                    CollisionNode <T> node = chunks[x, y];
                    while (node != null)
                    {
                        yield return((T)node.Parent);

                        node = node.Next;
                    }
                }
            }
        }
Exemplo n.º 7
0
        public IEnumerable <T> GetActiveChunks(CollisionMap <T> from)
        {
            if (from.w != w || from.h != h)
            {
                throw new ArgumentException("from");
            }

            var ret = new HashSet <T>();

            for (int y = 0; y < cH; y++)
            {
                for (int x = 0; x < cW; x++)
                {
                    if (from.chunks[x, y] != null)
                    {
                        for (int i = -ACTIVE_RADIUS; i <= ACTIVE_RADIUS; i++)
                        {
                            for (int j = -ACTIVE_RADIUS; j <= ACTIVE_RADIUS; j++)
                            {
                                if (x + j < 0 || x + j >= cW || y + i < 0 || y + i >= cH)
                                {
                                    continue;
                                }
                                CollisionNode <T> node = chunks[x + j, y + i];
                                while (node != null)
                                {
                                    ret.Add((T)node.Parent);
                                    node = node.Next;
                                }
                            }
                        }
                    }
                }
            }

            return(ret);
        }