/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
- using Delta.Utilities.Datatypes;
-
- namespace Delta.Engine.Game
- {
- /// <summary>
- /// Basic actor class with state machine.
- /// Actor, still needs to be merged with the game code from all the games
- /// currently in development. This class is really old and will change soon!
- /// </summary>
- public abstract class Actor
- {
- #region State (Public)
- /// <summary>
- /// State
- /// </summary>
- /// <value>
- /// The state.
- /// </value>
- public string State
- {
- get
- {
- return currentState;
- }
- set
- {
- EndState(currentState, value);
- BeginState(currentState, value);
- currentState = value;
- }
- }
- #endregion
-
- #region WorldPosition (Public)
- /// <summary>
- /// World position
- /// </summary>
- /// <value>
- /// The world position.
- /// </value>
- public Vector WorldPosition
- {
- protected set;
- get;
- }
- #endregion
-
- #region WorldRotation (Public)
- /// <summary>
- /// World rotation
- /// </summary>
- /// <value>
- /// The world rotation.
- /// </value>
- public float WorldRotation
- {
- protected set;
- get;
- }
- #endregion
-
- #region OwnerWorld (Public)
- /// <summary>
- /// The world that this actor is part of
- /// </summary>
- public World OwnerWorld;
- #endregion
-
- #region Private
-
- #region currentState (Private)
- /// <summary>
- /// The current state for the state machine
- /// </summary>
- private string currentState;
- #endregion
-
- #endregion
-
- #region Constructors
- /// <summary>
- /// Create actor
- /// </summary>
- /// <param name="setOwnerWorld">Set owner world.</param>
- public Actor(World setOwnerWorld)
- {
- OwnerWorld = setOwnerWorld;
- }
- #endregion
-
- #region Spawned (Public)
- /// <summary>
- /// Automatically called by the engine after the actor has been spawned.
- /// May be overriden in derived classes.
- /// </summary>
- public virtual void Spawned()
- {
- // Does nothing here, but may be overridden in derived classes.
- }
- #endregion
-
- #region Despawned (Public)
- /// <summary>
- /// Automatically called by the engine after the actor has been despawned.
- /// May be overriden in derived classes.
- /// </summary>
- public virtual void Despawned()
- {
- // Does nothing here, but may be overridden in derived classes.
- }
- #endregion
-
- #region Destroy (Public)
- /// <summary>
- /// Destroy
- /// </summary>
- public void Destroy()
- {
- OwnerWorld.DespawnActor(this);
- }
- #endregion
-
- #region CollidesWith (Public)
- /// <summary>
- /// Collides with
- /// </summary>
- /// <param name="otherActor">The other actor.</param>
- public virtual void CollidesWith(Actor otherActor)
- {
- //Log.Info(this + " collides with " + otherActor);
- }
- #endregion
-
- #region SetPosition (Public)
- /// <summary>
- /// Set position
- /// </summary>
- /// <param name="newPosition">The new position.</param>
- public void SetPosition(Vector newPosition)
- {
- WorldPosition = newPosition;
- }
- #endregion
-
- #region SetRotation (Public)
- /// <summary>
- /// Set rotation
- /// </summary>
- /// <param name="newRotation">The new rotation.</param>
- public void SetRotation(float newRotation)
- {
- WorldRotation = newRotation;
- }
- #endregion
-
- #region Tick (Public)
- /// <summary>
- /// Tick function. Allows the actor to do tick-based logic.
- /// </summary>
- public virtual void Tick()
- {
- // Tick the state machine
- TickState();
- }
- #endregion
-
- #region Render (Public)
- /// <summary>
- /// Render function. Allows the actor to do custom rendering logic.
- /// </summary>
- public virtual void Render()
- {
- }
- #endregion
-
- #region BeginState (Public)
- /// <summary>
- /// Begin state
- /// </summary>
- /// <param name="lastState">The last state.</param>
- /// <param name="newState">The new state.</param>
- public virtual void BeginState(string lastState, string newState)
- {
- }
- #endregion
-
- #region TickState (Public)
- /// <summary>
- /// Tick state
- /// </summary>
- public virtual void TickState()
- {
- }
- #endregion
-
- #region EndState (Public)
- /// <summary>
- /// End state
- /// </summary>
- /// <param name="state">The state.</param>
- /// <param name="newState">The new state.</param>
- public virtual void EndState(string state, string newState)
- {
- }
- #endregion
- }
- }