From: Kyle Date: Mon, 26 Apr 2010 02:41:46 +0000 (+0000) Subject: Basic HUD... Feel free to completely redo it. Not sure how it'll work X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=0e79580156b8233b17ab4e563dec20befcf08be1;p=chaz%2Fcarfire Basic HUD... Feel free to completely redo it. Not sure how it'll work with more than one player. git-svn-id: https://bd85.net/svn/cs3505_group@148 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- diff --git a/CarFire/CarFire/CarFire/CarFire.csproj b/CarFire/CarFire/CarFire/CarFire.csproj index e59c3df..e83bbdd 100644 --- a/CarFire/CarFire/CarFire/CarFire.csproj +++ b/CarFire/CarFire/CarFire/CarFire.csproj @@ -85,6 +85,7 @@ + diff --git a/CarFire/CarFire/CarFire/Display.cs b/CarFire/CarFire/CarFire/Display.cs index c6ae062..ed848fa 100644 --- a/CarFire/CarFire/CarFire/Display.cs +++ b/CarFire/CarFire/CarFire/Display.cs @@ -24,6 +24,7 @@ namespace CarFire Texture2D projectile1; Game mGame; GameLogic mGameLogic; + HUD theHUD; #if SINGLE_TEST List mLastPressedKeys = new List(); #endif @@ -31,6 +32,7 @@ namespace CarFire { mGame = game; mGameLogic = new GameLogic(game); + theHUD = new HUD(game); /* mMap = aMap; mCharacters = characters; @@ -45,6 +47,7 @@ namespace CarFire { everything = contentManager.Load("cs"); projectile1 = contentManager.Load("projectile"); + theHUD.LoadContent(contentManager); } /// @@ -93,6 +96,8 @@ namespace CarFire } } + theHUD.Draw(spriteBatch); + } diff --git a/CarFire/CarFire/CarFire/HUD.cs b/CarFire/CarFire/CarFire/HUD.cs new file mode 100644 index 0000000..5b7ffec --- /dev/null +++ b/CarFire/CarFire/CarFire/HUD.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework.Input; + +namespace CarFire +{ + class HUD + { + Game mGame; + SpriteFont HUDfont; + public HUD(Game game) + { + mGame = game; + } + public void LoadContent(ContentManager contentManager) + { + HUDfont = contentManager.Load("menuFont"); + } + /// + /// This is called when the game should draw itself. + /// + /// Used to draw with + public void Draw(SpriteBatch spriteBatch) + { + Color[] playerColors = new Color[4]; + playerColors[0] = Color.Red; + playerColors[1] = Color.PowderBlue; + playerColors[2] = Color.Peru; + playerColors[3] = Color.Wheat; + spriteBatch.GraphicsDevice.RenderState.AlphaBlendEnable = true; + spriteBatch.GraphicsDevice.RenderState.SourceBlend = Blend.One; + spriteBatch.GraphicsDevice.RenderState.DestinationBlend = Blend.One; + for (int i = 0; i < mGame.State.mCharacters.Length; i++ ) + { + Player player = mGame.State.mCharacters[i]; + spriteBatch.DrawString(HUDfont, "Player" + (i+1), new Vector2(640, 10 + 80*i), playerColors[i]); + spriteBatch.DrawString(HUDfont, "Health: " + player.Health, new Vector2(640, 30 + 80 * i), playerColors[i]); + spriteBatch.DrawString(HUDfont, "Score: " + player.Score, new Vector2(640, 50 + 80 * i), playerColors[i]); + } + } + } +}