예제 #1
0
        public void Update(double elapsedTime)
        {
            _level.Update(elapsedTime, _gameTime);
            _gameTime -= elapsedTime;

            if (_gameTime <= 0)
            {
                OnGameStart();
                _gameData.JustWon = true;
                _system.ChangeState("game_over");
            }

            if (_level.HasPlayerDied())
            {
                OnGameStart();
                _gameData.JustWon = false;
                _system.ChangeState("game_over");
            }
        }
예제 #2
0
        public void Update(double elapsedTime)
        {
            _lvlTitleTime -= elapsedTime;

            if (_lvlTitleTime < 0)
            {
                _gameTime += elapsedTime;
                _level.Update(elapsedTime, _gameTime);
                _score.Update(_gameData.Score);
                _lives.Update(_gameData.Lives);

                //if (_gameTime < 0)
                if (_level.Finished)
                {
                    if (_gameData.CurrentLevel.NextLevel != null && _gameData.CurrentLevel.NextLevel != string.Empty)
                    {
                        _gameData.NewGame      = false;
                        _gameData.CurrentLevel = _levelManager.Load(_gameData.CurrentLevel.NextLevel);
                    }
                    else
                    {
                        _gameData.JustWon      = true;
                        _gameData.NewGame      = true;
                        _gameData.CurrentLevel = _levelManager.Load("Level_1");
                        UpdateHighScore(_gameData.Score);
                        _system.ChangeState("game_over");
                    }

                    OnGameStart();
                }

                if (_level.HasPlayerDied())
                {
                    _gameData.JustWon      = false;
                    _gameData.NewGame      = true;
                    _gameData.CurrentLevel = _levelManager.Load("Level_1");
                    OnGameStart();
                    _system.ChangeState("game_over");
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            KeyboardState keyboard = Keyboard.GetState();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || (keyboard.IsKeyDown(Keys.Escape)))
            {
                this.Exit();
            }
            if (Player.m_lifes == 0)
            {
                gameOver = true;
            }

            if (!GameValues.Instance.gamePaused)
            {
                Player.Reset();

                if (Player.m_active)
                {
                    if (keyboard.IsKeyDown(Keys.P))
                    {
                        if (!GameValues.Instance.gamePaused)
                        {
                            GameValues.Instance.gamePaused = true;
                        }
                        else
                        {
                            GameValues.Instance.gamePaused = false;
                        }
                    }
                    if ((keyboard.IsKeyDown(Keys.Up)) || (keyboard.IsKeyDown(Keys.W)))
                    {
                        Player.m_up = true;
                    }
                    if ((keyboard.IsKeyDown(Keys.Down)) || (keyboard.IsKeyDown(Keys.S)))
                    {
                        Player.m_down = true;
                    }
                    if ((keyboard.IsKeyDown(Keys.Left)) || (keyboard.IsKeyDown(Keys.A)))
                    {
                        Player.m_left = true;
                    }
                    if ((keyboard.IsKeyDown(Keys.Right)) || (keyboard.IsKeyDown(Keys.D)))
                    {
                        Player.m_right = true;
                    }
                    if (keyboard.IsKeyDown(Keys.Space) || (keyboard.IsKeyDown(Keys.RightControl)))
                    {
                        Player.Fire();
                    }
                }

                // TODO: Add your update logic here
                Level.Update();
                int i = 0;
                for (i = 0; i < PlayerWeapons.Count; i++)
                {
                    if (PlayerWeapons[i].m_active)
                    {
                        PlayerWeapons[i].Update();
                    }
                }
                for (i = 0; i < GameValues.Instance.EnemyWeapons.Count; i++)
                {
                    if (GameValues.Instance.EnemyWeapons[i].m_active)
                    {
                        GameValues.Instance.EnemyWeapons[i].Update();
                    }
                }

                Player.Update();
                starField.Update();
            }

            base.Update(gameTime);
        }