public override void Update(GameState s, float dt) { if (lastState != unit.State) { // A New Animation State If Provided SetAnimation(unit.State); if (lastState == BehaviorFSM.None) { rt = r.Next(120, 350) / 10f; } } // Save Last State lastState = unit.State; // Step The Current Animation if (alCurrent != null) { alCurrent.Step(dt); AnimationFrame = alCurrent.CurrentFrame; } if (lastState == BehaviorFSM.None) { // Check For A Random Animation if (alCurrent == null) { rt -= dt; if (rt <= 0) { rt = r.Next(120, 350) / 10f; alCurrent = alRest; alCurrent.Restart(false); } } else { // Check If At The End Of The Loop if (AnimationFrame == alCurrent.EndFrame) { alCurrent = null; rt = r.Next(120, 350) / 10f; } } } }
private void SetAnimation(int state) { switch (state) { case BehaviorFSM.None: alCurrent = null; AnimationFrame = 0; break; case BehaviorFSM.Walking: alCurrent = alWalk; alCurrent.Restart(true); break; case BehaviorFSM.PrepareCombatRanged: alCurrent = alPrepareFire; alCurrent.Restart(false); break; case BehaviorFSM.CombatRanged: alCurrent = alFire; alCurrent.Restart(false); break; case BehaviorFSM.CombatMelee: alCurrent = alMelee; alCurrent.Restart(true); break; case BehaviorFSM.Rest: alCurrent = alRest; alCurrent.Restart(true); break; default: alCurrent = null; return; } }
private void SetAnimation(int state) { switch (state) { case BehaviorFSM.Walking: alCurrent = alWalk; alCurrent.Restart(true); break; case BehaviorFSM.CombatMelee: alCurrent = alCombat; alCurrent.Restart(true); break; case BehaviorFSM.Rest: alCurrent = alRest; alCurrent.Restart(true); break; default: alCurrent = null; return; } }
public override void Update(GameState s, float dt) { if (System.Threading.Interlocked.CompareExchange(ref isInit, 1, 1) == 0) { return; } if (addBlood) { Splurt(s.TotalGameTime); addBlood = false; } // Animate Death if (!unit.IsAlive) { if (AnimationFrame == alDeath.EndFrame) { return; } alDeath.Step(dt); AnimationFrame = alDeath.CurrentFrame; return; } if (lastState != unit.State) { // A New Animation State If Provided SetAnimation(unit.State); if (lastState == BehaviorFSM.None) { rt = r.Next(120, 350) / 10f; } } // Save Last State lastState = unit.State; // Step The Current Animation if (alCurrent != null) { alCurrent.Step(dt); AnimationFrame = alCurrent.CurrentFrame; } if (lastState == BehaviorFSM.None) { // Check For A Random Animation if (alCurrent == null) { rt -= dt; if (rt <= 0) { rt = r.Next(120, 350) / 10f; alCurrent = alRest; alCurrent.Restart(false); } } else { // Check If At The End Of The Loop if (AnimationFrame == alCurrent.EndFrame) { alCurrent = null; rt = r.Next(120, 350) / 10f; } } } }