topical media & game development

talk show tell print

game-xna-intro-XnaShooterUIProject-GameScreens-Mission.cs / cs



  // Project: XnaGraphicEngine, File: Mission.cs
  // Namespace: XnaGraphicEngine.GameScreens, Class: Mission
  // Path: C:\code\XnaGraphicEngine\GameScreens, Author: Abi
  // Code lines: 46, Size of file: 857 Bytes
  // Creation date: 01.11.2005 23:55
  // Last modified: 08.12.2005 16:14
  // Generated with Commenter by abi.exDream.com
  
  #region Using directives
  using System;
  using System.Collections.Generic;
  using System.Text;
  using XnaGraphicEngine.Graphics;
  using XnaGraphicEngine.Helpers;
  using XnaGraphicEngine.Game;
  using Microsoft.Xna.Framework;
  using Microsoft.Xna.Framework.Graphics;
  using Texture = XnaGraphicEngine.Graphics.Texture;
  using Model = XnaGraphicEngine.Graphics.Model;
  using XnaGraphicEngine.Sounds;
  using Microsoft.Xna.Framework.Input;
  #endregion
  
  namespace XnaGraphicEngine.GameScreens
  {
  
<summary> Mission, just manages the on screen display for the game. Controlling is done in SpaceCamera class. Most graphical stuff is done in AsteroidManager. </summary> class Mission : IGameScreen { #region Variables <summary> Link to game.hudTopTexture and hudBottomTexture. This are just references. </summary> private Texture hudTopTexture, hudBottomTexture; #endregion #region Properties <summary> Name of this game screen </summary> <returns>String</returns> public string Name { get { return "Mission"; } // get } // Name

                  private bool quit = false;
  
<summary> Returns true if we want to quit this screen and return to the previous screen. If no more screens are left the game is exited. </summary> <returns>Bool</returns> public bool Quit { get { return quit; } // get } // Quit #endregion

                  #region Constructor
  
<summary> Create mission </summary> public Mission() { //TODO: load textures? } // Mission() #endregion

                  #region Show hud controls
  
<summary> Show hud controls </summary> private void ShowHudControls() { Rectangle rect = BaseGame.CalcRectangleKeep4To3(hudTopTexture.GfxRectangle); if XBOX360 // Make it 7% smaller! rect.X = (int)(rect.X + BaseGame.Width * 0.035f); rect.Y = (int)(rect.Y + BaseGame.Height * 0.035f); rect.Width = (int)(rect.Width * 0.93f); //rect.Height = (int)(rect.Height * 0.93f); endif // Render top hud part hudTopTexture.RenderOnScreen( rect, hudTopTexture.GfxRectangle);

                          // Time
                          BaseGame.NumbersFont.WriteTime(
                                  rect.X + (int)(73 * rect.Width / 1024.0f),
                                  rect.Y + BaseGame.YToRes(8),
                                  (int)Player.gameTimeMs);
                          // Score
                          BaseGame.NumbersFont.WriteNumberCentered(
                                  rect.X + (int)(485 * rect.Width / 1024.0f),
                                  rect.Y + BaseGame.YToRes(8),
                                  Player.score);
                          // Highscore
                          BaseGame.NumbersFont.WriteNumberCentered(
                                  rect.X + (int)(920 * rect.Width / 1024.0f),
                                  rect.Y + BaseGame.YToRes(8),
                                  Highscores.TopHighscore);
  
                          // Render bottom hud part
                          Rectangle bottomHudGfxRect = new Rectangle(0, 25, 1024, 39);
                          rect = BaseGame.CalcRectangleKeep4To3(bottomHudGfxRect);
                          rect.Y = BaseGame.YToRes(768 - 40);
  if XBOX360
                          // Make it 10% smaller!
                          rect.X = (int)(rect.X + BaseGame.Width * 0.035f);
                          rect.Y = (int)(rect.Y - BaseGame.Height * 0.035f);
                          rect.Width = (int)(rect.Width * 0.93f);
                          //rect.Height = (int)(rect.Height * 0.93f);
  endif
                          hudBottomTexture.RenderOnScreen(
                                  rect, bottomHudGfxRect);
                          // Health
                          //tst: Player.health = 0.35f;
                          Rectangle healthGfxRect = new Rectangle(50, 0, 361, 24);
                          healthGfxRect = new Rectangle(healthGfxRect.X, healthGfxRect.Y,
                                  (int)(healthGfxRect.Width * Player.health), healthGfxRect.Height);
                          hudBottomTexture.RenderOnScreen(
                                  //Relative4To3(50, 768 - 31,
                                  new Rectangle(
                                  rect.X + (int)(50 * rect.Width / 1024.0f),
                                  rect.Bottom - BaseGame.YToRes(31),
                                  (int)(healthGfxRect.Width * rect.Width / 1024.0f),
                                  BaseGame.YToRes(24)),
                                  healthGfxRect);
                          // Weapon and Emps!
                          Rectangle weaponMgGfxRect = new Rectangle(876, 0, 31, 24);
                          Rectangle weaponGattlingGfxRect = new Rectangle(909, 0, 27, 24);
                          Rectangle weaponPlasmaGfxRect = new Rectangle(939, 0, 33, 24);
                          Rectangle weaponRocketsGfxRect = new Rectangle(975, 0, 24, 24);
                          Rectangle weaponEmpGfxRect = new Rectangle(1001, 0, 23, 24);
                          int xPos = rect.X + (int)(606 * rect.Width / 1024.0f);
                          int yPos = rect.Bottom - BaseGame.YToRes(20) -
                                  TextureFont.Height / 3;
                          TextureFont.WriteText(xPos, yPos, "Weapon: ");
                          // Show weapon icon!
                          //tst: Player.currentWeapon = Player.WeaponTypes.Gattling;
                          Rectangle weaponRect =
                                  Player.currentWeapon == Player.WeaponTypes.MG ? weaponMgGfxRect :
                                  Player.currentWeapon == Player.WeaponTypes.Gattling ? weaponGattlingGfxRect :
                                  Player.currentWeapon == Player.WeaponTypes.Plasma ? weaponPlasmaGfxRect :
                                  weaponRocketsGfxRect;
                          hudBottomTexture.RenderOnScreen(
                                  new Rectangle(
                                  rect.X + (int)(715 * rect.Width / 1024.0f),
                                  rect.Bottom - BaseGame.YToRes(30),
                                  (int)((weaponRect.Width - 2) * rect.Width / 1024.0f),
                                  BaseGame.YToRes(weaponRect.Height - 2)),
                                  weaponRect);
                          // And weapon name
                          xPos += BaseGame.XToRes(747 - 606);
                          TextureFont.WriteText(xPos, yPos, Player.currentWeapon.ToString());
                          xPos += BaseGame.XToRes(854 - 747);
                          TextureFont.WriteText(xPos, yPos, "EMPs: ");
                          // Show emp icons if we have any
                          //tst:Player.empBombs = 3;
                          xPos = rect.Right - BaseGame.XToRes(1024 - 932);
                          yPos = rect.Y + BaseGame.YToRes(10);// (int)((768 - 31) * rect.Height / 768.0f);
                          for (int num = 0; num < Player.empBombs; num++)
                                  hudBottomTexture.RenderOnScreen(
                                          new Rectangle(xPos + BaseGame.XToRes(24 * num), yPos,
                                          BaseGame.XToRes(weaponEmpGfxRect.Width),
                                          BaseGame.XToRes(weaponEmpGfxRect.Height)),
                                          weaponEmpGfxRect);
                  } // ShowHudControls()
                  #endregion
  
                  #region Run
  
<summary> Run game screen. Called each frame. </summary> <param name="game">Form for access to asteroid manager and co</param> public void Run(YourGame game) { // Make sure the textures are linked correctly hudTopTexture = game.hudTopTexture; hudBottomTexture = game.hudBottomTexture;

                          // Enable alpha blending for all controls
                          BaseGame.EnableAlphaBlending();
  
                          // Kill background
                          BaseGame.Device.Clear(Color.Black);
  
                          // Show hud
                          ShowHudControls();
  
                          //TODO: handle game logic here and display landscape, ships, effects, etc.
  
                          // End game if escape was pressed or game is over and space or mouse
                          // button was pressed.
                          if (Input.KeyboardEscapeJustPressed ||
                                  Input.GamePadBackJustPressed ||
                                  (Player.GameOver &&
                                  (Input.Keyboard.IsKeyDown(Keys.Space) ||
                                  Input.GamePadAPressed ||
                                  Input.GamePadBPressed ||
                                  Input.GamePadXPressed ||
                                  Input.GamePadXPressed ||
                                  Input.MouseLeftButtonPressed)))
                          {
                                  //TODO: quit game
  
                                  // Quit to the main menu
                                  quit = true;
                          } // if
                  } // Run(game)
                  #endregion
          } // class Mission
  } // namespace XnaGraphicEngine.GameScreens
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.