]> Dogcows Code - chaz/carfire/commitdiff
Basic HUD... Feel free to completely redo it. Not sure how it'll work
authorKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Mon, 26 Apr 2010 02:41:46 +0000 (02:41 +0000)
committerKyle <Kyle@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Mon, 26 Apr 2010 02:41:46 +0000 (02:41 +0000)
with more than one player.

git-svn-id: https://bd85.net/svn/cs3505_group@148 92bb83a3-7c8f-8a45-bc97-515c4e399668

CarFire/CarFire/CarFire/CarFire.csproj
CarFire/CarFire/CarFire/Display.cs
CarFire/CarFire/CarFire/HUD.cs [new file with mode: 0644]

index e59c3df7ea62783a3454ffc0fb0806a44ebac0c7..e83bbdd5e45cb71a61e42f39e5f267883c96c38c 100644 (file)
@@ -85,6 +85,7 @@
   </ItemGroup>\r
   <ItemGroup>\r
     <Compile Include="GameLogic.cs" />\r
+    <Compile Include="HUD.cs" />\r
     <Compile Include="IEntity.cs" />\r
     <Compile Include="Key.cs" />\r
     <Compile Include="Melee.cs" />\r
index c6ae062c2ad93fa57cbedcb031d0647c7e2952d0..ed848fa31d07596d970b868cf8c55336765e1102 100644 (file)
@@ -24,6 +24,7 @@ namespace CarFire
         Texture2D projectile1;\r
         Game mGame;\r
         GameLogic mGameLogic;\r
+        HUD theHUD;\r
 #if SINGLE_TEST\r
         List<Keys> mLastPressedKeys = new List<Keys>();\r
 #endif\r
@@ -31,6 +32,7 @@ namespace CarFire
         {\r
             mGame = game;\r
             mGameLogic = new GameLogic(game);\r
+            theHUD = new HUD(game);\r
             /*\r
             mMap = aMap;\r
             mCharacters = characters;\r
@@ -45,6 +47,7 @@ namespace CarFire
         {\r
             everything = contentManager.Load<Texture2D>("cs");\r
             projectile1 = contentManager.Load<Texture2D>("projectile");\r
+            theHUD.LoadContent(contentManager);\r
         }\r
 \r
         /// <summary>\r
@@ -93,6 +96,8 @@ namespace CarFire
                     \r
                 }\r
             }\r
+            theHUD.Draw(spriteBatch);\r
+\r
             \r
         }\r
         \r
diff --git a/CarFire/CarFire/CarFire/HUD.cs b/CarFire/CarFire/CarFire/HUD.cs
new file mode 100644 (file)
index 0000000..5b7ffec
--- /dev/null
@@ -0,0 +1,47 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Content;\r
+using Microsoft.Xna.Framework.Graphics;\r
+using Microsoft.Xna.Framework.Input;\r
+\r
+namespace CarFire\r
+{\r
+    class HUD\r
+    {\r
+        Game mGame;\r
+        SpriteFont HUDfont;\r
+        public HUD(Game game)\r
+        {\r
+            mGame = game;\r
+        }\r
+        public void LoadContent(ContentManager contentManager)\r
+        {\r
+            HUDfont = contentManager.Load<SpriteFont>("menuFont");\r
+        }\r
+        /// <summary>\r
+        /// This is called when the game should draw itself.\r
+        /// </summary>\r
+        /// <param name="spriteBatch">Used to draw with</param>\r
+        public void Draw(SpriteBatch spriteBatch)\r
+        {\r
+            Color[] playerColors = new Color[4];\r
+            playerColors[0] = Color.Red;\r
+            playerColors[1] = Color.PowderBlue;\r
+            playerColors[2] = Color.Peru;\r
+            playerColors[3] = Color.Wheat;\r
+            spriteBatch.GraphicsDevice.RenderState.AlphaBlendEnable = true;\r
+            spriteBatch.GraphicsDevice.RenderState.SourceBlend = Blend.One;\r
+            spriteBatch.GraphicsDevice.RenderState.DestinationBlend = Blend.One;\r
+            for (int i = 0; i < mGame.State.mCharacters.Length; i++ )\r
+            {\r
+                Player player = mGame.State.mCharacters[i];\r
+                spriteBatch.DrawString(HUDfont, "Player" + (i+1), new Vector2(640, 10 + 80*i), playerColors[i]);\r
+                spriteBatch.DrawString(HUDfont, "Health: " + player.Health, new Vector2(640, 30 + 80 * i), playerColors[i]);\r
+                spriteBatch.DrawString(HUDfont, "Score: " + player.Score, new Vector2(640, 50 + 80 * i), playerColors[i]);\r
+            }\r
+        }\r
+    }\r
+}\r
This page took 0.028658 seconds and 4 git commands to generate.