Esempio n. 1
0
        public void Update(PlayerSprite player)
        {
            //Z, and X used to manipulate scale value of the camera for zooming
            if (Keyboard.GetState().IsKeyDown(Keys.Z))
            {
                if (m_scale < 1.2)
                    m_scale += 0.003f;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.X))
            {
                if (m_scale > 0.4)
                    m_scale -= 0.003f;
            }

            //C, and V used to manipulate the orientation of the camera
            if (Keyboard.GetState().IsKeyDown(Keys.C))
                m_rotation += 0.005f;

            if (Keyboard.GetState().IsKeyDown(Keys.V))
                m_rotation -= 0.005f;

            if (m_rotation >= 2.0f * (float)Math.PI || m_rotation <= -2.0f * (float)Math.PI)
                m_rotation = 0;

            m_cameraFocus = player.Center;
            //Translate once to focus position, rotate, scale, then translate again to center the camera on the focus.
            m_transform = Matrix.CreateTranslation(new Vector3(-m_cameraFocus.X, -m_cameraFocus.Y, 1.0f)) *
                            Matrix.CreateRotationZ(m_rotation) *
                            Matrix.CreateScale(new Vector3(m_scale, m_scale, 0)) *
                            Matrix.CreateTranslation(new Vector3(m_view.Width / 2, m_view.Height / 2, 0));
        }
        public void LoadContent(ContentManager content)
        {
            //init player
            m_player = new PlayerSprite(content.Load<Texture2D>("MonoGameContent/Sprites/MarioSprite"), new Vector2(0.0f, 0.0f));

            //init camera
            m_playerCamera = new PlayerCamera(Main.Instance.GraphicsDevice.Viewport, 1.0f);

            m_levelManager = new LevelManager(LevelManager.Levels.JungTown, new JungTown());

            //after everything has been loaded in, we initialize our partition trees, and send them to the current level to be populated
            m_drawTree = new QuadPartitionTree<IPartitionNode>(m_levelManager.LevelRectangle);
            m_collisionTree = new QuadPartitionTree<IPartitionNode>(m_levelManager.LevelRectangle);

            //load elements into partition trees
            PopulateTrees();

            //Set the graphics rectangle
            m_graphicsRectangle = new Rectangle((int)m_player.Center.X - VIEWPORTWIDTH, (int)m_player.Center.Y - VIEWPORTHEIGHT, VIEWPORTWIDTH * 2, VIEWPORTHEIGHT * 2);
        }