2
0

TexturedDrawableGameComponent.cs 2.5 KB

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