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); }
private void createTopRight() { if (topRight == null) topRight = new QuadTree(position + new Vector2(gridSize / 2, 0), gridSize / 2, this, QuadType.TopRight); }
private void createBottomRight() { if (bottomRight == null) bottomRight = new QuadTree(position + new Vector2(gridSize / 2, gridSize / 2), gridSize / 2, this, QuadType.BottomRight); }
private void createTopLeft() { if (topLeft == null) topLeft = new QuadTree(position, gridSize / 2, this, QuadType.TopLeft); }
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; } }