Esempio n. 1
0
        public override void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            currentLevelTime = currentLevelStopTime.Subtract(DateTime.Now);
            if (currentLevelTime.Seconds < 0)
            {
                currentLevelTime = TimeSpan.Zero;
            }

            if (Input.WasPressed(0, Buttons.Back, Keys.Escape))
            {
                storedTime = currentLevelTime;
                GameManager.PushState(OurGame.StartMenuState.Value);
            }

            if (Input.WasPressed(0, Buttons.Start, Keys.Enter))
            {
                storedTime = currentLevelTime;
                GameManager.PushState(OurGame.PausedState.Value);
            }


            if ((Input.WasPressed(0, Buttons.A, Keys.Space)) ||
                (Input.WasPressed(0, Buttons.RightShoulder,
                                  Keys.LeftControl)) ||
                Input.GamePads[0].Triggers.Right > 0
                )
            {
                if (missileManager.AddMissile(new Vector3(
                                                  OurGame.Camera.Position.X,
                                                  OurGame.Camera.Position.Y - 1,
                                                  OurGame.Camera.Position.Z + 1
                                                  ), OurGame.Camera.Target - OurGame.Camera.Position,
                                              DateTime.Now))
                {
                    //play sound
                    //OurGame.Sound.Play("gunshot");
                }
            }

            if (enemyManager.Enabled)
            {
                UpdateEnemies(elapsed);

                while (CheckCollisions())
                {
                    //increase score if enemy was hit
                    score += 100; //100 points for each enemy
                }

                //Are we finished with this level?
                if (TotalCollisions == Levels[CurrentLevel].Enemies)
                {
                    if (currentLevelTime.Seconds > 0)
                    {
                        score += ((int)currentLevelTime.TotalSeconds * 500);
                    }

                    TotalCollisions = 0;
                    currentLevel++;

                    //Are we finished with the game?
                    if (CurrentLevel == Levels.Count)
                    {
                        //You won the game!!!
                        GameManager.PushState(OurGame.WonGameState.Value);
                        currentLevel--; //reset count back
                    }
                    else
                    {
                        StartLevel();
                    }
                }
            }

            levelText   = "Level: " + ((int)(CurrentLevel + 1)).ToString();
            timeText    = "Time: " + ((int)currentLevelTime.TotalSeconds).ToString();
            enemiesText = "Enemies: " +
                          ((int)(Levels[CurrentLevel].Enemies - TotalCollisions)).ToString();
            scoreText = "Score: " + score.ToString();

            base.Update(gameTime);
        }
Esempio n. 2
0
        public override void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (Input.WasPressed(0, Buttons.Back, Keys.Escape))
                GameManager.PushState(OurGame.StartMenuState.Value);

            if (Input.WasPressed(0, Buttons.Start, Keys.Enter))
            {
                // push our paused state onto the stack
                GameManager.PushState(OurGame.PausedState.Value);
            }

            if ((Input.WasPressed(0, Buttons.A, Keys.Space)) ||
               (Input.WasPressed(0, Buttons.RightShoulder,
                    Keys.LeftControl)) ||
               Input.GamePads[0].Triggers.Right > 0
                )
            {
                if (missileManager.AddMissile(new Vector3(
                        OurGame.Camera.Position.X,
                        OurGame.Camera.Position.Y - 1,
                        OurGame.Camera.Position.Z + 1
                    ), OurGame.Camera.Target - OurGame.Camera.Position,
                    DateTime.Now))
                {
                    //play sound
                }
            }

            if (enemyManager.Enabled)
            {
                UpdateEnemies(elapsed);

                while (CheckCollisions())
                {
                    //increase score if enemy was hit
                }

                //Are we finished with this level?
                if (TotalCollisions == Levels[CurrentLevel].Enemies)
                {
                    TotalCollisions = 0;
                    currentLevel++;

                    //Are we finished with the game?
                    if (CurrentLevel == Levels.Count)
                    {
                        //You won the game!!!
                        GameManager.PushState(OurGame.WonGameState.Value);
                        currentLevel--; //reset count back
                    }
                    else
                    {
                        StartLevel();
                    }
                }
            }

            base.Update(gameTime);
        }