You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.3 KiB
45 lines
1.3 KiB
#include "animationHandler.h"
|
|
#include "animation.h"
|
|
#include "stdlib.h"
|
|
#include "stdio.h"
|
|
|
|
AnimationHandler * AnimationHandlerInit(Animation **animations){
|
|
AnimationHandler *new = malloc(sizeof(AnimationHandler));
|
|
|
|
new->animations = animations;
|
|
new->currentAnimation = 0;
|
|
new->currentFrame = new->animations[new->currentAnimation]->head;
|
|
new->forward = 1;
|
|
new->deltaElapsed = 0;
|
|
|
|
return new;
|
|
}
|
|
|
|
void AnimationUpdate(AnimationHandler *animationHandler){
|
|
animationHandler->deltaElapsed += GetFrameTime();
|
|
|
|
if(animationHandler->deltaElapsed >= 0.2){
|
|
if(animationHandler->forward == 1){
|
|
animationHandler->currentFrame = animationHandler->currentFrame->next;
|
|
}
|
|
else{
|
|
animationHandler->currentFrame = animationHandler->currentFrame->prev;
|
|
}
|
|
animationHandler->deltaElapsed = 0;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
void AnimationReset(AnimationHandler *animationHandler){
|
|
animationHandler->currentFrame = animationHandler->animations[animationHandler->currentAnimation]->head;
|
|
}
|
|
|
|
void AnimationChangeAnimation(AnimationHandler *animationHandler, int newAnimation){
|
|
if(animationHandler->currentAnimation != newAnimation){
|
|
animationHandler->currentAnimation = newAnimation;
|
|
AnimationReset(animationHandler);
|
|
}
|
|
|
|
}
|