Advertisement
Chronos_Ouroboros

Actor class thing

Nov 29th, 2015
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using SFML.Audio;
  6.  
  7. namespace SpaceShooterGameThingy {
  8.     public class Actor {
  9.         #region Getters/Setters
  10.         public State [] StateTable {
  11.             get {
  12.                 return _statesTable;
  13.             }
  14.         }
  15.         public uint CurrentState {
  16.             get {
  17.                 return _currentState;
  18.             }
  19.         }
  20.         public Dictionary<string, uint> StateLabels {
  21.             get {
  22.                 return _stateLabels;
  23.             }
  24.         }
  25.         #endregion
  26.         #region Public variables
  27.         public short Health;
  28.         public short Height;
  29.         public short Width;
  30.         #endregion
  31.         #region Private variables
  32.         private State [] _statesTable;
  33.         private uint _ticTimeLeft;
  34.         private uint _currentState;
  35.         private Dictionary<string, uint> _stateLabels;
  36.         #endregion
  37.  
  38.         public Actor (State [] newStatesTable, Dictionary <string, uint> newStateLabels) {
  39.             if (newStatesTable.Length < 1)
  40.                 throw new ArgumentException ("Actor: States table must have at least one state!");
  41.             this._statesTable = newStatesTable;
  42.             this._ticTimeLeft = _statesTable [0].Length;
  43.             this._currentState = 0;
  44.             this._stateLabels = newStateLabels;
  45.  
  46.             SetDefaults ();
  47.         }
  48.  
  49.         private void SetDefaults () {
  50.             Health = 1000;
  51.             Height = 16;
  52.             Width = 32;
  53.         }
  54.  
  55.         public void SetState (uint StateNumber) {
  56.             _currentState = StateNumber;
  57.             _ticTimeLeft = _statesTable [_currentState].Length;
  58.         }
  59.  
  60.         public void RunState (uint StateNumber) {
  61.             this.SetState (this._statesTable [_currentState].NextState);
  62.             if (_statesTable [_currentState].StateAction != null)
  63.                 this._statesTable [_currentState].StateAction.Run (this);
  64.         }
  65.  
  66.         public void Think () {
  67.             if (this._ticTimeLeft > 0)
  68.                 this._ticTimeLeft--;
  69.             else
  70.                 while (this._ticTimeLeft == 0) {
  71.                    
  72.                 }
  73.         }
  74.  
  75.         public void Die () {
  76.             if (_stateLabels.ContainsKey ("Death"))
  77.                 RunState (_stateLabels ["Death"]);
  78.         }
  79.     }
  80.  
  81.     public struct State {
  82.         public uint Length;
  83.         public string SpriteName;
  84.         public uint NextState;
  85.         public ActionFunction StateAction;
  86.         public State (uint Length, string SpriteName, uint NextState, ActionFunction StateAction) {
  87.             this.Length = Length;
  88.             this.SpriteName = SpriteName;
  89.             this.NextState = NextState;
  90.             this.StateAction = StateAction;
  91.         }
  92.     }
  93.  
  94.     public abstract class ActionFunction {
  95.         Type type;
  96.         public abstract bool Run (Actor _actor);
  97.     }
  98.  
  99.     public class A_Die : ActionFunction {
  100.         public override bool Run (Actor _actor) {
  101.             _actor.Health = 0;
  102.             _actor.Die ();
  103.             return true;
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement