Example #1
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)
        {
            if (gameState == GameState.TitleScreen)
            {
                previousState = GameState.TitleScreen;
                startScreen.Update(gameTime, 1);

                if (startScreen.SinglePlayer || startScreen.MultiPlayer)
                {
                    if (fadeScreen.Opacity <= 255)
                    {
                        if (fadeScreen.Opacity != 255)
                        {
                            MediaPlayer.Volume -= .07f;
                            fadeScreen.Fade(gameTime, 15);
                        }
                        else
                        {
                            if (startScreen.SinglePlayer)
                            {
                                gameState = GameState.CharacterSelection;
                                characterScreen = new CharacterSelectionScreen(graphics, Content);
                            }
                            else if (startScreen.MultiPlayer)
                            {
                                gameState = GameState.MultiplayerLobby;
                                multiplayerLobby = new Lobby(graphics, Content, startScreen.ControlScheme);
                            }
                            MediaPlayer.Volume = 1f;
                        }
                    }
                    else
                    {
                        if (fadeScreen != null)
                        {
                            if (fadeScreen.Opacity > 0)
                            {
                                fadeScreen.Fade(gameTime, -1);
                            }
                        }
                    }
                }
            }
            else if (gameState == GameState.CharacterSelection)
            {
                previousState = GameState.CharacterSelection;
                characterScreen.Update(gameTime);

                if (characterScreen.IsDone)
                {
                    if (fadeScreen.Opacity <= 255)
                    {
                        if (fadeScreen.Opacity != 255)
                        {
                            fadeScreen.Fade(gameTime, 15);
                            MediaPlayer.Volume -= .06f;
                        }
                        else
                        {
                            LoadCharacter();
                            gameState = GameState.StartLevel; // .Credits; //
                            characterScreen = null;
                            startScreen = null;
                        }
                    }
                }
                else
                {
                    if (fadeScreen.Opacity > 0)
                    {
                        fadeScreen.Fade(gameTime, -5);
                    }
                }
            }
            else if (gameState == GameState.MultiplayerLobby)
            {
                previousState = GameState.MultiplayerLobby;
                multiplayerLobby.Update(gameTime);

                if (multiplayerLobby.IsDone)
                {
                    if (fadeScreen.Opacity <= 255)
                    {
                        if (fadeScreen.Opacity != 255)
                        {
                            fadeScreen.Fade(gameTime, 15);
                            MediaPlayer.Volume -= .06f;
                        }
                        else
                        {
                            LoadCharacter();
                            gameState = GameState.StartLevel;
                            characterScreen = null;
                            startScreen = null;
                        }
                    }
                }
                else
                {
                    if (fadeScreen.Opacity > 0)
                    {
                        fadeScreen.Fade(gameTime, -5);
                    }
                }
            }
            else if (gameState == GameState.StartLevel)
            {
                previousState = GameState.StartLevel;
                if (fadeScreen.Opacity > 0)
                {
                    MediaPlayer.Volume += .07f;
                    fadeScreen.Fade(gameTime, -5);
                }
                if (fadeScreen.Opacity == 0)
                {
                    MediaPlayer.Volume = 1f;
                }

                float scrollSpeed = gameTime.ElapsedGameTime.Milliseconds / 6f;
                currentLevel.background.Update(gameTime, scrollSpeed);

                levelBeginning.Update(gameTime);
                if (levelIncrement == 1)
                    currentLevel.border.Update(gameTime, scrollSpeed);

                playerOneSprite.Update(gameTime);
                if (playerTwoSprite != null)
                {
                    playerTwoSprite.Update(gameTime);
                }

                if (levelBeginning.IsDone)
                {
                    gameState = GameState.PlayingLevel;
                }
            }
            else if (gameState == GameState.PlayingLevel)
            {
                previousState = GameState.PlayingLevel;

                if (dinosaurOne._currentHealth > 0)
                {
                    if (dinosaurOne.ControlScheme == ChosenControl.Keyboard)
                    {
                        input.Update(Keyboard.GetState(), playerOneSprite, dinosaurOne, playerShots, graphics, gameTime, gameState);
                    }
                    else if (dinosaurOne.ControlScheme == ChosenControl.Gamepad)
                    {
                        padInput.Update(GamePad.GetState(PlayerIndex.One, GamePadDeadZone.None), playerOneSprite, dinosaurOne, playerShots, graphics, gameTime, gameState);
                    }
                }

                if (dinosaurTwo != null)
                {
                    if (dinosaurTwo._currentHealth > 0)
                    {
                        if (dinosaurTwo.ControlScheme == ChosenControl.Keyboard)
                        {
                            input.Update(Keyboard.GetState(), playerTwoSprite, dinosaurTwo, playerShots, graphics, gameTime, gameState);
                        }
                        else if (dinosaurTwo.ControlScheme == ChosenControl.Gamepad)
                        {
                            if (dinosaurOne.ControlScheme != ChosenControl.Gamepad)
                            {
                                padInput.Update(GamePad.GetState(PlayerIndex.One, GamePadDeadZone.None), playerTwoSprite, dinosaurTwo, playerShots, graphics, gameTime, gameState);
                            }
                            else
                            {
                                padInput.Update(GamePad.GetState(PlayerIndex.Two, GamePadDeadZone.None), playerTwoSprite, dinosaurTwo, playerShots, graphics, gameTime, gameState);
                            }
                        }
                    }
                }

                hbOne.Update(dinosaurOne.Health);
                cbOne.Update(dinosaurOne.LaserCharge);
                if (playerTwoSprite != null)
                {
                    hbTwo.Update(dinosaurTwo.Health);
                    cbTwo.Update(dinosaurTwo.LaserCharge);
                }

                int counter = 0;
                foreach (Sprite s in enemies)
                {
                    currentLevel.healthBars[counter++].Update(s.Health, s.Position);

                    if (s.enemyType.type == Enemies.EnemyType.Etype.Level1Boss ||
                        s.enemyType.type == Enemies.EnemyType.Etype.Level2Boss ||
                        s.enemyType.type == Enemies.EnemyType.Etype.Level3Boss)
                    {
                        bossLifeBar.IsVisible = true;
                        bossLifeBar.Update(s.Health);
                    }
                    else
                    {
                        bossLifeBar.IsVisible = false;
                    }
                }

                enemyShots.Update(gameTime, graphics, playerOneSprite, playerTwoSprite);
                playerShots.Update(gameTime, graphics);

                gameState = currentLevel.Update(this, gameTime, spriteBatch, graphics, this.enemies);

                foreach (Sprite enemy in enemies)
                {
                    if (enemy.GetType() == (typeof(AnimatedSprite)))
                    {
                        (enemy as AnimatedSprite).Update(gameTime);
                    }
                    else
                    {
                        enemy.Update(gameTime, graphics, playerOneSprite, playerTwoSprite, dinosaurOne, dinosaurTwo);
                    }

                    if ((enemy.Movement.X < 0 && enemy.Position.X <= 100) || (enemy.Movement.X > 0 && enemy.Position.X >= graphics.PreferredBackBufferWidth - 100))
                    {
                        enemy.Movement = new Vector2(enemy.Movement.X * -1, enemy.Movement.Y);
                    }

                    if ((enemy.Movement.Y < 0 && enemy.Position.Y <= 50) || (enemy.Movement.Y > 0 && enemy.Position.Y >= graphics.PreferredBackBufferHeight / 1.5))
                    {
                        enemy.Movement = new Vector2(enemy.Movement.X, enemy.Movement.Y * -1);
                    }

                    shotBehavior.Update(graphics, enemy, enemyShots);
                }

                AnimatedSprite removeMe = null;
                foreach (AnimatedSprite ex in explosions)
                {
                    ex.Update(gameTime);

                    if (ex.frames >= ex.frameTotal)
                    {
                        removeMe = ex;
                    }
                }
                explosions.Remove(removeMe);

                foreach (Powerup powerUp in collisions.powerups)
                {
                    if (powerUp != null)
                    {
                        powerUp.Update(gameTime);
                    }
                }

                collisions.Update(this, Content, spriteBatch, font, dinosaurOne, enemies, enemyShots, playerShots, currentLevel.randomObjects, currentLevel.healthBars, playerOneSprite, graphics, dinosaurTwo, playerTwoSprite);

                if (dinosaurOne._currentCharge < dinosaurOne.MaxLaserCharge)
                    playerOneCounter += 1;
                if (playerOneCounter >= 9)
                {
                    dinosaurOne._currentCharge++;
                    playerOneCounter = 0;
                }

                if (dinosaurTwo != null)
                {
                    if (dinosaurTwo._currentCharge < dinosaurTwo.MaxLaserCharge)
                        playerTwoCounter += 1;
                    if (playerTwoCounter >= 9)
                    {
                        dinosaurTwo._currentCharge++;
                        playerTwoCounter = 0;
                    }
                }

                if (singlePlayer)
                {
                    if (dinosaurOne._currentHealth <= 0)
                    {
                        hbOne.Update(dinosaurOne.Health);

                        gameState = GameState.Death;
                    }
                }
                else
                {
                    if (dinosaurOne._currentHealth <= 0 && dinosaurTwo._currentHealth <= 0)
                    {
                        hbOne.Update(dinosaurOne.Health);
                        hbTwo.Update(dinosaurTwo.Health);

                        gameState = GameState.Death;
                    }
                    else if (dinosaurOne._currentHealth <= 0 || dinosaurTwo._currentHealth <= 0)
                    {
                        if (dinosaurOne._currentHealth <= 0)
                        {
                            hbOne.Update(0);
                            if (playerOneSprite.Position.Y < graphics.PreferredBackBufferHeight + 200)
                            {
                                if (!explodedOne)
                                {
                                    explodedOne = true;
                                    collisions.explosionSound.Play();
                                }
                                AnimatedSprite explode = new AnimatedSprite(12, 0, 0, 134, 134, this, collisions.explodeImage,
                                playerOneSprite.Position,
                                spriteBatch, new Enemies.EnemyType(Content, Enemies.EnemyType.Etype.Simple));
                                explode.Name = "Explode";
                                explosions.Add(explode);

                                Vector2 movement = Vector2.Zero;
                                movement += Vector2.UnitY * .05f;
                                playerOneSprite.Movement += movement;

                                playerOneSprite.Update(gameTime);
                                movement.X = 0f;
                                movement.Y = 0f;
                                playerOneSprite.Movement = movement;
                                playerOneSprite.Update(gameTime);
                            }
                        }
                        else if (dinosaurTwo._currentHealth <= 0)
                        {
                            hbTwo.Update(0);
                            if (playerTwoSprite.Position.Y < graphics.PreferredBackBufferHeight + 200)
                            {
                                if (!explodedTwo)
                                {
                                    explodedTwo = true;
                                    collisions.explosionSound.Play();
                                }
                                AnimatedSprite explode = new AnimatedSprite(12, 0, 0, 134, 134, this, collisions.explodeImage,
                                playerTwoSprite.Position,
                                spriteBatch, new Enemies.EnemyType(Content, Enemies.EnemyType.Etype.Simple));
                                explode.Name = "Explode";
                                explosions.Add(explode);

                                Vector2 movement = Vector2.Zero;
                                movement += Vector2.UnitY * .05f;
                                playerTwoSprite.Movement += movement;

                                playerTwoSprite.Update(gameTime);
                                movement.X = 0f;
                                movement.Y = 0f;
                                playerTwoSprite.Movement = movement;
                                playerTwoSprite.Update(gameTime);
                            }
                        }
                    }
                }

            }

            else if (gameState == GameState.Death)
            {
                previousState = GameState.Death;

                if (playerTwoSprite != null)
                {
                    AnimatedSprite explode = new AnimatedSprite(12, 0, 0, 134, 134, this, collisions.explodeImage,
                                playerTwoSprite.Position,
                                spriteBatch, new Enemies.EnemyType(Content, Enemies.EnemyType.Etype.Simple));
                    explode.Name = "Explode";

                    if (!explodedOne)
                    {
                        collisions.explosionSound.Play();
                        explodedOne = true;
                    }
                    explosions.Add(explode);

                    AnimatedSprite explodeOne = new AnimatedSprite(12, 0, 0, 134, 134, this, collisions.explodeImage,
                                playerOneSprite.Position,
                                spriteBatch, new Enemies.EnemyType(Content, Enemies.EnemyType.Etype.Simple));
                    explode.Name = "Explode";
                    if (!explodedTwo)
                    {
                        collisions.explosionSound.Play();
                        explodedTwo = true;
                    }
                    explosions.Add(explodeOne);
                }
                else
                {
                    AnimatedSprite explode = new AnimatedSprite(12, 0, 0, 134, 134, this, collisions.explodeImage,
                                playerOneSprite.Position,
                                spriteBatch, new Enemies.EnemyType(Content, Enemies.EnemyType.Etype.Simple));
                    explode.Name = "Explode";
                    if (!explodedOne)
                    {
                        collisions.explosionSound.Play();
                        explodedOne = true;
                    }
                    explosions.Add(explode);
                }

                AnimatedSprite removeMe = null;
                foreach (AnimatedSprite ex in explosions)
                {
                    ex.Update(gameTime);

                    if (ex.frames >= ex.frameTotal)
                    {
                        removeMe = ex;
                    }
                }
                explosions.Remove(removeMe);

                if (fadeScreen.Opacity <= 180)
                {
                    fadeScreen.Fade(gameTime, 1);
                }

                deathScreen.Update(gameTime);

                enemyShots.Update(gameTime, graphics, playerOneSprite, playerTwoSprite);
                playerShots.Update(gameTime, graphics);
                foreach (Powerup powerUp in collisions.powerups)
                {
                    if (powerUp != null)
                    {
                        powerUp.Update(gameTime);
                    }
                }
                collisions.Update(this, Content, spriteBatch, font, dinosaurOne, enemies, enemyShots, playerShots, currentLevel.randomObjects, currentLevel.healthBars, playerOneSprite, graphics, dinosaurTwo, playerTwoSprite);

                if (deathScreen.TitleSelected)
                {
                    if (fadeScreen.Opacity < 255)
                    {
                        fadeScreen.Fade(gameTime, 5);
                        MediaPlayer.Volume -= .06f;
                    }
                    else if (fadeScreen.Opacity >= 255)
                    {
                        UnloadContent();
                        LoadContent();
                    }
                }
            }
            else if (gameState == GameState.EndOfLevel)
            {
                previousState = GameState.EndOfLevel;

                enemyShots.list.Clear();

                playerOneSprite.Update(gameTime);
                if (playerTwoSprite != null)
                {
                    playerTwoSprite.Update(gameTime);
                }

                currentLevel.Update(this, gameTime, spriteBatch, graphics, enemies);
                //enemyShots.Update(gameTime, graphics, playerOneSprite, playerTwoSprite);
                playerShots.Update(gameTime, graphics);
                upgradeScreen.Update(gameTime);

                foreach (Powerup powerUp in collisions.powerups)
                {
                    if (powerUp != null)
                    {
                        powerUp.Update(gameTime);
                    }
                }

                AnimatedSprite removeMe = null;
                foreach (AnimatedSprite ex in explosions)
                {
                    ex.Update(gameTime);

                    if (ex.frames >= ex.frameTotal)
                    {
                        removeMe = ex;
                    }
                }
                explosions.Remove(removeMe);

                collisions.Update(this, Content, spriteBatch, font, dinosaurOne, enemies, enemyShots, playerShots, currentLevel.randomObjects, currentLevel.healthBars, playerOneSprite, graphics, dinosaurTwo, playerTwoSprite);

                if (upgradeScreen.IsComplete)
                {
                    if (fadeScreen.Opacity <= 255)
                    {
                        if (fadeScreen.Opacity != 255)
                        {
                            fadeScreen.Fade(gameTime, 15);
                        }
                        else
                        {
                            if (playerTwoSprite == null)
                            {
                                playerOneSprite.Position = new Vector2(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight - 250);
                                dinosaurOne.Replenish();
                            }
                            else
                            {
                                playerOneSprite.Position = new Vector2(graphics.PreferredBackBufferWidth / 3, graphics.PreferredBackBufferHeight - 250);
                                playerTwoSprite.Position = new Vector2(graphics.PreferredBackBufferWidth - (graphics.PreferredBackBufferWidth / 3), graphics.PreferredBackBufferHeight - 250);
                                dinosaurOne.Replenish();
                                hbOne.Update(dinosaurOne.Health);
                                dinosaurTwo.Replenish();
                                hbTwo.Update(dinosaurTwo.Health);
                            }

                            if (currentLevel.levelSelected != Level.LevelSelected.Level5)
                            {
                                gameState = GameState.LoadingScreen;
                            }
                        }
                    }
                }
            }
            else if (gameState == GameState.LoadingScreen)
            {
                previousState = GameState.LoadingScreen;
                loadingScreen.Update(gameTime);

                if (loadingScreen.IsDone)
                {
                    if (fadeScreen.Opacity <= 255)
                    {
                        if (fadeScreen.Opacity != 255)
                        {
                            fadeScreen.Fade(gameTime, 5);
                            MediaPlayer.Volume -= .07f;
                        }
                        else
                        {
                            gameState = GameState.StartLevel;
                            CreateScreens();
                            GenerateLevel();
                            MediaPlayer.Volume = 1f;
                        }
                    }
                }
                else
                {
                    if (fadeScreen.Opacity > 0)
                    {
                        fadeScreen.Fade(gameTime, -5);
                    }
                }
            }
            else if (gameState == GameState.Pause)
            {
                pauseScreen.Update(gameTime);
                MediaPlayer.Volume = .25f;
                if (pauseScreen.QuitSelected)
                {
                    this.Exit();
                }
                else if (pauseScreen.ResumeSelected)
                {
                    pauseScreen.ResumeSelected = false;
                    gameState = previousState;
                    MediaPlayer.Volume = 1f;
                }
                else if (pauseScreen.TitleSelected)
                {
                    if (fadeScreen.Opacity <= 255)
                    {
                        if (fadeScreen.Opacity != 255)
                        {
                            fadeScreen.Fade(gameTime, 15);
                            MediaPlayer.Volume -= .06f;
                        }
                        else
                        {
                            UnloadContent();
                            LoadContent();
                        }
                    }
                }
            }
            else if (gameState == GameState.Credits)
            {
                previousState = GameState.Credits;

                creditScreen.Update(gameTime);

                if (creditScreen.TextDone && !creditScreen.BeginBackgroundCreditScroll)
                {
                    if (fadeScreen.Opacity < 255)
                    {
                        fadeScreen.Fade(gameTime, 5);
                    }
                    else if (fadeScreen.Opacity == 255)
                    {
                        creditScreen.BeginBackgroundCreditScroll = true;
                        levelBeginning.LevelCount = 1;
                        GenerateLevel();
                    }
                }
                else if (creditScreen.BeginBackgroundCreditScroll)
                {
                    if (fadeScreen.Opacity > 0)
                    {
                        fadeScreen.Fade(gameTime, -5);
                    }
                    currentLevel.background.Update(gameTime, 2);
                    currentLevel.border.Update(gameTime, 3);
                }
                else
                {
                    if (fadeScreen.Opacity > 0)
                    {
                        fadeScreen.Fade(gameTime, -5);
                    }
                }
            }

            // Allows the game to exit
            // Gamepad option to exit
            //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            //{
            //    this.Exit();
            //}

            // allows keyboard exit on esc keypress
            if (Keyboard.GetState().IsKeyDown(Keys.Escape) || GamePad.GetState(PlayerIndex.One, GamePadDeadZone.None).IsButtonDown(Buttons.Start))
            {
            gameState = GameState.Pause;
            }
            base.Update(gameTime);
        }
Example #2
0
        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            gameState = GameState.TitleScreen;
            previousState = gameState;

            upgradeScreen = null;
            startScreen = null;
            characterScreen = null;
            multiplayerLobby = null;
            deathScreen = null;
            levelBeginning = null;
            pauseScreen = null;
            loadingScreen = null;

            levelCreator = null;

            Random rand = new Random();
            currentLevel = null;

            enemies = null;
            explosions = null;
            shotBehavior = null;
            enemyShots = null;
            playerShots = null;
            hbOne = null;
            hbTwo = null;
            bossLifeBar = null;
            cbOne = null;
            cbTwo = null;
            backGroundMusic = null;
            playerOneMeterTitle = null;
            playerTwoMeterTitle = null;
            meterLabel = null;
            playerOneMarker = null;
            playerTwoMarker = null;

            dinosaurOne = null;
            dinosaurTwo = null;
            playerOneSprite = null;
            playerTwoSprite = null;
            collisions = null;
            font = null;

            playerOneCounter = 0;
            playerTwoCounter = 0;
            levelIncrement = 0;

            singlePlayer = false;
            explodedOne = false;
            explodedTwo = false;

            input = null;
            padInput = null;
        }
        private void CheckIfPlayerHitSomething(Game game, SpriteBatch spriteBatch, ContentManager Content, List<HealthBar> healthBars)
        {
            for (int enemyCounter = enemies.Count - 1; enemyCounter >= 0; enemyCounter--)
            {
                Sprite enemy = enemies[enemyCounter];
                enemy.IsHit = false;
                for (int i = playerShots.shotsOne.Count - 1; i >= 0; i--)
                {
                    //don't check for collision below half screen height
                    if (playerShots.shotsOne[i].Y > _halfScreenHeight)
                        continue;

                    if ((Vector2.DistanceSquared(playerShots.shotsOne[i], enemy.Position) < ((enemy.width * enemy.height) / 11f)))
                    {
                        enemy.IsHit = true;
                        enemy._currentHealth -= 10;
                        playerShots.shotsOne.RemoveAt(i);
                        if (enemy._currentHealth <= 0)
                        {
                            AnimatedSprite explode = new AnimatedSprite(12, 0, 0, 134, 134, game, explodeImage,
                                enemy.Position,
                                spriteBatch, new Enemies.EnemyType(Content, Enemies.EnemyType.Etype.Simple));
                            explode.Name = "Explode";
                            explode.delay = 75f;

                            healthBars.RemoveAt(healthBars.Count - 1);

                            explosionSound.Play();
                            dinosaurOne.Points += enemy.enemyType.PointValue;
                            Random r = new Random();
                            if (r.NextDouble() > 0.75)
                            {
                                Vector2 powerupStartingPosition = enemy.Position;
                                Powerup p = new Powerup(gdm, sb, cm, powerupStartingPosition);
                                powerups.Add(p);
                            }

                            enemies.RemoveAt(enemyCounter);
                            explosions.Add(explode);
                        }
                        return;
                    }
                }
            }

            if (playerShots.shotsTwo != null)
            {

                for (int enemyCounter = enemies.Count - 1; enemyCounter >= 0; enemyCounter--)
                {
                    Sprite enemy = enemies[enemyCounter];
                    enemy.IsHit = false;
                    for (int i = playerShots.shotsTwo.Count - 1; i >= 0; i--)
                    {
                        //don't check for collision below half screen height
                        if (playerShots.shotsTwo[i].Y > _halfScreenHeight)
                            continue;

                        if ((Vector2.DistanceSquared(playerShots.shotsTwo[i], enemy.Position) < ((enemy.width * enemy.height) / 11f)))
                        {
                            enemy.IsHit = true;
                            enemy._currentHealth -= 10;
                            playerShots.shotsTwo.RemoveAt(i);
                            if (enemy._currentHealth <= 0)
                            {
                                AnimatedSprite explode = new AnimatedSprite(12, 0, 0, 134, 134, game, explodeImage,
                                    enemy.Position,
                                    spriteBatch, new Enemies.EnemyType(Content, Enemies.EnemyType.Etype.Simple));
                                explode.Name = "Explode";
                                explode.delay = 75f;

                                healthBars.RemoveAt(healthBars.Count - 1);

                                explosionSound.Play();
                                dinosaurTwo.Points += enemy.enemyType.PointValue;
                                Random r = new Random();
                                if (r.NextDouble() > 0.75)
                                {
                                    Vector2 powerupStartingPosition = enemy.Position;
                                    Powerup p = new Powerup(gdm, sb, cm, powerupStartingPosition);
                                    powerups.Add(p);
                                }

                                enemies.RemoveAt(enemyCounter);
                                explosions.Add(explode);
                            }
                            return;
                        }
                    }
                }
            }
        }
Example #4
0
        private void ValidateCharacter(int player)
        {
            if (player == 1)
            {
                if (dinosaurOne.dinoChosen == Player.Chara.Bronto)
                {
                    playerOneSprite = new AnimatedSprite(12, 0, 0, 38, 183, this, dinosaurOne.Image, dinosaurOne.Position, spriteBatch, new EnemyType(Content, EnemyType.Etype.Player));
                }
                else if (dinosaurOne.dinoChosen == Player.Chara.Trex)
                {
                    playerOneSprite = new AnimatedSprite(12, 0, 0, 69, 181, this, dinosaurOne.Image, dinosaurOne.Position, spriteBatch, new EnemyType(Content, EnemyType.Etype.Player));
                }
                else if (dinosaurOne.dinoChosen == Player.Chara.Ptera)
                {
                    playerOneSprite = new AnimatedSprite(7, 0, 0, 195, 118, this, dinosaurOne.Image, dinosaurOne.Position, spriteBatch, new EnemyType(Content, EnemyType.Etype.Player));
                }
                else if (dinosaurOne.dinoChosen == Player.Chara.Cera)
                {
                    playerOneSprite = new AnimatedSprite(7, 0, 0, 62, 175, this, dinosaurOne.Image, dinosaurOne.Position, spriteBatch, new EnemyType(Content, EnemyType.Etype.Player));
                }
            }
            else if (player == 2)
            {
                if (dinosaurTwo.dinoChosen == Player.Chara.Bronto)
                {
                    playerTwoSprite = new AnimatedSprite(12, 0, 0, 38, 183, this, dinosaurTwo.Image, dinosaurTwo.Position, spriteBatch, new EnemyType(Content, EnemyType.Etype.Player));
                }
                else if (dinosaurTwo.dinoChosen == Player.Chara.Trex)
                {
                    playerTwoSprite = new AnimatedSprite(12, 0, 0, 69, 181, this, dinosaurTwo.Image, dinosaurTwo.Position, spriteBatch, new EnemyType(Content, EnemyType.Etype.Player));
                }
                else if (dinosaurTwo.dinoChosen == Player.Chara.Ptera)
                {
                    playerTwoSprite = new AnimatedSprite(7, 0, 0, 195, 118, this, dinosaurTwo.Image, dinosaurTwo.Position, spriteBatch, new EnemyType(Content, EnemyType.Etype.Player));
                }
                else if (dinosaurTwo.dinoChosen == Player.Chara.Cera)
                {
                    playerTwoSprite = new AnimatedSprite(7, 0, 0, 62, 175, this, dinosaurTwo.Image, dinosaurTwo.Position, spriteBatch, new EnemyType(Content, EnemyType.Etype.Player));
                }

                hbTwo = new HealthBar(Content, graphics, new Vector2(graphics.PreferredBackBufferWidth - 330, graphics.PreferredBackBufferHeight - 125));
                cbTwo = new ChargeMeter(Content, graphics, new Vector2(graphics.PreferredBackBufferWidth - 330, graphics.PreferredBackBufferHeight - 75));
            }
        }
Example #5
0
        public GameState Update(Game game, GameTime gameTime, SpriteBatch spriteBatch, GraphicsDeviceManager graphics, List<Sprite> enemies)
        {
            GameState gameState = GameState.PlayingLevel;

            if (!boss && !midBoss)
            {
                DistanceTravelled += 1;
                ScrollSpeed = gameTime.ElapsedGameTime.Milliseconds / 6f;
            }
            else
            {
                ScrollSpeed = 0;

                if (playBossSound == false && boss)
                {
                    playBossSound = true;

                    bossSound.Play();
                }
                if (boss)
                {
                    if (!IsBossMusicPlaying)
                    {
                        BossBGMusic.Play();
                        IsBossMusicPlaying = true;
                    }
                }
                else
                {
                    playBossSound = false;
                }
            }

            background.Update(gameTime, ScrollSpeed);

            if (levelSelected == LevelSelected.Level1)
            {
                border.Update(gameTime, ScrollSpeed);
            }
            else if (levelSelected == LevelSelected.Level2)
            {
                foreach (Clouds cloud in clouds)
                {
                    cloud.Update(gameTime, graphics, ScrollSpeed);
                }
            }

            EnemyGroup deleteMe = null;
            foreach (EnemyGroup eg in groups)
            {
                eg.Update(DistanceTravelled, this);

                if (eg.group.Count == 0)
                {
                    deleteMe = eg;
                }
            }

            if (deleteMe != null)
            {
                this.groups.Remove(deleteMe);
            }

            foreach (Enemy e in this.enemies)
            {
                Sprite newEnemy = null;

                if (e.isAnimatedSprite)
                {
                    if (e.type.type == EnemyType.Etype.Level2MidBoss)
                    {
                        newEnemy = new AnimatedSprite(5, 0, 0, 85, 87, game, e.Image, e.Position, spriteBatch, e.type);
                    }
                    else if (e.type.type == EnemyType.Etype.Level2Boss)
                    {
                        newEnemy = new AnimatedSprite(3, 0, 0, 193, 377, game, e.Image, e.Position, spriteBatch, e.type);
                    }
                    else if (e.type.type == EnemyType.Etype.Level3Boss)
                    {
                        newEnemy = new AnimatedSprite(7, 0, 0, 189, 377, game, e.Image, e.Position, spriteBatch, e.type);
                    }
                    else if (e.type.type == EnemyType.Etype.Level4Boss)
                    {
                        newEnemy = new AnimatedSprite(3, 0, 0, 192, 377, game, e.Image, e.Position, spriteBatch, e.type);
                    }
                }
                else
                {
                    newEnemy = new Sprite(game, e.Image, e.Position, spriteBatch, e.type);
                }

                healthBars.Add(new HealthBar(Content, graphics, newEnemy.Position));
                newEnemy.Movement = e.Movement;
                enemies.Add(newEnemy);
            }

            // used to move random items down the screen
            Vector2 movement = new Vector2();
            movement = Vector2.Zero;
            movement.Y = ScrollSpeed;

            foreach (Sprite rObj in randomObjects)
            {
                rObj.Position += movement;

                if (rObj.Position.Y >= graphics.PreferredBackBufferHeight + 200)
                {
                    rObj.Position = new Vector2(rand.Next(50, graphics.PreferredBackBufferWidth - 50), rand.Next(-1000, -100));
                }
            }

            this.enemies.Clear();

            if (enemies.Count == 0)
            {
                if (midBoss)
                    midBoss = false;
                else if (boss)
                {
                    boss = false;
                    if (this.levelSelected != Level.LevelSelected.Level5)
                    {
                        gameState = GameState.EndOfLevel;
                    }
                    else
                    {
                        gameState = GameState.Credits;
                    }
                }
            }
            return gameState;
        }