예제 #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

            base.Initialize();

            m_exit = false;
            m_deltaTime = 0;            

            m_score = 0;

            m_stateMangr.Init(this);

            gameConfig = new Config();

            gameConfig.Init(this, spriteBatch, m_actorList, m_actorListSplash);

            //check start state
            if (gameConfig.m_firstState == "game")
            {
                GameStateMainGame newGame = new GameStateMainGame();
                //boot up the main game!
                m_stateMangr.Cmd("game", StateManager.cmds.PUSH, newGame);

                //centre the camera
                m_cam.Pos = new Vector2(m_screenWidth / 2, m_screenHeight / 2);
            }
            else
            {
                GameStateSplash newSplash = new GameStateSplash();
                //boot up the splash screen!
                m_stateMangr.Cmd("splash", StateManager.cmds.PUSH, newSplash);
                m_cam.Pos = new Vector2(m_screenWidth / 2, m_screenHeight / 2);
            }
        }
        public override void Update(float a_dt)
        {
            if (m_runCount > 10)
            {
                //make sure the spritebactch has been called on the draw string, it seems to lag behind
                //draw sprite... 
                int getNewIndex = ldrBrd.SearchForNewHighScoreIndex(m_game.m_score); //debug test for this score                
                String name = Console.ReadLine();
                ldrBrd.AddNewHighScore(m_game.m_score, name, getNewIndex);                           

                //pop this state to return to game over state
                m_game.m_stateMangr.Cmd("addScore", StateManager.cmds.POP, this);
            }
            else
            {
                m_runCount++;                
            }
            
            //check for keyboard input
            KeyboardState myKeyboard = Keyboard.GetState();
            //check for exit game
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                m_game.m_exit = true;

            //check for space to begin game
            if (myKeyboard.IsKeyDown(Keys.Space))
            {
                GameStateMainGame newGame = new GameStateMainGame();
                //boot up the main game!
                //m_game.m_stateMangr.Cmd("game", StateManager.cmds.PUSH, newGame);
            }
        }
예제 #3
0
        public override void Update(float a_dt)
        {
            //update the splash screen actors
            //note that this is needed to have the sprites process/display
            for (int i = 0; i < m_game.m_actorListSplash.Count; i++)
            {
                m_game.m_actorListSplash[i].Update(m_game.m_deltaTime);
            }

            //check for keyboard input
            KeyboardState myKeyboard = Keyboard.GetState();
            //check for exit game
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                m_game.m_exit = true;

            //check for space to begin game
            if (myKeyboard.IsKeyDown(Keys.Space))
            {
                GameStateMainGame newGame = new GameStateMainGame();
                //boot up the main game!
                m_game.m_stateMangr.Cmd("game", StateManager.cmds.PUSH, newGame);
            }

        }
        public override void Update(float a_dt)
        {

            if (m_runOnReturn) //runs on return from add score state
            {
                //display the leaderboard and player score
                ldrBrd.Init(); //refresh the leaderboard from file
                m_userMessage = ldrBrd.DisplayLeaderBoard(); //print leaderboard to console
                m_userMessage += "Your score: " + m_game.m_score;
                m_runOnReturn = false; //don't run this again
            }


            //run once used to check if a new high score needs to be added
            if (!m_runOnce)
            {
                int getNewIndex = ldrBrd.SearchForNewHighScoreIndex(m_game.m_score); //debug test for this score
                if (getNewIndex != -1) //if the score is valid add it to the leaderboard
                {                    
                    GameStateAddScore scoreState = new GameStateAddScore();
                    m_game.m_stateMangr.Cmd("addScore", StateManager.cmds.PUSH, scoreState);
                }
                else
                {                    
                    m_userMessage = ldrBrd.DisplayLeaderBoard(); //print leaderboard to console
                    m_userMessage += "Your Score: " + m_game.m_score.ToString();
                }

                m_runOnce = true;
                m_runOnReturn = true; //make sure we update the display for the user
            }
            


            //update the splash screen actors
            //note that this is needed to have the sprites process/display
            for (int i = 0; i < m_game.m_actorListSplash.Count; i++)
            {
                m_game.m_actorListSplash[i].Update(m_game.m_deltaTime);
            }

            //check for keyboard input
            KeyboardState myKeyboard = Keyboard.GetState();
            //check for exit game
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                m_game.m_exit = true;

            //check for space to begin game
            if (myKeyboard.IsKeyDown(Keys.Space))
            {
                GameStateMainGame newGame = new GameStateMainGame();
                //boot up the main game!
                //m_game.m_stateMangr.Cmd("game", StateManager.cmds.PUSH, newGame);
            }
        }