Esempio n. 1
0
 public QuadTree(int level, Rectangle bounds)
 {
     this.level = level;
     this.bounds = bounds;
     this.objects = new List<ICollidable>();
     this.nodes = new QuadTree[4];
 }
 public static bool Intersects(Rectangle rectA, Rectangle rectB)
 {
     return rectA.TopLeft.X < rectB.BottomRight.X &&
         rectA.BottomRight.X > rectB.TopLeft.X &&
         rectA.TopLeft.Y < rectB.BottomRight.Y &&
         rectA.BottomRight.Y > rectB.TopLeft.Y;
 }
Esempio n. 3
0
 public Engine()
 {
     this.objects = new List<EnvironmentObject>();
     this.consoleRenderer = new ConsoleRenderer(WorldWidth, WorldHeight);
     this.objectGenerator = new ObjectGenerator(WorldWidth, WorldHeight);
     this.worldBounds = new Rectangle(0, 0, WorldWidth, WorldHeight);
     CollisionHandler.Initlialize(WorldWidth, WorldHeight);
 }
Esempio n. 4
0
        /*
         * Return all objects that could collide with the given object
         */
        public List<ICollidable> GetItemsInRange(List<ICollidable> returnObjects, Rectangle bounds)
        {
            int index = this.GetIndex(bounds);
            if (index != -1 && this.nodes[0] != null)
            {
                this.nodes[index].GetItemsInRange(returnObjects, bounds);
            }

            returnObjects.AddRange(this.objects);

            return returnObjects;
        }
Esempio n. 5
0
        public Engine(int worldWidth, 
            int worldHeight, 
            IObjectGenerator<EnvironmentObject> objectGenerator,
            ICollisionHandler collisionHandler, 
            IRenderer renderer)
        {
            this.objects = new List<EnvironmentObject>();
            this.objectGenerator = objectGenerator;

            this.renderer = renderer;
            this.collisionHandler = collisionHandler;
            this.worldBounds = new Rectangle(0, 0, worldWidth, worldHeight);
        }
Esempio n. 6
0
 protected EnvironmentObject(Rectangle bounds)
 {
     this.Bounds = bounds;
     this.Exists = true;
 }
Esempio n. 7
0
 public Snow(Rectangle rect)
     : base(rect)
 {
     this.ImageProfile = new char[,] { { '.' } };
     this.CollisionGroup = CollisionGroup.Snow;
 }
Esempio n. 8
0
        /*
         * Determine which node the object belongs to. -1 means
         * object cannot completely fit within a child node and is part
         * of the parent node
         */
        private int GetIndex(Rectangle pRect)
        {
            int index = -1;
            double verticalMidpoint = this.bounds.TopLeft.X + (this.bounds.Width / 2);
            double horizontalMidpoint = this.bounds.TopLeft.Y + (this.bounds.Height / 2);

            // Object can completely fit within the top quadrants
            bool withinTopQuadrant = pRect.TopLeft.Y < horizontalMidpoint && pRect.TopLeft.Y + pRect.Height < horizontalMidpoint;
            // Object can completely fit within the bottom quadrants
            bool withinBottomQuadrant = pRect.TopLeft.Y > horizontalMidpoint;

            // Object can completely fit within the left quadrants
            if (pRect.TopLeft.X < verticalMidpoint && pRect.TopLeft.X + pRect.Width < verticalMidpoint)
            {
                if (withinTopQuadrant)
                {
                    index = 1;
                }
                else if (withinBottomQuadrant)
                {
                    index = 2;
                }
            }
            // Object can completely fit within the right quadrants
            else if (pRect.TopLeft.X > verticalMidpoint)
            {
                if (withinTopQuadrant)
                {
                    index = 0;
                }
                else if (withinBottomQuadrant)
                {
                    index = 3;
                }
            }

            return index;
        }
 public Stars(Rectangle bounds)
     : base(bounds)
 {
 }