Exemple #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;
 }
Exemple #3
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;
        }
        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);
        }
Exemple #5
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 Explosion(Rectangle bounds)
     : base(bounds)
 {
 }
 protected EnvironmentObject(Rectangle bounds)
 {
     this.Bounds = bounds;
     this.Exists = true;
 }
 public Snow(Rectangle bounds)
     : base(bounds)
 {
 }
Exemple #9
0
 public Star(Rectangle bounds) : base(bounds)
 {
 }
 public Tail(Rectangle bounds)
     : base(bounds)
 {
 }
 public Snow(Rectangle rect)
     : base(rect)
 {
     this.ImageProfile = new char[,] { { '.' } };
     this.CollisionGroup = CollisionGroup.Snow;
 }
 public MeltedSnow(Rectangle bounds)
     : base(bounds)
 {
 }
Exemple #13
0
 public Snow(Rectangle rect)
     : base(rect)
 {
     this.ImageProfile = this.GenerateImageProfile();
     this.CollisionGroup = CollisionGroup.Snow;
 }