Beispiel #1
0
 public void LinkNeighbour(CollisionBucket bucket, bool backLink = true)
 {
     neighbours.Add(bucket);
     if (backLink)
     {
         bucket.LinkNeighbour(this, false);
     }
 }
Beispiel #2
0
        static Collision()
        {
            var bucketList = new List <CollisionBucket>();

            var maxX = (Game.MaxX / 100);
            var maxY = (Game.MaxY / 100);

            buckets = new CollisionBucket[maxX][];
            for (int x = 0; x < maxX; x++)
            {
                buckets[x] = new CollisionBucket[maxY];
                for (int y = 0; y < maxY; y++)
                {
                    buckets[x][y] = new CollisionBucket();
                    bucketList.Add(buckets[x][y]);
                }
            }

            for (int x = 0; x < maxX; x++)
            {
                for (int y = 0; y < maxY; y++)
                {
                    var xMin1  = (x - 1 + maxX) % maxX;
                    var xPlus1 = (x + 1 + maxX) % maxX;
                    var yMin1  = (y - 1 + maxY) % maxY;
                    var yPlus1 = (y + 1 + maxY) % maxY;

                    //top
                    buckets[x][y].LinkNeighbour(buckets[x][yMin1]);

                    //left
                    buckets[x][y].LinkNeighbour(buckets[xMin1][y]);

                    //topright
                    buckets[x][y].LinkNeighbour(buckets[xPlus1][yMin1]);

                    //topleft
                    buckets[x][y].LinkNeighbour(buckets[xMin1][yMin1]);
                }
            }

            allBuckets = bucketList.ToArray();
        }