public void DoUpdateCollide() { hwmBox2D collideAABB = hwmBox2D.BuildAABB(m_Head.GetPosition(), new Vector2(m_Head.Radius, m_Head.Radius)); hwmSphere2D headSphere = new hwmSphere2D(m_Head.GetPosition(), m_Properties.HeadColliderRadius); if ((slConstants.DAMAGETYPE_WALL & m_EnableDamageType) != 0 && !slWorld.GetInstance().GetMap().GetMapBox().IsInsideOrOn(m_Head.AABB)) { m_AliveState = AliveState.DeadHitWall; return; } hwmQuadtree <QuadtreeElement> .AABBEnumerator enumerator = new hwmQuadtree <QuadtreeElement> .AABBEnumerator(m_Head.OwnerQuadtree.GetRootNode() , collideAABB); while (enumerator.MoveNext()) { hwmQuadtree <QuadtreeElement> .Node iterNode = enumerator.Current; hwmBetterList <QuadtreeElement> elements = iterNode.GetElements(); for (int iElement = elements.Count - 1; iElement >= 0; iElement--) { QuadtreeElement iterElement = elements[iElement]; if ((slConstants.DAMAGETYPE_SNAKE & m_EnableDamageType) != 0 && iterElement.Owner != m_Guid && iterElement.NodeType != slConstants.NodeType.Predict && (iterElement.GetPosition() - m_Head.GetPosition()).sqrMagnitude <= ((m_Head.Radius + iterElement.Radius) * (m_Head.Radius + iterElement.Radius))) { m_AliveState = AliveState.DeadHitSnake; } } } }
// Copy constructor public Quadtree(Quadtree qt) { if (qt != null) { this.children[0] = qt.children[0]; this.children[1] = qt.children[1]; this.children[2] = qt.children[2]; this.children[3] = qt.children[3]; this.element = qt.element; } }
public Quadtree(QuadtreeElement element) { // Quadtree leaf this.element = element; }
static private Quadtree buildTree(Quadtree origin, List <Direction> directions, QuadtreeElement elem) { Quadtree qt = new Quadtree(); // set new Quadtree as node if (origin != null) { qt = origin; } // exit condition if (directions.Count == 0) { // set element as leaf qt.element = elem; return(qt); } // move in the next direction of the list and remove it from the List // if there is no quadtree object in that direction, call the recursive function with null // otherwise hand down the existing quadtree part List <Direction> newDir = new List <Direction>(directions); newDir.RemoveAt(0); switch (directions[0]) { case Direction.NorthWest: if (qt.children[0] == null) { qt.children[0] = buildTree(null, newDir, elem); } else { qt.children[0] = buildTree(qt.children[0], newDir, elem); } break; case Direction.NorthEast: if (qt.children[1] == null) { qt.children[1] = buildTree(null, newDir, elem); } else { qt.children[1] = buildTree(qt.children[1], newDir, elem); } break; case Direction.SouthEast: if (qt.children[2] == null) { qt.children[2] = buildTree(null, newDir, elem); } else { qt.children[2] = buildTree(qt.children[2], newDir, elem); } break; case Direction.SouthWest: if (qt.children[3] == null) { qt.children[3] = buildTree(null, newDir, elem); } else { qt.children[3] = buildTree(qt.children[3], newDir, elem); } break; } return(qt); }