Exemple #1
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            float timeScale = (float)gameTime.ElapsedGameTime.TotalSeconds;

            timeScale = 1.0f;

            // clear every cycle or we can get graphical artifacts
            // not strictly necessary as we tend to fill up the whole screen every frame
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // begin drawing - XNA 4.0 code -
            spriteBatch.Begin(SpriteSortMode.Deferred,          // TODO: Research
                              BlendState.AlphaBlend,            // blend alphas - i.e., transparencies
                              SamplerState.PointClamp,          // turn off magnification blurring
                              DepthStencilState.Default,        //
                              RasterizerState.CullNone);        // TODO: Research

            // FIXME: create separate cloud-overlay class
            // begin janky cloud-drawing code: (should put this off in its own class)

            Rectangle tmpBackgroundRect = new Rectangle(0, cloudsOffset, SCREEN_WIDTH, SCREEN_HEIGHT);

            spriteBatch.Draw(cloudsTexture, tmpBackgroundRect, Color.White);

            tmpBackgroundRect = new Rectangle(0, cloudsOffset - SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);

            spriteBatch.Draw(cloudsTexture, tmpBackgroundRect, Color.White);

            cloudsOffset += 1;
            if (cloudsOffset > 600)
            {
                cloudsOffset -= SCREEN_HEIGHT;
            }

            // end janky cloud-drawing code



            // spit out all the entities:
            foreach (Entity tmpEntity in listOfEntities)
            {
                tmpEntity.Draw(spriteBatch, gameTime);
            }

            // spit out powerups
            foreach (Entity tmpPowerUp in listOfPowerUps)
            {
                tmpPowerUp.Draw(spriteBatch, gameTime);
            }

            // now for explosions
            foreach (Entity tmpExplosion in listOfExplosions)
            {
                tmpExplosion.Draw(spriteBatch, gameTime);
            }


            // FIXME: this should be in its own crowd-drawing class
            // foreground clouds -- janky as f**k --- TODO: put this in a separate class

            Rectangle tmpForegroundRect = new Rectangle(0, fastCloudsOffset, SCREEN_WIDTH, SCREEN_HEIGHT);

//          Color transparentColor = new Color(1.0f, 1.0f, 1.0f, 0.25f);          // XNA 3.1 version
            // FIXME: don't redefine this every frame! that is DUMB.
            Color transparentColor = new Color(0.25f, 0.25f, 0.25f, 0.25f);         // XNA 4.0 version

            spriteBatch.Draw(cloudsTexture, tmpForegroundRect, transparentColor);

            tmpForegroundRect = new Rectangle(0, fastCloudsOffset - SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);

            spriteBatch.Draw(cloudsTexture, tmpForegroundRect, transparentColor);

            fastCloudsOffset += 5;
            if (fastCloudsOffset > SCREEN_HEIGHT)
            {
                fastCloudsOffset -= SCREEN_HEIGHT;
            }


            // debugging text -- FIXME: put this in its own function
            string output = "";

            // Draw debugging text:
            if (gameState == GameStatus.game)
            {
//                output = "Kills:" + totalKills;
                output = "Number of power ups: " + listOfPowerUps.Count();
//                output = "Time Alive: " + aliveTime.TotalRealTime.Hours + ":" + aliveTime.TotalRealTime.Minutes + ":" + aliveTime.TotalRealTime.Seconds;
            }



            // Find the center of the string
            Vector2 FontOrigin = devFont.MeasureString(output) / 2;

            // Draw the string
            spriteBatch.DrawString(devFont, output, new Vector2(21, 571), Color.DarkBlue);

            spriteBatch.DrawString(devFont, output, new Vector2(20, 570), Color.WhiteSmoke);

            hudHealthBar.DrawHealthTicks(spriteBatch, player.GetHealth(), player.GetMaxHealth());

            // draw overlays:

            switch (gameState)
            {
            case GameStatus.startMenu:
            {
                spriteBatch.Draw(mainMenuTexture, fullScreen, Color.White);

                break;
            }

            case GameStatus.dead:
            {
                spriteBatch.Draw(deathScreenTexture, fullScreen, Color.White);

                string finalScore = "You took " + totalKills + " souls with you.";

                // Find the center of the string
                int scoreXPos = 400 - ((int)devFont.MeasureString(finalScore).X / 2);

                // Draw the string
                spriteBatch.DrawString(devFont, finalScore, new Vector2(scoreXPos, 561), Color.DarkBlue);

                spriteBatch.DrawString(devFont, finalScore, new Vector2(scoreXPos, 560), Color.WhiteSmoke);

                break;
            }

            default:
            {
                break;
            }
            }

            fader.Draw(spriteBatch, gameTime);      // fader overlay for fading in and out

            // end drawing:
            spriteBatch.End();

            base.Draw(gameTime);
        }
Exemple #2
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); */
        }
Exemple #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); */
        }