// File : fwAnimat.c // Author : John Wojcik ( QuietBloke ) // Created : August 2000 // Desc : 2D game Framework Animation Manager. // This manager controls the Animations. // Animations are used by the frameowrk to automate // actor costumes, positions etc. They are also available to the // main program if required. Animations are automatically updated // by the director for each screen refresh. // // History : // Date Author Description // -------- --------------- ---------------------------------------- // 05/10/00 J.Wojcik Added a new function to reset the animation List ( ie. Clear it out ). // #include "fwanimat.h" #include "fw.h" typedef struct { int stage; // What stage are we in the animation int type; // Type of animation int initRepeats; // How many times this should be repeated int repeats; // Current repeat counter int minValue; // Minimum allowed animation value int maxValue; // Maximum allowed animation value int currentValue; // Current value of animation int changeValue; // How much the value changes by between frames int initValue; // Value to use when starting animation int finalValue; // Value to have when animation finishes int pauseLeft; // How long to wait before next animation frame int minPause; // Time to wait at min value before next frame int maxPause; // Time to wait at max value before next frame int tweenPause; // Time to wait before next frame at all other times } Animation; Animation AnimationList[MAX_ANIMATIONS]; int NextAnimation = 0; // Next available animation in the list //declare internal functions void fwAnimateBounce ( Animation* anim ); void fwAnimateRepeat ( Animation* anim ); void fwAnimateReset ( void ) { NextAnimation = 0; } int fwAnimateAdd ( int type, int repeats, int value, int minvalue, int maxvalue, int changevalue, int pause ) { int StoreAnimationID; StoreAnimationID = NextAnimation; NextAnimation++; fwAnimateInit ( StoreAnimationID, type, repeats, value, minvalue, maxvalue, changevalue, pause ); return ( StoreAnimationID ); } void fwAnimateInit ( int AnimationID, int type, int repeats, int value, int minvalue, int maxvalue, int changevalue, int pause ) { Animation* Anim; Anim = &AnimationList[AnimationID]; Anim->stage = ANIMATE_STOPPED; Anim->type = type; Anim->initRepeats = repeats; Anim->minValue = minvalue; Anim->maxValue = maxvalue; Anim->changeValue = changevalue; Anim->currentValue = minvalue; Anim->initValue = value; // if ( type == ANIMATE_REPEAT ) Anim->finalValue = maxvalue; // else // Anim->finalValue = minvalue; Anim->minPause = pause; Anim->maxPause = pause; Anim->tweenPause = pause; } void fwAnimateSetPause ( int AnimationID, int minpause, int maxpause, int tweenpause ) { Animation* anim; anim = &AnimationList[AnimationID]; anim->minPause = minpause; anim->maxPause = maxpause; anim->tweenPause = tweenpause; } void fwAnimateStart ( int AnimationID ) { Animation* anim; anim = &AnimationList[AnimationID]; anim->stage = ANIMATE_START; } void fwAnimateStop ( int AnimationID ) { Animation* anim; anim = &AnimationList[AnimationID]; anim->stage = ANIMATE_STOPPED; } void fwAnimateResume ( int AnimationID ) { Animation* anim; anim = &AnimationList[AnimationID]; anim->stage = ANIMATE_RESUME; } // Cycle through and animate All animations void fwAnimate ( void ) { int CurrentAnimationID; Animation* anim; for ( CurrentAnimationID = 0 ; CurrentAnimationID < NextAnimation; CurrentAnimationID++ ) { anim = &AnimationList[CurrentAnimationID]; if ( anim->stage != ANIMATE_STOPPED ) { switch ( anim->stage ) { case ANIMATE_START: anim->currentValue = anim->initValue; anim->repeats = anim->initRepeats; anim->stage = ANIMATE_RUNNING; break; case ANIMATE_RUNNING: // Update the animation. This is dependent on the // type of animation. switch ( anim->type ) { case ANIMATE_BOUNCE: fwAnimateBounce ( anim ); break; case ANIMATE_REPEAT: fwAnimateRepeat ( anim ); break; } break; case ANIMATE_RESUME: anim->stage = ANIMATE_RUNNING; break; case ANIMATE_END: anim->currentValue = anim->finalValue; anim->stage = ANIMATE_STOPPED; break; } } } } void fwAnimateBounce ( Animation* anim ) { // Only stop if animation hits zero. A negative value means // infinate cycles if ( anim->repeats == 0 ) anim->stage = ANIMATE_END; else { anim->pauseLeft--; if ( anim->pauseLeft <= 0 ) { anim->pauseLeft = anim->tweenPause; anim->currentValue += anim->changeValue; if ( anim->currentValue < anim->minValue ) { if ( anim->repeats != -1 ) anim->repeats--; anim->changeValue *= -1; anim->currentValue = anim->minValue; anim->pauseLeft = anim->minPause; } if ( anim->currentValue > anim->maxValue ) { if ( anim->repeats != -1 ) anim->repeats--; anim->currentValue = anim->maxValue; anim->changeValue *= -1; anim->pauseLeft = anim->maxPause; } } } // If what we did has ended the animation then so be it. if ( anim->repeats == 0 ) anim->stage = ANIMATE_END; } void fwAnimateRepeat ( Animation* anim ) { // Only stop if animation hits zero. A negative value means // infinate cycles if ( anim->repeats == 0 ) { printf ( "No more animating\n"); anim->stage = ANIMATE_END; } else { anim->pauseLeft--; if ( anim->pauseLeft <= 0 ) { anim->pauseLeft = anim->tweenPause; anim->currentValue += anim->changeValue; if ( anim->currentValue < anim->minValue ) { if ( anim->repeats != -1 ) anim->repeats--; anim->currentValue = anim->maxValue; anim->pauseLeft = anim->minPause; } if ( anim->currentValue > anim->maxValue ) { if ( anim->repeats != -1 ) anim->repeats--; anim->currentValue = anim->minValue; anim->pauseLeft = anim->maxPause; } } } // If what we did has ended the animation then so be it. if ( anim->repeats == 0 ) { anim->stage = ANIMATE_END; // Set the value for this frame to be the final value of the costume anim->currentValue = anim->finalValue; } } int fwAnimateGetValue ( int AnimationID ) { if ( AnimationID == -1 ) return (0); else return ( AnimationList[AnimationID].currentValue ); } void fwAnimateSetValue ( int AnimationID, int NewValue ) { if ( AnimationID != -1 ) AnimationList[AnimationID].currentValue = NewValue; } int fwAnimateGetChangeValue ( int AnimationID ) { if ( AnimationID == - 1 ) return (0); else return ( AnimationList[AnimationID].changeValue ); } void fwAnimateSetChangeValue ( int AnimationID, int ChangeValue ) { if ( AnimationID != -1 ) AnimationList[AnimationID].changeValue = ChangeValue; }