Beispiel #1
0
 public QuadTree(Vector2 position, float gridSize, QuadTree parent, QuadType quadType)
 {
     this.topLeft = null;
     this.topRight = null;
     this.bottomLeft = null;
     this.bottomRight = null;
     this.position = position;
     this.gridSize = gridSize;
     this.parent = parent;
     this.entities = new List<GraphicalEntity>();
     this.quadType = quadType;
     this.boundRect = new Rectangle((int)position.X, (int)position.Y, (int)gridSize, (int)gridSize);
 }
Beispiel #2
0
 private void createTopRight()
 {
     if (topRight == null)
         topRight = new QuadTree(position + new Vector2(gridSize / 2, 0), gridSize / 2, this, QuadType.TopRight);
 }
Beispiel #3
0
 private void createBottomRight()
 {
     if (bottomRight == null)
         bottomRight = new QuadTree(position + new Vector2(gridSize / 2, gridSize / 2), gridSize / 2, this, QuadType.BottomRight);
 }
Beispiel #4
0
 private void createTopLeft()
 {
     if (topLeft == null)
         topLeft = new QuadTree(position, gridSize / 2, this, QuadType.TopLeft);
 }
Beispiel #5
0
        public void RemoveChildren()
        {
            if (topLeft != null)
            {
                if (topLeft.HasChildren())
                    topLeft.RemoveChildren();
                else
                    topLeft = null;
            }

            if (topRight != null)
            {
                if (topRight.HasChildren())
                    topRight.RemoveChildren();
                else
                    topRight = null;
            }

            if (bottomLeft != null)
            {
                if (bottomLeft.HasChildren())
                    bottomLeft.RemoveChildren();
                else
                    bottomLeft = null;
            }

            if (bottomRight != null)
            {
                if (bottomRight.HasChildren())
                    bottomRight.RemoveChildren();
                else
                    bottomRight = null;
            }
        }