Score.cs 2.6 KB

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