using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using V3.Objects;
namespace V3
{
public sealed class Quadtree
{
private Node mRoot; // The first "Node" of the Quadtree
private ContentManager mContentManager;
private readonly Point mMaxSize;
///
/// Generates Quadtree
///
/// Gives the biggest/first Rectangle of the Quadtree. This should be the sice of the howl map.
public Quadtree(Point maxSize)
{
mRoot = new Node(new Rectangle(new Point(-128, -128), maxSize), null);
mMaxSize = maxSize;
}
///
/// Updates the Quadtree. This is importent for the movements of the Objects.
///
public void Update()
{
mRoot.Update1();
}
///
/// You call this method if you want to Inster an Object to the Quadtree.
///
/// Type of Creature including their position.
public void Insert(IGameObject item)
{
mRoot.AddtoSubNode(item);
}
///
/// DMakes the Rectangles of the Quadtree visible.
///
///
public void Draw(SpriteBatch spriteBatch)
{
mRoot.DrawQuadtree(spriteBatch, Texture);
}
public List GetObjectsInRectangle(Rectangle rectangle)
{
List objectList = new List();
return mRoot.GetObjectsInRectangle(rectangle, objectList);
}
///
/// Deletes an Object out of the Quadtree.
///
/// Type of Creature including their position.
public void RemoveItem(IGameObject item)
{
mRoot.Delete(item);
}
///
/// Loads the content to draw the Rectangels of the Quadtree.
///
///
public void LoadContent(ContentManager contentManager)
{
mContentManager = contentManager;
Texture = mContentManager.Load("Sprites/WhiteRectangle");
}
///
/// Deletes all elements from the quadtree.
///
public void Clear()
{
mRoot?.Clear();
mRoot = new Node(new Rectangle(new Point(-50, -50), mMaxSize), null);
}
private Texture2D Texture { get; set; }
}
}