Score.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #region Using Statements
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Graphics;
  4. #endregion
  5. namespace RockRainIphone
  6. {
  7. /// <summary>
  8. /// This is a game component that implements the Game Score.
  9. /// </summary>
  10. public class Score : DrawableGameComponent
  11. {
  12. // Spritebatch
  13. protected SpriteBatch spriteBatch = null;
  14. // Score Position
  15. protected Vector2 position = new Vector2();
  16. // Values
  17. protected int value;
  18. protected int power;
  19. protected readonly SpriteFont font;
  20. protected readonly Color fontColor;
  21. public Score(Game game, SpriteFont font, Color fontColor)
  22. : base(game)
  23. {
  24. this.font = font;
  25. this.fontColor = fontColor;
  26. // Get the current spritebatch
  27. spriteBatch = (SpriteBatch)
  28. Game.Services.GetService(typeof (SpriteBatch));
  29. }
  30. /// <summary>
  31. /// Points value
  32. /// </summary>
  33. public int Value
  34. {
  35. get { return value; }
  36. set { this.value = value; }
  37. }
  38. /// <summary>
  39. /// Power Value
  40. /// </summary>
  41. public int Power
  42. {
  43. get { return power; }
  44. set { power = value; }
  45. }
  46. /// <summary>
  47. /// Position of component in screen
  48. /// </summary>
  49. public Vector2 Position
  50. {
  51. get { return position; }
  52. set { position = value; }
  53. }
  54. /// <summary>
  55. /// Allows the game component to draw itself.
  56. /// </summary>
  57. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  58. public override void Draw(GameTime gameTime)
  59. {
  60. string TextToDraw = string.Format("Score: {0}", value);
  61. // Draw the text shadow
  62. spriteBatch.DrawString(font, TextToDraw, new Vector2(position.X + 1,
  63. position.Y + 1), Color.Black);
  64. // Draw the text item
  65. spriteBatch.DrawString(font, TextToDraw,
  66. new Vector2(position.X, position.Y),
  67. fontColor);
  68. TextToDraw = string.Format("Power: {0}", power);
  69. // Draw the text shadow
  70. spriteBatch.DrawString(font, TextToDraw,
  71. new Vector2(position.X + 151, position.Y + 1),
  72. Color.Black);
  73. // Draw the text item
  74. spriteBatch.DrawString(font, TextToDraw,
  75. new Vector2(position.X+150, position.Y),
  76. fontColor);
  77. base.Draw(gameTime);
  78. }
  79. }
  80. }