示例#1
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();
        }