コード例 #1
0
 private void checkShotToPlayerCollisions()
 {
     foreach (Sprite shot in enemyManager.EnemyShotManager.Shots)
     {
         if (shot.IsCircleColliding(
                 playerManager.playerSprite.Center,
                 playerManager.playerSprite.CollisionRadius))
         {
             shot.Location           = offScreen;
             playerManager.Destroyed = true;
             SoundManager.PlayPlayerDeath();
             explosionManager.AddExplosion(
                 playerManager.playerSprite.Center,
                 Vector2.Zero);
         }
     }
 }
コード例 #2
0
        private void checkEnemyToPlayerCollisions()
        {
            foreach (Enemy enemy in enemyManager.Enemies)
            {
                if (enemy.EnemySprite.IsCircleColliding(
                        playerManager.playerSprite.Center,
                        playerManager.playerSprite.CollisionRadius))
                {
                    enemy.Destroyed = true;
                    explosionManager.AddExplosion(
                        enemy.EnemySprite.Center,
                        enemy.EnemySprite.Velocity / 10);

                    playerManager.Destroyed = true;
                    SoundManager.PlayPlayerDeath();

                    explosionManager.AddExplosion(
                        playerManager.playerSprite.Center,
                        Vector2.Zero);
                }
            }
        }
コード例 #3
0
        private void checkAsteroidToPlayerCollisions()
        {
            foreach (Sprite asteroid in asteroidManager.Asteroids)
            {
                if (asteroid.IsCircleColliding(
                        playerManager.playerSprite.Center,
                        playerManager.playerSprite.CollisionRadius))
                {
                    explosionManager.AddExplosion(
                        asteroid.Center,
                        asteroid.Velocity / 10);

                    asteroid.Location = offScreen;

                    playerManager.Destroyed = true;
                    SoundManager.PlayPlayerDeath();
                    explosionManager.AddExplosion(
                        playerManager.playerSprite.Center,
                        Vector2.Zero);
                }
            }
        }
コード例 #4
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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            EffectManager.Update(gameTime);

            // TODO: Add your update logic here
            KeyboardState kb = Keyboard.GetState();

            switch (gameState)
            {
            case GameStates.TitleScreen:
                SoundManager.StopSong();
                titleScreenTimer +=
                    (float)gameTime.ElapsedGameTime.TotalSeconds;

                if (titleScreenTimer >= titleScreenDelayTime)
                {
                    if ((Keyboard.GetState().IsKeyDown(Keys.Space)) ||
                        (GamePad.GetState(PlayerIndex.One).Buttons.A ==
                         ButtonState.Pressed))
                    {
                        playerManager.LivesRemaining = playerStartingLives;
                        playerManager.PlayerScore    = 0;
                        resetGame();
                        gameState = GameStates.DifficultySelect;
                    }
                }
                break;


            case GameStates.CreditsScreen:

                if (kb.IsKeyDown(Keys.R))
                {
                    gameState = GameStates.TitleScreen;
                }

                break;

            case GameStates.Pause:
                if (kb.IsKeyDown(Keys.P))
                {
                    gameState = GameStates.Playing;
                }

                break;

            case GameStates.DifficultySelect:
                //WORK ON DIFFICULTY

                if (kb.IsKeyDown(Keys.D1))
                {
                    //CHANGING DIFFICULTY LEVEL
                    difficultyLevel = 1;
                    gameState       = GameStates.Playing;
                    //LIVES - 1, because the game includes 0 as a life.  Total lives are lives remaining + 1.  Fixed it in the display, so life 1 is your last life.
                    playerManager.LivesRemaining = 5;
                    //ENEMIES
                    enemyManager.MinShipsPerWave = 2;
                    enemyManager.MaxShipsPerWave = 4;
                    //ASTEROIDS
                    asteroidManager.minSpeed = 40;
                    asteroidManager.maxSpeed = 80;
                    //SCORES
                    collisionManager.enemyPointValue = 50;

                    for (int i = 0; i < 7; i++)
                    {
                        asteroidManager.AddAsteroid();
                    }
                }
                else if (kb.IsKeyDown(Keys.D2))
                {
                    difficultyLevel = 2;
                    gameState       = GameStates.Playing;
                    playerManager.LivesRemaining     = 2;
                    enemyManager.MinShipsPerWave     = 6;
                    enemyManager.MaxShipsPerWave     = 8;
                    asteroidManager.minSpeed         = 60;
                    asteroidManager.maxSpeed         = 120;
                    collisionManager.enemyPointValue = 100;
                    for (int i = 0; i < 10; i++)
                    {
                        asteroidManager.AddAsteroid();
                    }
                }

                else if (kb.IsKeyDown(Keys.D3))
                {
                    difficultyLevel = 3;
                    gameState       = GameStates.Playing;
                    playerManager.LivesRemaining     = 1;
                    enemyManager.MinShipsPerWave     = 12;
                    enemyManager.MaxShipsPerWave     = 16;
                    asteroidManager.minSpeed         = 100;
                    asteroidManager.maxSpeed         = 140;
                    collisionManager.enemyPointValue = 200;
                    for (int i = 0; i < 13; i++)
                    {
                        asteroidManager.AddAsteroid();
                    }
                }

                else if (kb.IsKeyDown(Keys.D4))
                {
                    difficultyLevel                  = 4;
                    playerManager.isD4               = true;
                    gameState                        = GameStates.Playing;
                    playerManager.LivesRemaining     = 0;
                    enemyManager.MinShipsPerWave     = 20;
                    enemyManager.MaxShipsPerWave     = 24;
                    asteroidManager.minSpeed         = 160;
                    asteroidManager.maxSpeed         = 220;
                    collisionManager.enemyPointValue = 400;

                    playerManager.PowerupLevel = 4;

                    for (int i = 0; i < 15; i++)
                    {
                        asteroidManager.AddAsteroid();
                    }
                }

                else if (kb.IsKeyDown(Keys.D9))     //Survival Mode.  Score = time played.  No enemies.
                {
                    difficultyLevel = 9;
                    gameState       = GameStates.Playing;
                    playerManager.LivesRemaining = 1;
                    enemyManager.MinShipsPerWave = 0;
                    enemyManager.MaxShipsPerWave = 0;
                    asteroidManager.minSpeed     = 200;
                    asteroidManager.maxSpeed     = 300;
                    playerManager.playerSpeed    = 400.0f;

                    for (int i = 0; i < 20; i++)
                    {
                        asteroidManager.AddAsteroid();
                    }
                }



                //Cheat Code Viewer
                else if (kb.IsKeyDown(Keys.D5))
                {
                    gameState = GameStates.ccViewer;
                }

                if (kb.IsKeyDown(Keys.Z))
                {
                    gameState = GameStates.CreditsScreen;
                }
                break;

            case GameStates.ccViewer:
                if (kb.IsKeyDown(Keys.R))
                {
                    gameState = GameStates.DifficultySelect;
                }

                break;

            case GameStates.Playing:

                starField.Update(gameTime);
                asteroidManager.Update(gameTime);
                playerManager.Update(gameTime);
                enemyManager.Update(gameTime);
                explosionManager.Update(gameTime);
                collisionManager.CheckCollisions();
                planetManager.Update(gameTime);

                if (playerManager.Destroyed)
                {
                    SoundManager.PlayPlayerDeath();

                    playerDeathTimer    = 0f;
                    enemyManager.Active = false;
                    playerManager.LivesRemaining--;
                    if (playerManager.LivesRemaining < 0)
                    {
                        gameState = GameStates.GameOver;
                    }
                    else
                    {
                        gameState = GameStates.PlayerDead;
                    }
                }
                //RESET FUNCTION

                if (kb.IsKeyDown(Keys.R))
                {
                    resetGame();
                    gameState = GameStates.DifficultySelect;
                    playerManager.PlayerScore = 0;
                    playerManager.playerSpeed = 320.0f;
                    playerTimePlayed          = 0f;
                    asteroidManager.Clear();
                    playerManager.PowerupLevel = 1;
                }
                //PAUSE FUNCTION
                if (kb.IsKeyDown(Keys.P))
                {
                    gameState = GameStates.Pause;
                }

                //CHEAT CODES FOR LOSERS

                //Press 6 & 9 on Keypad to change lives to 69.
                if (kb.IsKeyDown(Keys.D6) && kb.IsKeyDown(Keys.D9))
                {
                    playerManager.LivesRemaining = 68;
                }

                //KYS
                if (kb.IsKeyDown(Keys.K) && kb.IsKeyDown(Keys.Y) && kb.IsKeyDown(Keys.S))
                {
                    playerManager.Destroyed = true;
                    SoundManager.PlayPlayerDeath();
                }

                //AND THIS IS TO GO EVEN FURTHER BEYOND! (Work on This)
                if (kb.IsKeyDown(Keys.S) && kb.IsKeyDown(Keys.D3))
                {
                    playerManager.playerSpeed  = 480.0f;
                    asteroidManager.minSpeed   = 60;
                    asteroidManager.maxSpeed   = 120;
                    playerManager.PowerupLevel = 2;
                    SoundManager.PlayGoku();
                }

                //Smokemon
                if (kb.IsKeyDown(Keys.D4) && kb.IsKeyDown(Keys.D2) && kb.IsKeyDown(Keys.D0))
                {
                    isWeed = true;
                    SoundManager.PlaySmokemon();
                    //Plays Smokemon, but does not reset when you rest.

                    starField = new StarField(
                        this.Window.ClientBounds.Width,
                        this.Window.ClientBounds.Height,
                        200,
                        new Vector2(0, 30f),
                        weedBG,
                        new Rectangle(0, 0, 800, 600));
                }

                /*
                 * Automatic difficulty adjustment based on your progress
                 * if (difficultyLevel == 4 && playerManager.LivesRemaining > 1 && playerManager.LivesRemaining < 59)
                 * {
                 *  asteroidManager.minSpeed = 170;
                 *  asteroidManager.maxSpeed = 270;
                 * }
                 */
                break;

            case GameStates.PlayerDead:
                playerDeathTimer +=
                    (float)gameTime.ElapsedGameTime.TotalSeconds;


                starField.Update(gameTime);
                asteroidManager.Update(gameTime);
                enemyManager.Update(gameTime);
                playerManager.PlayerShotManager.Update(gameTime);
                explosionManager.Update(gameTime);
                planetManager.Update(gameTime);


                if (playerDeathTimer >= playerDeathDelayTime)
                {
                    resetGame();
                    gameState = GameStates.Playing;
                }
                //RESET FUNCTION
                kb = Keyboard.GetState();
                if (kb.IsKeyDown(Keys.R))
                {
                    resetGame();
                    gameState = GameStates.DifficultySelect;
                    playerManager.PlayerScore = 0;
                    playerManager.playerSpeed = 320.0f;
                    playerTimePlayed          = 0f;
                    asteroidManager.Clear();
                    playerManager.PowerupLevel = 1;
                }

                break;

            case GameStates.GameOver:
                playerDeathTimer +=
                    (float)gameTime.ElapsedGameTime.TotalSeconds;
                starField.Update(gameTime);
                asteroidManager.Update(gameTime);
                enemyManager.Update(gameTime);
                playerManager.PlayerShotManager.Update(gameTime);
                explosionManager.Update(gameTime);
                planetManager.Update(gameTime);

                if (playerDeathTimer >= playerDeathDelayTime)
                {
                    gameState = GameStates.TitleScreen;
                }
                //RESET FUNCTION
                kb = Keyboard.GetState();
                if (kb.IsKeyDown(Keys.R))
                {
                    resetGame();
                    gameState = GameStates.DifficultySelect;
                    playerManager.PlayerScore = 0;
                    playerManager.playerSpeed = 320.0f;
                    playerTimePlayed          = 0f;
                    asteroidManager.Clear();
                    playerManager.PowerupLevel = 1;
                }
                break;
            }

            base.Update(gameTime);
        }