コード例 #1
0
ファイル: Quadtree.cs プロジェクト: finaiized/sleepwalker
        /// <summary>
        /// Divide a node into four subnodes
        /// </summary>
        private void Split()
        {
            int subWidth = (bounds.Width / 2);
            int subHeight = (bounds.Height / 2);
            int x = bounds.X;
            int y = bounds.Y;

            nodes[0] = new Quadtree(level + 1, new Rectangle(x + subWidth, y, subWidth, subHeight));
            nodes[1] = new Quadtree(level + 1, new Rectangle(x, y, subWidth, subHeight));
            nodes[2] = new Quadtree(level + 1, new Rectangle(x, y + subHeight, subWidth, subHeight));
            nodes[3] = new Quadtree(level + 1, new Rectangle(x + subWidth, y + subHeight, subWidth, subHeight));
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: finaiized/sleepwalker
        /// <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()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            world = new SceneManager();
            renderer = new Renderer(spriteBatch);

            player = new Player()
            {
                Name = "Flag1",
                Position = new Vector2(300, 300),
                Sprite = Content.Load<Texture2D>("flag")
            };

            SceneNode sn2 = new SceneNode()
            {
                Name = "Flag2",
                Position = new Vector2(200, 300),
                Sprite = Content.Load<Texture2D>("flag")
            };

            SceneNode sn3 = new SceneNode()
            {
                Name = "Flag3",
                Position = new Vector2(232, 300),
                Sprite = Content.Load<Texture2D>("flag")
            };

            SceneNode sn4 = new SceneNode()
            {
                Name = "Flag4",
                Position = new Vector2(232, 332),
                Sprite = Content.Load<Texture2D>("flag")
            };

            world.Add(player);
            world.Add(sn2);
            world.Add(sn3);
            world.Add(sn4);

            for (int i = 0; i < 100; i++)
            {
                world.Add(new SceneNode
                {
                    Name = "FlagX",
                    Position = new Vector2(232 + i * 32, 332),
                    Sprite = Content.Load<Texture2D>("flag")
                });
            }

            for (int i = 0; i < 10; i++)
            {
                world.Add(new SceneNode
                {
                    Name = "FlagY" + i.ToString(),
                    Position = new Vector2(232 + 320, 332 - i * 32),
                    Sprite = Content.Load<Texture2D>("flag")
                });
            }

            List<SceneNode> sns = new List<SceneNode>(world.GetAllNodes());
            sns.Remove(player);

            cr = new CollisionResolver(sns);

            inputManager = new InputManager();

            quadTree = new Quadtree(0, new Rectangle(0, 0,
                GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height));

            inputManager.AddKeyBinding("Exit Game");
            inputManager["Exit Game"].Add(Keys.Escape);
            inputManager["Exit Game"].Add(MouseButton.Right);

            inputManager.AddKeyBinding("Move Left");
            inputManager["Move Left"].Add(Keys.Left);

            inputManager.AddKeyBinding("Move Right");
            inputManager["Move Right"].Add(Keys.Right);

            inputManager.AddKeyBinding("Move Up");
            inputManager["Move Up"].Add(Keys.Up);

            inputManager.AddKeyBinding("Move Down");
            inputManager["Move Down"].Add(Keys.Down);

            camera = new Camera2D(GraphicsDevice.Viewport);

            base.Initialize();
        }