PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/Engine/Game/Actor.cs

#
C# | 207 lines | 109 code | 19 blank | 79 comment | 0 complexity | 58cc7f77a1db4bc954ff10ee306e5213 MD5 | raw file
Possible License(s): Apache-2.0
  1. using Delta.Utilities.Datatypes;
  2. namespace Delta.Engine.Game
  3. {
  4. /// <summary>
  5. /// Basic actor class with state machine.
  6. /// Actor, still needs to be merged with the game code from all the games
  7. /// currently in development. This class is really old and will change soon!
  8. /// </summary>
  9. public abstract class Actor
  10. {
  11. #region State (Public)
  12. /// <summary>
  13. /// State
  14. /// </summary>
  15. /// <value>
  16. /// The state.
  17. /// </value>
  18. public string State
  19. {
  20. get
  21. {
  22. return currentState;
  23. }
  24. set
  25. {
  26. EndState(currentState, value);
  27. BeginState(currentState, value);
  28. currentState = value;
  29. }
  30. }
  31. #endregion
  32. #region WorldPosition (Public)
  33. /// <summary>
  34. /// World position
  35. /// </summary>
  36. /// <value>
  37. /// The world position.
  38. /// </value>
  39. public Vector WorldPosition
  40. {
  41. protected set;
  42. get;
  43. }
  44. #endregion
  45. #region WorldRotation (Public)
  46. /// <summary>
  47. /// World rotation
  48. /// </summary>
  49. /// <value>
  50. /// The world rotation.
  51. /// </value>
  52. public float WorldRotation
  53. {
  54. protected set;
  55. get;
  56. }
  57. #endregion
  58. #region OwnerWorld (Public)
  59. /// <summary>
  60. /// The world that this actor is part of
  61. /// </summary>
  62. public World OwnerWorld;
  63. #endregion
  64. #region Private
  65. #region currentState (Private)
  66. /// <summary>
  67. /// The current state for the state machine
  68. /// </summary>
  69. private string currentState;
  70. #endregion
  71. #endregion
  72. #region Constructors
  73. /// <summary>
  74. /// Create actor
  75. /// </summary>
  76. /// <param name="setOwnerWorld">Set owner world.</param>
  77. public Actor(World setOwnerWorld)
  78. {
  79. OwnerWorld = setOwnerWorld;
  80. }
  81. #endregion
  82. #region Spawned (Public)
  83. /// <summary>
  84. /// Automatically called by the engine after the actor has been spawned.
  85. /// May be overriden in derived classes.
  86. /// </summary>
  87. public virtual void Spawned()
  88. {
  89. // Does nothing here, but may be overridden in derived classes.
  90. }
  91. #endregion
  92. #region Despawned (Public)
  93. /// <summary>
  94. /// Automatically called by the engine after the actor has been despawned.
  95. /// May be overriden in derived classes.
  96. /// </summary>
  97. public virtual void Despawned()
  98. {
  99. // Does nothing here, but may be overridden in derived classes.
  100. }
  101. #endregion
  102. #region Destroy (Public)
  103. /// <summary>
  104. /// Destroy
  105. /// </summary>
  106. public void Destroy()
  107. {
  108. OwnerWorld.DespawnActor(this);
  109. }
  110. #endregion
  111. #region CollidesWith (Public)
  112. /// <summary>
  113. /// Collides with
  114. /// </summary>
  115. /// <param name="otherActor">The other actor.</param>
  116. public virtual void CollidesWith(Actor otherActor)
  117. {
  118. //Log.Info(this + " collides with " + otherActor);
  119. }
  120. #endregion
  121. #region SetPosition (Public)
  122. /// <summary>
  123. /// Set position
  124. /// </summary>
  125. /// <param name="newPosition">The new position.</param>
  126. public void SetPosition(Vector newPosition)
  127. {
  128. WorldPosition = newPosition;
  129. }
  130. #endregion
  131. #region SetRotation (Public)
  132. /// <summary>
  133. /// Set rotation
  134. /// </summary>
  135. /// <param name="newRotation">The new rotation.</param>
  136. public void SetRotation(float newRotation)
  137. {
  138. WorldRotation = newRotation;
  139. }
  140. #endregion
  141. #region Tick (Public)
  142. /// <summary>
  143. /// Tick function. Allows the actor to do tick-based logic.
  144. /// </summary>
  145. public virtual void Tick()
  146. {
  147. // Tick the state machine
  148. TickState();
  149. }
  150. #endregion
  151. #region Render (Public)
  152. /// <summary>
  153. /// Render function. Allows the actor to do custom rendering logic.
  154. /// </summary>
  155. public virtual void Render()
  156. {
  157. }
  158. #endregion
  159. #region BeginState (Public)
  160. /// <summary>
  161. /// Begin state
  162. /// </summary>
  163. /// <param name="lastState">The last state.</param>
  164. /// <param name="newState">The new state.</param>
  165. public virtual void BeginState(string lastState, string newState)
  166. {
  167. }
  168. #endregion
  169. #region TickState (Public)
  170. /// <summary>
  171. /// Tick state
  172. /// </summary>
  173. public virtual void TickState()
  174. {
  175. }
  176. #endregion
  177. #region EndState (Public)
  178. /// <summary>
  179. /// End state
  180. /// </summary>
  181. /// <param name="state">The state.</param>
  182. /// <param name="newState">The new state.</param>
  183. public virtual void EndState(string state, string newState)
  184. {
  185. }
  186. #endregion
  187. }
  188. }