Exemple #1
0
        public QuadTree(int MaxX, int MinX, int MaxY, int MinY, BouncingThing[] things)
        {
            cldMgr     = new Colliding();
            cells      = new Cell[16];
            objects    = things;
            corners    = new int[4];
            corners[0] = MaxX;
            corners[1] = MinX;
            corners[2] = MaxY;
            corners[3] = MinY;
            int max = things.Length;

            objA = new BouncingThing[max];
            objB = new BouncingThing[max];
            objC = new BouncingThing[max];
            objD = new BouncingThing[max];

            for (int i = 0; i < max; i++)
            {
                objA[i] = new BouncingThing();
                objB[i] = new BouncingThing();
                objC[i] = new BouncingThing();
                objD[i] = new BouncingThing();
            }
        }
Exemple #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here


            graphics.SynchronizeWithVerticalRetrace = false;


            frameRate    = 0;
            frameCount   = 0;
            frameTime    = 0;
            CollisionMgr = new Colliding();
            device       = graphics.GraphicsDevice;

            boundaries     = new int[4];
            count          = new int[4];
            bouncingThings = new BouncingThing[ELEMENTS];

            Vector2 pos  = new Vector2(5, 5);
            Random  rand = new Random();

            boundaries[0] = maxX = graphics.GraphicsDevice.Viewport.Width;
            boundaries[1] = minX = 0;
            boundaries[2] = maxY = graphics.GraphicsDevice.Viewport.Height;
            boundaries[3] = minY = 0;

            for (int i = 0; i < 20; i++)
            {
                if (i < 10)
                {
                    bouncingThings[i] = new BouncingTriangle(new Vector2(rand.Next(minX, maxX - TEXTUREWIDTH),
                                                                         rand.Next(minY, maxY - TEXTUREHEIGHT)),
                                                             new Vector2(rand.Next(-10, 10), rand.Next(-10, 10)),
                                                             rand.Next(5, 20),
                                                             new Vector2(rand.Next(5, 20), rand.Next(5, 20)));
                }
                else
                {
                    bouncingThings[i] = new BouncingBox(new Vector2(rand.Next(minX, maxX - TEXTUREWIDTH),
                                                                    rand.Next(minY, maxY - TEXTUREHEIGHT)),
                                                        new Vector2(rand.Next(-10, 10), rand.Next(-10, 10)),
                                                        rand.Next(1, 5),
                                                        new Vector2(rand.Next(5, 10), rand.Next(5, 10)));
                }
            }

            quad = new QuadTree(maxX, minX, maxY, minY, bouncingThings);

            base.Initialize();
        }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            graphics.SynchronizeWithVerticalRetrace = false;

            frameRate = 0;
            frameCount = 0;
            frameTime = 0;
            CollisionMgr = new Colliding();
            device = graphics.GraphicsDevice;

            boundaries = new int[4];
            count = new int[4];
            bouncingThings = new BouncingThing[ELEMENTS];

            Vector2 pos = new Vector2 (5,5);
            Random rand = new Random();

            boundaries[0] = maxX = graphics.GraphicsDevice.Viewport.Width;
            boundaries[1] = minX = 0;
            boundaries[2] = maxY = graphics.GraphicsDevice.Viewport.Height;
            boundaries[3] = minY = 0;

            for (int i = 0; i < 20; i++)
            {
                if (i < 10)
                {
                    bouncingThings[i] = new BouncingTriangle(new Vector2(rand.Next(minX, maxX - TEXTUREWIDTH),
                       rand.Next(minY, maxY - TEXTUREHEIGHT)),
                       new Vector2(rand.Next(-10, 10), rand.Next(-10, 10)),
                       rand.Next(5, 20),
                       new Vector2(rand.Next(5, 20), rand.Next(5, 20)));
                }
                else
                    bouncingThings[i] = new BouncingBox(new Vector2(rand.Next(minX, maxX - TEXTUREWIDTH),
                        rand.Next(minY, maxY - TEXTUREHEIGHT)),
                        new Vector2(rand.Next(-10, 10), rand.Next(-10, 10)),
                         rand.Next(1, 5),
                         new Vector2(rand.Next(5, 10), rand.Next(5, 10)));
            }

            quad = new QuadTree(maxX, minX, maxY, minY, bouncingThings);

            base.Initialize();
        }