Exemplo n.º 1
0
        public Animation()
        {
            alRest = new AnimationLoop(0, 59);
            alRest.FrameSpeed = 30;
            alWalk = new AnimationLoop(60, 119);
            alWalk.FrameSpeed = 80;
            alCombat = new AnimationLoop(120, 149);
            alCombat.FrameSpeed = 30;

            SetAnimation(BehaviorFSM.None);
        }
Exemplo n.º 2
0
        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;
                    }
                }
            }
        }
Exemplo n.º 3
0
 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;
     }
 }
Exemplo n.º 4
0
 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;
     }
 }
Exemplo n.º 5
0
        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;
                    }
                }
            }
        }
Exemplo n.º 6
0
        public override void Init(GameState s, GameplayController c, object args)
        {
            state = s;

            initArgs = args == null ? null : args as AnimationInitArgs;
            if(initArgs == null) initArgs = AnimationInitArgs.Default;

            alRest = new AnimationLoop(initArgs.Splices[0].X, initArgs.Splices[0].Y);
            alRest.FrameSpeed = initArgs.Speeds[0];
            alWalk = new AnimationLoop(initArgs.Splices[1].X, initArgs.Splices[1].Y);
            alWalk.FrameSpeed = initArgs.Speeds[1];
            alMelee = new AnimationLoop(initArgs.Splices[2].X, initArgs.Splices[2].Y);
            alMelee.FrameSpeed = initArgs.Speeds[2];
            alPrepareFire = new AnimationLoop(initArgs.Splices[3].X, initArgs.Splices[3].Y);
            alPrepareFire.FrameSpeed = initArgs.Speeds[3];
            alFire = new AnimationLoop(initArgs.Splices[4].X, initArgs.Splices[4].Y);
            alFire.FrameSpeed = initArgs.Speeds[4];
            alDeath = new AnimationLoop(initArgs.Splices[5].X, initArgs.Splices[5].Y);
            alDeath.FrameSpeed = initArgs.Speeds[5];
            SetAnimation(BehaviorFSM.None);

            System.Threading.Interlocked.Exchange(ref isInit, 1);
        }