Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using SFML.Audio;
- namespace SpaceShooterGameThingy {
- public class Actor {
- #region Getters/Setters
- public State [] StateTable {
- get {
- return _statesTable;
- }
- }
- public uint CurrentState {
- get {
- return _currentState;
- }
- }
- public Dictionary<string, uint> StateLabels {
- get {
- return _stateLabels;
- }
- }
- #endregion
- #region Public variables
- public short Health;
- public short Height;
- public short Width;
- #endregion
- #region Private variables
- private State [] _statesTable;
- private uint _ticTimeLeft;
- private uint _currentState;
- private Dictionary<string, uint> _stateLabels;
- #endregion
- public Actor (State [] newStatesTable, Dictionary <string, uint> newStateLabels) {
- if (newStatesTable.Length < 1)
- throw new ArgumentException ("Actor: States table must have at least one state!");
- this._statesTable = newStatesTable;
- this._ticTimeLeft = _statesTable [0].Length;
- this._currentState = 0;
- this._stateLabels = newStateLabels;
- SetDefaults ();
- }
- private void SetDefaults () {
- Health = 1000;
- Height = 16;
- Width = 32;
- }
- public void SetState (uint StateNumber) {
- _currentState = StateNumber;
- _ticTimeLeft = _statesTable [_currentState].Length;
- }
- public void RunState (uint StateNumber) {
- this.SetState (this._statesTable [_currentState].NextState);
- if (_statesTable [_currentState].StateAction != null)
- this._statesTable [_currentState].StateAction.Run (this);
- }
- public void Think () {
- if (this._ticTimeLeft > 0)
- this._ticTimeLeft--;
- else
- while (this._ticTimeLeft == 0) {
- }
- }
- public void Die () {
- if (_stateLabels.ContainsKey ("Death"))
- RunState (_stateLabels ["Death"]);
- }
- }
- public struct State {
- public uint Length;
- public string SpriteName;
- public uint NextState;
- public ActionFunction StateAction;
- public State (uint Length, string SpriteName, uint NextState, ActionFunction StateAction) {
- this.Length = Length;
- this.SpriteName = SpriteName;
- this.NextState = NextState;
- this.StateAction = StateAction;
- }
- }
- public abstract class ActionFunction {
- Type type;
- public abstract bool Run (Actor _actor);
- }
- public class A_Die : ActionFunction {
- public override bool Run (Actor _actor) {
- _actor.Health = 0;
- _actor.Die ();
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement