public void Add(Entity entity) { float pxHalfWidth = pxBounds.Width / 2.0f; float pxHalfHeight = pxBounds.Height / 2.0f; if ((IsLeafNode && Entities.Count < QuadTree.EntityLimit) || pxHalfWidth <= QuadTree.pxTileWidth || pxHalfHeight <= QuadTree.pxTileHeight) { if(!Entities.Contains(entity)) Entities.Add(entity); return; } if (IsLeafNode) { ChildNode1 = QuadTree.GetQuadTreeNode( pxBounds.X, pxBounds.Y, pxHalfWidth, pxHalfHeight, this); ChildNode2 = QuadTree.GetQuadTreeNode( pxBounds.X + pxHalfWidth, pxBounds.Y, pxHalfWidth, pxHalfHeight, this); ChildNode3 = QuadTree.GetQuadTreeNode( pxBounds.X, pxBounds.Y + pxHalfHeight, pxHalfWidth, pxHalfHeight, this); ChildNode4 = QuadTree.GetQuadTreeNode( pxBounds.X + pxHalfWidth, pxBounds.Y + pxHalfHeight, pxHalfWidth, pxHalfHeight, this); } // Add the entity specified in the function paramaters if (ChildNode1.Intersects(entity.CurrentBoundingBox)) ChildNode1.Add(entity); if (ChildNode2.Intersects(entity.CurrentBoundingBox)) ChildNode2.Add(entity); if (ChildNode3.Intersects(entity.CurrentBoundingBox)) ChildNode3.Add(entity); if (ChildNode4.Intersects(entity.CurrentBoundingBox)) ChildNode4.Add(entity); // Distrobute any entities found in this current Node foreach (Entity entityToAdd in this.Entities) { if (ChildNode1.Intersects(entityToAdd.CurrentBoundingBox)) ChildNode1.Add(entityToAdd); if (ChildNode2.Intersects(entityToAdd.CurrentBoundingBox)) ChildNode2.Add(entityToAdd); if (ChildNode3.Intersects(entityToAdd.CurrentBoundingBox)) ChildNode3.Add(entityToAdd); if (ChildNode4.Intersects(entityToAdd.CurrentBoundingBox)) ChildNode4.Add(entityToAdd); } Entities.Clear(); }
void MapEntrance_MapZoneHit(MapZone sender, Entity entity, TeeEngine engine, GameTime gameTime) { if(KeyboardExtensions.GetKeyDownState(Keyboard.GetState(), ACTIVATE_KEY, engine, true) && entity == engine.GetEntity("Player")) { MapEventArgs mapArgs = new MapEventArgs(); mapArgs.SetProperty("Target", Target); engine.ClearEntities(); engine.LoadMap(Destination, mapArgs); } }
public void staticObject_UpdateEvent(Entity caller, GameTime gameTime, TeeEngine engine) { caller.Opacity = 1.0f; foreach (RPGEntity entity in engine.Collider.GetIntersectingEntities<RPGEntity>(caller.CurrentBoundingBox)) { if (entity != caller && caller.Pos.Y > entity.Pos.Y && entity.CurrentBoundingBox.Intersects(caller.CurrentBoundingBox)) { caller.Opacity = 0.5f; return; } } }
void OnMapZoneHit(Entity entity, TeeEngine engine, GameTime gameTime) { if (MapZoneHit != null) MapZoneHit(this, entity, engine, gameTime); }
public void Remove(Entity Entity, FRectangle? pxBoundingBox) { List<QuadTreeNode> associations = new List<QuadTreeNode>(); GetAssociatedNodes(Entity, pxBoundingBox, ref associations); foreach (QuadTreeNode node in associations) { node.Entities.Remove(Entity); node.Validate(this); } }
// If pxBoundingBox is null, it will search everywhere public void GetAssociatedNodes(Entity entity, FRectangle? pxBoundingBox, ref List<QuadTreeNode> result) { if (IsLeafNode) { if (Entities.Contains(entity)) result.Add(this); return; } if (pxBoundingBox == null || ChildNode1.Intersects(pxBoundingBox.Value)) ChildNode1.GetAssociatedNodes(entity, pxBoundingBox, ref result); if (pxBoundingBox == null || ChildNode2.Intersects(pxBoundingBox.Value)) ChildNode2.GetAssociatedNodes(entity, pxBoundingBox, ref result); if (pxBoundingBox == null || ChildNode3.Intersects(pxBoundingBox.Value)) ChildNode3.GetAssociatedNodes(entity, pxBoundingBox, ref result); if (pxBoundingBox == null || ChildNode4.Intersects(pxBoundingBox.Value)) ChildNode4.GetAssociatedNodes(entity, pxBoundingBox, ref result); }
public bool DebugHasEntity(Entity entity) { if (IsLeafNode) return Entities.Contains(entity); else { if (ChildNode1.DebugHasEntity(entity)) return true; if (ChildNode2.DebugHasEntity(entity)) return true; if (ChildNode3.DebugHasEntity(entity)) return true; if (ChildNode4.DebugHasEntity(entity)) return true; } return false; }