From ced3d03bdb3ce866d832e03fb212865140905a9a Mon Sep 17 00:00:00 2001 From: Thomas Leyh Date: Sun, 24 Jul 2016 08:14:18 +0200 Subject: Add project files. --- V3/Quadtree.cs | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 V3/Quadtree.cs (limited to 'V3/Quadtree.cs') diff --git a/V3/Quadtree.cs b/V3/Quadtree.cs new file mode 100644 index 0000000..dfc088f --- /dev/null +++ b/V3/Quadtree.cs @@ -0,0 +1,87 @@ +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; } + } +} -- cgit v1.2.1