1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #include "anim.h"
- //Constructors
- Animation::Animation(unsigned char duration)
- {
- // Initialize at given duration
- max = duration;
- counter = 0;
- /* Positive being 0 means the animation is at a "standby" phase and
- * can't run yet
- */
- positive = 0;
- }
- Animation::Animation()
- {
- // Initialize at 0
- max = 0;
- counter = 0;
- positive = 0;
- }
- // Update
- bool Animation::update()
- {
- //Positive animation
- if (positive)
- {
- //Counter is below max
- if (counter < max)
- {
- //Advance animation and return updated
- counter++;
- return 1;
- }
- }
- //Negative animation
- else
- {
- //Counter is above zero
- if (counter > 0)
- {
- //Advance animation (negatively) and return updated
- counter--;
- return 1;
- }
- }
- //Animation is not updated
- return 0;
- }
- //Actions
- void Animation::startFromStart() {counter = 0 ; positive = 1;}
- void Animation::startFromEnd () {counter = max; positive = 0;}
- void Animation::startFromStart(unsigned char gMax) {max = gMax; counter = 0 ; positive = 1;}
- void Animation::startFromEnd (unsigned char gMax) {max = gMax; counter = max; positive = 0;}
- //Isers
- bool Animation::isAtStart() {return counter == 0 && !positive;}
- bool Animation::isAtEnd () {return counter == max && positive;}
- bool Animation::isRunning()
- {
- return (counter < max && positive)
- || (counter > 0 && !positive);
- }
- //Interpolation
- float Animation::interpolate(float amount) {return amount *counter /max;}
|