PageRenderTime 130ms CodeModel.GetById 60ms app.highlight 5ms RepoModel.GetById 56ms app.codeStats 7ms

/Engine/Game/Actor.cs

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