You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
using System; using System.Collections.Generic;
namespace SemiColinGames { public interface IState { public void Enter(); public string? Update(NPC npc, float modelTime, AABB[] collisionTargets); }
public class FSM { float timeInState = 0f; Dictionary<string, IState> states; IState state;
public FSM(Dictionary<string, IState> states, string initial) { this.states = states; StateName = initial; Transition(StateName); }
public string StateName { get; private set; }
public void Update(NPC npc, float modelTime, AABB[] collisionTargets) { timeInState += modelTime; string? newState = state.Update(npc, modelTime, collisionTargets); if (newState != null) { Transition(newState); } }
void Transition(string state) { Debug.WriteLine("{0} -> {1} @ {2}", StateName, state, timeInState); timeInState = 0f; StateName = state; IState newState = states[state]; this.state = newState; this.state.Enter(); } } }
|