public override void Initilize() { base.Initilize(); camera = new Camera(); cursor = new Cursor(); background = new Background(); background.Initialize(); }
public bool Remove(GraphicalEntity entity) { bool r = entities.Remove(entity); if (!r) return false; if (quadType != QuadType.Parent) parent.TryToMerge(); return true; }
private void InsertChild(GraphicalEntity entity) { Vector2 tmp = entity.Position - position; // Top left if (tmp.X <= gridSize / 2 && tmp.Y <= gridSize / 2) { createTopLeft(); topLeft.Insert(entity); } // Top right else if (tmp.X > gridSize / 2 && tmp.Y <= gridSize / 2) { createTopRight(); topRight.Insert(entity); } // Bottom left else if (tmp.X <= gridSize / 2 && tmp.Y > gridSize / 2) { createBottomLeft(); bottomLeft.Insert(entity); } // Bottom right else { createBottomRight(); bottomRight.Insert(entity); } }
public void InsertFromTop(GraphicalEntity entity) { if (parent != null) parent.InsertFromTop(entity); else Insert(entity); }
public bool Inside(GraphicalEntity entity) { return (entity.Position.X >= boundRect.X && entity.Position.X <= boundRect.X + gridSize && entity.Position.Y >= boundRect.Y && entity.Position.Y <= boundRect.Y + gridSize); }
public bool CircularIntersects(GraphicalEntity e) { if (Vector2.Distance(this.CenterPosition, e.CenterPosition) <= this.bounds.X + e.Bounds.X) return true; return false; }
public void Insert(GraphicalEntity entity) { if (HasChildren()) InsertChild(entity); else { Vector2 tmp = entity.Position - position; if (Inside(entity)) { entities.Add(entity); entity.QuadTree = this; //Console.WriteLine(position.X + "-" + position.Y + "\t" + gridSize + "\t\tAdding entity at " + entity.Position.X + "-" + entity.Position.Y); if (entities.Count > maxCapacity) BreakNode(); } // else //Console.WriteLine(position.X + "-" + position.Y + "\t" + gridSize + "\t\tEntity outside at " + entity.Position.X + "-" + entity.Position.Y); } }
public static bool RectangularIntersects(GraphicalEntity e1, GraphicalEntity e2) { Vector2 n1 = e1.Position; Vector2 n2 = e2.position; Rectangle r1 = new Rectangle((int)n1.X, (int)n1.Y, (int)e1.Bounds.X, (int)e1.Bounds.Y); Rectangle r2 = new Rectangle((int)n2.X, (int)n2.Y, (int)e2.Bounds.X, (int)e2.Bounds.Y); return r1.Intersects(r2); }
public static bool PositionIntersect(GraphicalEntity e, Vector2 pos) { if (e.position.X < pos.X && e.position.Y < pos.Y) { if (e.bounds.X + e.position.X > pos.X && e.bounds.Y + e.position.Y > pos.Y) return true; } return false; }
public static bool IntersectsNextNext(GraphicalEntity e1, GraphicalEntity e2) { Vector2 n1 = e1.GetNextPosition(); Vector2 n2 = e2.GetNextPosition(); Rectangle r1 = new Rectangle((int)n1.X, (int)n1.Y, (int)e1.Bounds.X, (int)e1.Bounds.Y); Rectangle r2 = new Rectangle((int)n2.X, (int)n2.Y, (int)e2.Bounds.X, (int)e2.Bounds.Y); return r1.Intersects(r2); }
public static bool Intersects(GraphicalEntity e1, Rectangle r2) { Vector2 n1 = e1.Position; Rectangle r1 = new Rectangle((int)n1.X, (int)n1.Y, (int)e1.Bounds.X, (int)e1.Bounds.Y); return r1.Intersects(r2); }
public static bool CircularIntersects(GraphicalEntity e1, GraphicalEntity e2) { if (Vector2.Distance(e1.CenterPosition, e2.CenterPosition) <= (Math.Max(e1.Bounds.X, e1.Bounds.Y) + Math.Max(e2.Bounds.Y, e2.bounds.X))) return true; return false; }