Exemplo n.º 1
0
        //Splits the current quadrant into four sub nodes
        private void Split()
        {
            //Gets the dimensions of the new nodes
            int subWidth = (int)(width / 2);
            int subHeight = (int)(height / 2);

            //Declares the bounderies of the nodes
            nodes[0] = new QuadTree(level + 1, new Point(topLeftCorner.X + subWidth, topLeftCorner.Y), subWidth, subHeight);
            nodes[1] = new QuadTree(level + 1, topLeftCorner, subWidth, subHeight);
            nodes[2] = new QuadTree(level + 1, new Point(topLeftCorner.X, topLeftCorner.Y + subHeight), subWidth, subHeight);
            nodes[3] = new QuadTree(level + 1, new Point(topLeftCorner.X + subWidth, topLeftCorner.Y + subHeight), subWidth, subHeight);
        }
Exemplo n.º 2
0
        public MainGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            IsMouseVisible = true;

            graphics.PreferredBackBufferWidth = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width;
            graphics.PreferredBackBufferHeight = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();

            //Gets the user's screen width and height, also creates the game fullscreen.
            scale = new Vector2((float)GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width / optimalWidth, (float)GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / optimalHeight);

            spaceLocOne = new Vector2(-810 * scale.X, -810 * scale.Y);
            spaceLocTwo = new Vector2(-810 * scale.X, -810 * scale.Y);

            quadTree = new QuadTree(1, new Point(0, 0), graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);

            bloom = new BloomComponent(this);
            Components.Add(bloom);
            bloom.Settings = new BloomSettings(null, 0.15f, 3, 1.20f, 1, 1.5f, 1);

            //Calculates the spawn point dimensions
            spawnPointsSizeX = (graphics.PreferredBackBufferWidth / 36) - 1;
            spawnPointsSizeY = (graphics.PreferredBackBufferHeight / 36) - 4;

            //Initializes the spawn points
            spawnPoints = new Vector2[spawnPointsSizeX, spawnPointsSizeY];
            for (int i = 0; i < spawnPointsSizeX; i++)
            {
                for (int j = 0; j < spawnPointsSizeY; j++)
                {
                    spawnPoints[i, j] = new Vector2(36 + i * 36, 136 + j * 36);
                }
            }
        }
Exemplo n.º 3
0
        //Retrieves all possible objects that can collide with the given object
        public List<Entity> RetrieveList(List<Entity> returnEntity, Entity e, bool searching, QuadTree quad)
        {
            //If there are more subnodes, recursively return the objects there
            if (searching)
            {
                int tempIndex = quad.GetIndex(e.BoundingRect);

                //Attempts to continue searching 
                if (tempIndex >= 0 && quad.nodes[0] != null)
                {
                    returnEntity = RetrieveList(returnEntity, e, true, quad.nodes[tempIndex]);
                }
                //Otherwise begin retrieving the list
                else
                {
                    returnEntity = RetrieveList(returnEntity, e, false, quad);
                }
            }
            else
            {
                //If there are more subnodes, recursively return the objects there
                if (quad.nodes[0] != null)
                {
                    for (int i = 0; i < 4; i++)
                    {
                        returnEntity = quad.nodes[i].RetrieveList(returnEntity, e, false, quad.nodes[i]);
                    }
                }

                //Adds all the objects in the given node
                for (int i = 0; i < quad.objects.Count; i++)
                {
                    returnEntity.Add(quad.objects[i]);
                }
            }

            return returnEntity;
        }