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)
        {
            fader.Update(gameTime);

            if (gameState == GameStatus.startMenu)
            {
                ParseInput(gameTime);           // fixme
                return;
            }

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

            // TODO: Add your update logic here

            foreach (Entity tmpEntity in newEntities)
            {
                listOfEntities.Add(tmpEntity);
            }

            newEntities.RemoveRange(0, newEntities.Count());

            // this code should be off in its own method
            // add more planes:
            if (numberOfEnemies < MAX_ENEMIES && randomizer.Next(10) < 1)
            {

                Vector2 tmpVector = new Vector2(randomizer.Next(10, 790), -50);     // FIXME: get rid of magic numbers

                ShipType tmpShipType = (ShipType)randomizer.Next(0, 3);

                AIType tmpAIType = (AIType)randomizer.Next(0, 4);

                // FIXME: this should be controlled differently
                if (enemiesPassed % ZEPPELIN_FREQUENCY == (ZEPPELIN_FREQUENCY - 1))
                {
                    ZeppelinBoss tmpZepp = new ZeppelinBoss(zeppelinTexture, new Vector2(400, -250), this);
                    listOfEntities.Add(tmpZepp);
                }
                else
                {

                    EnemyShip tmpEnemyShip = new EnemyShip(enemyTexture, tmpShipType, tmpAIType, tmpVector, this);
                    listOfEntities.Add(tmpEnemyShip);
                }
                ++numberOfEnemies;
                ++enemiesPassed;

            }

            // parse player's keypresses
            ParseInput(gameTime);

            List<Entity> entitiesToDelete = new List<Entity>();

            // go thru each entity and update its AI:
            foreach (Entity tmpEntity in listOfEntities)
            {
                tmpEntity.Update(gameTime);

                // if an entity is off the screen, mark it for death!
                if (!tmpEntity.isVisible()) entitiesToDelete.Add(tmpEntity);
            }

            // collision detection -- FIXME: this should be its own function at the very least.
            for (int compare_index1 = 0; compare_index1 < listOfEntities.Count; compare_index1++)
            {
                for (int compare_index2 = compare_index1 + 1; compare_index2 < listOfEntities.Count; compare_index2++)
                {
                    Entity compareEntity1 = listOfEntities[compare_index1];
                    Entity compareEntity2 = listOfEntities[compare_index2];

                    if(compareEntity1.Collision() &&
                       compareEntity2.Collision() &&
                       (compareEntity1.GetTeam() != compareEntity2.GetTeam())
                       )
                    {
                    Rectangle rect1 = compareEntity1.ScreenRect();
                    Rectangle rect2 = compareEntity2.ScreenRect();

                    if (rect1.Intersects(rect2))
                    {
                        // FIXME: this should take data from the individual ships
                        compareEntity1.TakeDamage(5);
                        compareEntity2.TakeDamage(5);

                        // FIXME
                        if (!compareEntity1.isVisible() || !compareEntity2.isVisible())
                        {
                            if (randomizer.Next(0, 10) < 1)
                            {
                                Entity tmpPowerUp = new PowerUp(powerUpsTexture, PowerUpType.repair, compareEntity1.CurrentPosition());
                                listOfPowerUps.Add(tmpPowerUp);

                            }

                        }

                        // randomize the pitch of the explosion
                        // TODO: put this in a separate class
                        float pitchShift = -0.1f * (float)randomizer.Next(1, 5) - 0.5f;

                        explosion1.Play(0.20f, pitchShift, 0.0f);

                        Vector2 tmpPosition = listOfEntities[compare_index2].CurrentPosition();

                        // create the physical explosion:
                        Explosion tmpExplosion = new Explosion(explosionsTexture, ExplosionType.Basic, tmpPosition);

                        listOfExplosions.Add(tmpExplosion);

                    }
                    }
                }

                // power-up collisions:

                foreach (Entity tmpPowerUp in listOfPowerUps)
                {
                    if (player.ScreenRect().Intersects(tmpPowerUp.ScreenRect()))
                    {
                        tmpPowerUp.Destroy();

                        // FIXME: this should be dealt with by the the powerup + player
                        player.Repair(1);

                    }
                }

                // FIXME: this is messy! should probably be split off
                if (player.GetHealth() <= 0 && gameState == GameStatus.game)
                {
                    gameState = GameStatus.dead;

                    MediaPlayer.IsRepeating = false;
                    MediaPlayer.Play(Content.Load<Song>("Music/taps"));
                    MediaPlayer.Volume = 1.0f;

                }
            }
            // end collision detection

            // remove any entities that have been marked for death:
            // have to do it this way, or the foreach code above will freak out
            foreach (Entity tmpEntity in entitiesToDelete)
            {
                listOfEntities.Remove(tmpEntity);
                if (tmpEntity is EnemyShip) --numberOfEnemies;
            }

            // power-ups next
            // update & delete ones that are finished       --- TODO: put this all in a separate function that gets called repeatedly
            List<Entity> powerUpsToDelete = new List<Entity>();

            foreach (Entity tmpPowerUp in listOfPowerUps)
            {
                tmpPowerUp.Update(gameTime);
                if (!tmpPowerUp.isVisible()) powerUpsToDelete.Add(tmpPowerUp);
            }

            foreach (Entity tmpPowerUp in powerUpsToDelete)
            {
                listOfPowerUps.Remove(tmpPowerUp);
            }

            // explosions now!
            // update and delete ones that are finished
            List<Entity> explosionsToDelete = new List<Entity>();

            foreach (Entity tmpExplosion in listOfExplosions)
            {
                tmpExplosion.Update(gameTime);
                if (!tmpExplosion.isVisible()) explosionsToDelete.Add(tmpExplosion);
            }

            foreach (Entity tmpExplosion in explosionsToDelete)
            {
                listOfExplosions.Remove(tmpExplosion);
            }

            base.Update(gameTime);
        }
Example #2
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)
        {
            fader.Update(gameTime);

            if (gameState == GameStatus.startMenu)
            {
                ParseInput(gameTime);           // fixme
                return;
            }

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

            // TODO: Add your update logic here

            foreach (Entity tmpEntity in newEntities)
            {
                listOfEntities.Add(tmpEntity);
            }

            newEntities.RemoveRange(0, newEntities.Count());

            // this code should be off in its own method
            // add more planes:
            if (numberOfEnemies < MAX_ENEMIES && randomizer.Next(10) < 1)
            {
                Vector2 tmpVector = new Vector2(randomizer.Next(10, 790), -50);     // FIXME: get rid of magic numbers

                ShipType tmpShipType = (ShipType)randomizer.Next(0, 3);

                AIType tmpAIType = (AIType)randomizer.Next(0, 4);

                // FIXME: this should be controlled differently
                if (enemiesPassed % ZEPPELIN_FREQUENCY == (ZEPPELIN_FREQUENCY - 1))
                {
                    ZeppelinBoss tmpZepp = new ZeppelinBoss(zeppelinTexture, new Vector2(400, -250), this);
                    listOfEntities.Add(tmpZepp);
                }
                else
                {
                    EnemyShip tmpEnemyShip = new EnemyShip(enemyTexture, tmpShipType, tmpAIType, tmpVector, this);
                    listOfEntities.Add(tmpEnemyShip);
                }
                ++numberOfEnemies;
                ++enemiesPassed;
            }

            // parse player's keypresses
            ParseInput(gameTime);

            List <Entity> entitiesToDelete = new List <Entity>();

            // go thru each entity and update its AI:
            foreach (Entity tmpEntity in listOfEntities)
            {
                tmpEntity.Update(gameTime);

                // if an entity is off the screen, mark it for death!
                if (!tmpEntity.isVisible())
                {
                    entitiesToDelete.Add(tmpEntity);
                }
            }

            // collision detection -- FIXME: this should be its own function at the very least.
            for (int compare_index1 = 0; compare_index1 < listOfEntities.Count; compare_index1++)
            {
                for (int compare_index2 = compare_index1 + 1; compare_index2 < listOfEntities.Count; compare_index2++)
                {
                    Entity compareEntity1 = listOfEntities[compare_index1];
                    Entity compareEntity2 = listOfEntities[compare_index2];

                    if (compareEntity1.Collision() &&
                        compareEntity2.Collision() &&
                        (compareEntity1.GetTeam() != compareEntity2.GetTeam())
                        )
                    {
                        Rectangle rect1 = compareEntity1.ScreenRect();
                        Rectangle rect2 = compareEntity2.ScreenRect();


                        if (rect1.Intersects(rect2))
                        {
                            // FIXME: this should take data from the individual ships
                            compareEntity1.TakeDamage(5);
                            compareEntity2.TakeDamage(5);

                            // FIXME
                            if (!compareEntity1.isVisible() || !compareEntity2.isVisible())
                            {
                                if (randomizer.Next(0, 10) < 1)
                                {
                                    Entity tmpPowerUp = new PowerUp(powerUpsTexture, PowerUpType.repair, compareEntity1.CurrentPosition());
                                    listOfPowerUps.Add(tmpPowerUp);
                                }
                            }

                            // randomize the pitch of the explosion
                            // TODO: put this in a separate class
                            float pitchShift = -0.1f * (float)randomizer.Next(1, 5) - 0.5f;

                            explosion1.Play(0.20f, pitchShift, 0.0f);

                            Vector2 tmpPosition = listOfEntities[compare_index2].CurrentPosition();

                            // create the physical explosion:
                            Explosion tmpExplosion = new Explosion(explosionsTexture, ExplosionType.Basic, tmpPosition);

                            listOfExplosions.Add(tmpExplosion);
                        }
                    }
                }



                // power-up collisions:



                foreach (Entity tmpPowerUp in listOfPowerUps)
                {
                    if (player.ScreenRect().Intersects(tmpPowerUp.ScreenRect()))
                    {
                        tmpPowerUp.Destroy();

                        // FIXME: this should be dealt with by the the powerup + player
                        player.Repair(1);
                    }
                }

                // FIXME: this is messy! should probably be split off
                if (player.GetHealth() <= 0 && gameState == GameStatus.game)
                {
                    gameState = GameStatus.dead;

                    MediaPlayer.IsRepeating = false;
                    MediaPlayer.Play(Content.Load <Song>("Music/taps"));
                    MediaPlayer.Volume = 1.0f;
                }
            }
            // end collision detection

            // remove any entities that have been marked for death:
            // have to do it this way, or the foreach code above will freak out
            foreach (Entity tmpEntity in entitiesToDelete)
            {
                listOfEntities.Remove(tmpEntity);
                if (tmpEntity is EnemyShip)
                {
                    --numberOfEnemies;
                }
            }

            // power-ups next
            // update & delete ones that are finished       --- TODO: put this all in a separate function that gets called repeatedly
            List <Entity> powerUpsToDelete = new List <Entity>();

            foreach (Entity tmpPowerUp in listOfPowerUps)
            {
                tmpPowerUp.Update(gameTime);
                if (!tmpPowerUp.isVisible())
                {
                    powerUpsToDelete.Add(tmpPowerUp);
                }
            }

            foreach (Entity tmpPowerUp in powerUpsToDelete)
            {
                listOfPowerUps.Remove(tmpPowerUp);
            }


            // explosions now!
            // update and delete ones that are finished
            List <Entity> explosionsToDelete = new List <Entity>();

            foreach (Entity tmpExplosion in listOfExplosions)
            {
                tmpExplosion.Update(gameTime);
                if (!tmpExplosion.isVisible())
                {
                    explosionsToDelete.Add(tmpExplosion);
                }
            }

            foreach (Entity tmpExplosion in explosionsToDelete)
            {
                listOfExplosions.Remove(tmpExplosion);
            }


            base.Update(gameTime);
        }
Example #3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            devFont = Content.Load<SpriteFont>("Fonts/devFont");

            // TODO: use this.Content to load your game content here

            myTexture = Content.Load<Texture2D>("Graphics/player_ship");
            enemyTexture = Content.Load<Texture2D>("Graphics/enemy_ship");
            projectileTexture = Content.Load<Texture2D>("Graphics/projectiles");
            cloudsTexture = Content.Load<Texture2D>("Graphics/clouds1");
            explosionsTexture = Content.Load<Texture2D>("Graphics/explosions");
            zeppelinTexture = Content.Load<Texture2D>("Graphics/zeppelin");
            blackPixelTexture = Content.Load<Texture2D>("Graphics/BlackPixel");
            mainMenuTexture = Content.Load<Texture2D>("Graphics/startScreen");
            deathScreenTexture = Content.Load<Texture2D>("Graphics/endScreen");      // FIXME
            healthTickTexture = Content.Load<Texture2D>("Graphics/healthTick");
            powerUpsTexture = Content.Load<Texture2D>("Graphics/powerups");

            explosion1 = Content.Load<SoundEffect>("Sfx/explosion1");
            gunShot1 = Content.Load<SoundEffect>("Sfx/magnum1");
            engineLoop = Content.Load<SoundEffect>("Sfx/engine_loop");

            // song to loop:
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(Content.Load<Song>("Music/taiko_piece"));
            MediaPlayer.Volume = 1.0f;

            listOfEntities = new List<Entity>();

            listOfExplosions = new List<Entity>();

            listOfPowerUps = new List<Entity>();

            newEntities = new List<Entity>();

            // this isn't necessary right now, but having a List later, esp. when file-names
            // are drawn from external data, will be very useful. probably want to have a separate
            // class to deal with texture data & names
            listOfTextures = new List<Texture2D> {
                myTexture,
                enemyTexture,
                projectileTexture,
                cloudsTexture,
                explosionsTexture,
                zeppelinTexture,
                blackPixelTexture,
                healthTickTexture,
                powerUpsTexture
            };

            // create the full-screen fader for fading in and out (how cinematic!)
            fader = new Fader(blackPixelTexture, fullScreen);
            fader.fadeIn(Fader.DEFAULT_FADE_SHIFT);

            // create our player's ship and assign it:
            player = new PlayerShip(myTexture);

            listOfEntities.Add(player);         // add the player entity to our global list of entities

            hudHealthBar = new HealthBar(healthTickTexture, player.GetHealth(), player.GetMaxHealth());

            PowerUp tmpPowerUp = new PowerUp(powerUpsTexture, PowerUpType.repair, new Vector2(400, 100));

            listOfPowerUps.Add(tmpPowerUp);

            /*            // test enemy -- this should really go elsewhere:
            EnemyShip tmpEnemy = new EnemyShip(enemyTexture, ShipType.Grey, AIType.Basic, new Vector2(300, 0), this);

            listOfEntities.Add(tmpEnemy);       // make sure to add all entities to our global list!
            ++numberOfEnemies;

            zeppBoss = new ZeppelinBoss(zeppelinTexture, new Vector2(0, -100), this);

            listOfEntities.Add(zeppBoss); */
        }
Example #4
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            devFont     = Content.Load <SpriteFont>("Fonts/devFont");

            // TODO: use this.Content to load your game content here

            myTexture          = Content.Load <Texture2D>("Graphics/player_ship");
            enemyTexture       = Content.Load <Texture2D>("Graphics/enemy_ship");
            projectileTexture  = Content.Load <Texture2D>("Graphics/projectiles");
            cloudsTexture      = Content.Load <Texture2D>("Graphics/clouds1");
            explosionsTexture  = Content.Load <Texture2D>("Graphics/explosions");
            zeppelinTexture    = Content.Load <Texture2D>("Graphics/zeppelin");
            blackPixelTexture  = Content.Load <Texture2D>("Graphics/BlackPixel");
            mainMenuTexture    = Content.Load <Texture2D>("Graphics/startScreen");
            deathScreenTexture = Content.Load <Texture2D>("Graphics/endScreen");      // FIXME
            healthTickTexture  = Content.Load <Texture2D>("Graphics/healthTick");
            powerUpsTexture    = Content.Load <Texture2D>("Graphics/powerups");

            explosion1 = Content.Load <SoundEffect>("Sfx/explosion1");
            gunShot1   = Content.Load <SoundEffect>("Sfx/magnum1");
            engineLoop = Content.Load <SoundEffect>("Sfx/engine_loop");

            // song to loop:
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Play(Content.Load <Song>("Music/taiko_piece"));
            MediaPlayer.Volume = 1.0f;

            listOfEntities = new List <Entity>();

            listOfExplosions = new List <Entity>();

            listOfPowerUps = new List <Entity>();

            newEntities = new List <Entity>();

            // this isn't necessary right now, but having a List later, esp. when file-names
            // are drawn from external data, will be very useful. probably want to have a separate
            // class to deal with texture data & names
            listOfTextures = new List <Texture2D> {
                myTexture,
                enemyTexture,
                projectileTexture,
                cloudsTexture,
                explosionsTexture,
                zeppelinTexture,
                blackPixelTexture,
                healthTickTexture,
                powerUpsTexture
            };

            // create the full-screen fader for fading in and out (how cinematic!)
            fader = new Fader(blackPixelTexture, fullScreen);
            fader.fadeIn(Fader.DEFAULT_FADE_SHIFT);

            // create our player's ship and assign it:
            player = new PlayerShip(myTexture);

            listOfEntities.Add(player);         // add the player entity to our global list of entities

            hudHealthBar = new HealthBar(healthTickTexture, player.GetHealth(), player.GetMaxHealth());

            PowerUp tmpPowerUp = new PowerUp(powerUpsTexture, PowerUpType.repair, new Vector2(400, 100));

            listOfPowerUps.Add(tmpPowerUp);



/*            // test enemy -- this should really go elsewhere:
 *          EnemyShip tmpEnemy = new EnemyShip(enemyTexture, ShipType.Grey, AIType.Basic, new Vector2(300, 0), this);
 *
 *          listOfEntities.Add(tmpEnemy);       // make sure to add all entities to our global list!
 ++numberOfEnemies;
 *
 *          zeppBoss = new ZeppelinBoss(zeppelinTexture, new Vector2(0, -100), this);
 *
 *          listOfEntities.Add(zeppBoss); */
        }