Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Animation.h"
- Animation::Animation(void)
- {
- }
- Animation::Animation(int cFrame, int numOfFrames, float timePerFrame[], bool animateOnlyOnce, bool setIndividualFrameTimes)
- {
- //Set initial values
- Timer = timer();
- currentTime = 0.0f;
- currentFrame = cFrame;
- oldFrame = cFrame;
- numberOfFrames = numOfFrames;
- //Set Individual Maximum Times per frame
- for (int n = 0; n < numOfFrames; n++)
- a_maxTimePerFrame[n] = timePerFrame[n];
- animateOnce = animateOnlyOnce;
- animating = true;
- }
- Animation::Animation(int cFrame, int numOfFrames, float timePerFrame, bool animateOnlyOnce)
- {
- //Set initial values
- Timer = timer();
- currentTime = 0.0f;
- currentFrame = cFrame;
- oldFrame = cFrame;
- numberOfFrames = numOfFrames;
- maxTimePerFrame = timePerFrame;
- animateOnce = animateOnlyOnce;
- animating = true;
- individualFrameTimes = false;
- }
- void Animation::Update(SDLib& lib)
- {
- if (lib.pause)
- Timer.pause();
- if (Timer.is_paused() && lib.play)
- Timer.unpause();
- if (!Timer.is_started())
- Timer.start();
- if (animating && numberOfFrames > 0 && maxTimePerFrame > 0 && !lib.pause && !individualFrameTimes) //We have some frames to animate with
- {
- float accumlator = 1000 * Timer.getDelta();
- currentTime += accumlator;
- float maxTime = 0;
- //Half The Reload-Time if we want faster gamplay
- if (lib.speedUp)
- maxTime = maxTimePerFrame / 2;
- else
- maxTime = maxTimePerFrame;
- if (currentTime > maxTime)
- {
- currentTime = 0.0f;
- currentFrame++;
- Timer.stop();
- if (currentFrame >= numberOfFrames && !animateOnce)
- {
- currentFrame = oldFrame;
- }
- else if (currentFrame >= numberOfFrames && animateOnce)
- {
- animating = false;
- currentFrame = numberOfFrames - 1;
- }
- }
- }
- else if (animating && numberOfFrames > 0 && a_maxTimePerFrame[currentFrame] > 0 && individualFrameTimes && !lib.pause) //We have some frames to animate with
- {
- float accumlator = 1000 * Timer.getDelta();
- currentTime += accumlator;
- float maxTime = 0;
- //Half The Reload-Time if we want faster gamplay
- if (lib.speedUp)
- maxTime = a_maxTimePerFrame[currentFrame] / 2;
- else
- maxTime = a_maxTimePerFrame[currentFrame];
- if (currentTime > maxTime)
- {
- currentTime = 0.0f;
- currentFrame++;
- Timer.stop();
- if (currentFrame >= numberOfFrames && !animateOnce)
- {
- currentFrame = oldFrame;
- }
- else if (currentFrame >= numberOfFrames && animateOnce)
- {
- animating = false;
- currentFrame = numberOfFrames - 1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement