Beispiel #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()
        {
            // 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();
        }
Beispiel #2
0
 /// <summary>
 /// Draws a 2D sprite.
 /// </summary>
 /// <param name="sn">The scene node to draw</param>
 public void DrawSprite(SceneNode sn)
 {
     spriteBatch.Draw(sn.Sprite, sn.Rectangle, null, Color.White, sn.Rotation, Vector2.Zero,
         SpriteEffects.None, 0f);
 }
Beispiel #3
0
 public void Add(SceneNode sn)
 {
     _nodes.Add(sn);
 }