TexturedDrawableGameComponent.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //-----------------------------------------------------------------------------
  2. // TexturedDrawableGameComponent.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System.Collections.Generic;
  8. using Microsoft.Xna.Framework;
  9. using Microsoft.Xna.Framework.Graphics;
  10. namespace HoneycombRush
  11. {
  12. /// <summary>
  13. /// This abstract class represent a component which has a texture that represents it visually.
  14. /// </summary>
  15. public abstract class TexturedDrawableGameComponent : DrawableGameComponent
  16. {
  17. protected ScaledSpriteBatch scaledSpriteBatch;
  18. protected Texture2D texture;
  19. protected Vector2 position;
  20. protected GameplayScreen gamePlayScreen;
  21. /// <summary>
  22. /// Represents the bounds of the component.
  23. /// </summary>
  24. public virtual Rectangle Bounds
  25. {
  26. get
  27. {
  28. if (texture == null)
  29. {
  30. return default(Rectangle);
  31. }
  32. else
  33. {
  34. return new Rectangle((int)position.X, (int)position.Y,
  35. (int)(texture.Width * scaledSpriteBatch.ScaleVector.X),
  36. (int)(texture.Height * scaledSpriteBatch.ScaleVector.Y));
  37. }
  38. }
  39. }
  40. /// <summary>
  41. /// Represents an area used for collision calculations.
  42. /// </summary>
  43. public virtual Rectangle CentralCollisionArea
  44. {
  45. get
  46. {
  47. return default(Rectangle);
  48. }
  49. }
  50. public Dictionary<string, ScaledAnimation> AnimationDefinitions { get; set; }
  51. /// <summary>
  52. /// Creates a new instance.
  53. /// </summary>
  54. /// <param name="game">Associated game object.</param>
  55. /// <param name="gamePlayScreen">Gameplay screen where the component will be presented.</param>
  56. public TexturedDrawableGameComponent(Game game, GameplayScreen gamePlayScreen)
  57. : base(game)
  58. {
  59. this.gamePlayScreen = gamePlayScreen;
  60. scaledSpriteBatch = (ScaledSpriteBatch)game.Services.GetService(typeof(ScaledSpriteBatch));
  61. }
  62. }
  63. }