CollideElement.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // CollideElement.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;
  11. using System.Collections.Generic;
  12. using System.Text;
  13. using Microsoft.Xna.Framework;
  14. using Microsoft.Xna.Framework.Graphics;
  15. using RobotGameData.GameInterface;
  16. #endregion
  17. namespace RobotGameData.Collision
  18. {
  19. /// <summary>
  20. /// It's a basic element of collision.
  21. /// </summary>
  22. public abstract class CollideElement : INamed
  23. {
  24. #region Fields
  25. protected string name = String.Empty;
  26. protected int id = 0;
  27. protected Matrix transformMatrix = Matrix.Identity;
  28. protected object owner = null;
  29. protected CollisionLayer parentLayer = null;
  30. #endregion
  31. #region Properties
  32. public string Name
  33. {
  34. get { return name; }
  35. set { name = value; }
  36. }
  37. public int Id
  38. {
  39. get
  40. {
  41. if (id == 0)
  42. {
  43. id = GetHashCode();
  44. }
  45. return id;
  46. }
  47. set { id = value; }
  48. }
  49. public Matrix TransformMatrix
  50. {
  51. get { return transformMatrix; }
  52. }
  53. public CollisionLayer ParentLayer
  54. {
  55. get { return parentLayer; }
  56. set { parentLayer = value; }
  57. }
  58. public object Owner
  59. {
  60. get { return owner; }
  61. set { owner = value; }
  62. }
  63. #endregion
  64. /// <summary>
  65. /// Removes this element in the collison layer.
  66. /// </summary>
  67. public void RemoveInLayer()
  68. {
  69. if (parentLayer != null)
  70. {
  71. parentLayer.RemoveCollide(this);
  72. parentLayer = null;
  73. }
  74. }
  75. /// <summary>
  76. /// Set to new transform matrix.
  77. /// </summary>
  78. public virtual void Transform(Matrix matrix)
  79. {
  80. transformMatrix = matrix;
  81. }
  82. }
  83. }