Advertisement
Spectrewiz

HUD

Aug 27th, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.75 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Audio;
  3. using Microsoft.Xna.Framework.Content;
  4. using Microsoft.Xna.Framework.GamerServices;
  5. using Microsoft.Xna.Framework.Graphics;
  6. using Microsoft.Xna.Framework.Input;
  7. using Microsoft.Xna.Framework.Media;
  8. namespace Horror
  9. {
  10.     public class HUD
  11.     {
  12.         private int xStack;
  13.         private int yStack;
  14.         private int xStackCounter;
  15.         public const float redHeartInt = 1.00F;
  16.         public const float yellowHeartInt = 1.33F;
  17.         public const float blackHeartInt = 1.66F;
  18.         enum HeartColor
  19.         {
  20.             Green,
  21.             Red,
  22.             Yellow,
  23.             Black
  24.         }
  25.         public static HeartColor heartColor = HeartColor.Green;
  26.         private Color heartColorObj = new Color();
  27.         private int controllingRec;
  28.         public static Texture2D texture = new Texture2D(Game.graphics.GraphicsDevice, 1, 1),
  29.             nonchangeableTexture = new Texture2D(Game.graphics.GraphicsDevice, 1, 1);
  30.  
  31.         public static Rectangle hbar1 = new Rectangle(0, Game.screen.Height, /*Player.player.Health*/100, 50),
  32.             hbar2 = new Rectangle(0, Game.screen.Height, /*Player.player.maxHealth*/100, 50);
  33.  
  34.         private static void HUD_Layout(SpriteBatch a)
  35.         {
  36.             heartDisplay(a);
  37.  
  38.         }
  39.         private static void heartDisplay(SpriteBatch a)
  40.         {
  41.             if ( /*Player.player.Health*/100 <= (/*Player.player.maxHealth*/100) && /*Player.player.Health*/100 > (/*Player.player.maxHealth*/100) / yellowHeartInt)
  42.             {
  43.                 changeHeartColor(HeartColor.Green);
  44.             }
  45.             else if ( /*Player.player.Health*/100 <= (/*Player.player.maxHealth*/100 / yellowHeartInt) && /*Player.player.Health*/100 > (/*Player.player.maxHealth*/100) / blackHeartInt)
  46.             {
  47.                 changeHeartColor(HeartColor.Yellow);
  48.             }
  49.             else if ( /*Player.player.Health*/100 <= (/*Player.player.maxHealth*/100 / blackHeartInt) && /*Player.player.Health*/100 > 0)
  50.             {
  51.                 changeHeartColor(HeartColor.Red);
  52.             }
  53.             switch (heartColor)
  54.             {
  55.                 case HeartColor.Green:
  56.                     texture.SetData(new[] { Color.Red });
  57.                     break;
  58.                 case HeartColor.Yellow:
  59.                     texture.SetData(new[] { Color.Yellow });
  60.                     break;
  61.                 case HeartColor.Red:
  62.                     texture.SetData(new[] { Color.Black });
  63.                     break;
  64.                 default:
  65.                     texture.SetData(new[] { Color.Red });
  66.                     break;
  67.                     a.DrawString(Game.spriteFont, "- Health[" + /*Player.player.Health*/100 + " / " + /*Player.player.maxHealth*/100 + "]", new Vector2(/*Player.player.maxHealth*/100 + 5, Game.screen.Height), Color.Magenta);
  68.                     a.Draw(texture, hbar1, Color.White);
  69.                     a.Draw(nonchangeableTexture, hbar2, Color.White);
  70.             }
  71.         }
  72.         public static void changeHeartColor(HeartColor heartColor)
  73.         {
  74.             /*The reason I'm using different variables even
  75.              * though I could've made a few Objs
  76.              * is because I have some cool
  77.              * item ideas that influence
  78.              * how your health bar acts!
  79.              */
  80.             if (heartColor == HeartColor.Green)
  81.             {
  82.                 HUD.heartColor = HeartColor.Green;
  83.             }
  84.             if (heartColor == HeartColor.Yellow)
  85.             {
  86.                 HUD.heartColor = HeartColor.Yellow;
  87.             }
  88.             if (heartColor == HeartColor.Red)
  89.             {
  90.                 HUD.heartColor = HeartColor.Red;
  91.             }
  92.         }
  93.     }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement