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.
65 lines
2.2 KiB
65 lines
2.2 KiB
#include "animationHandler.h"
|
|
#include "animation.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include "../definitions.h"
|
|
|
|
AnimationHandler * AnimationHandlerInit(Animation ***animations, Texture2D **spriteTexture){
|
|
AnimationHandler *new = malloc(sizeof(AnimationHandler));
|
|
|
|
new->spriteTexture = spriteTexture;
|
|
new->animations = animations;
|
|
new->currentType = 0;
|
|
new->currentDirection = 0;
|
|
new->currentFrame = new->animations[new->currentType][new->currentDirection]->head;
|
|
new->spriteTexture = spriteTexture;
|
|
new->forward = 1;
|
|
new->deltaElapsed = 0;
|
|
|
|
return new;
|
|
}
|
|
|
|
void AnimationUpdate(AnimationHandler *animationHandler){
|
|
animationHandler->deltaElapsed += ACT_TIME;
|
|
|
|
if(animationHandler->deltaElapsed >= 0.2){
|
|
if(animationHandler->forward == 1){
|
|
animationHandler->currentFrame = animationHandler->currentFrame->next;
|
|
}
|
|
else{
|
|
animationHandler->currentFrame = animationHandler->currentFrame->prev;
|
|
}
|
|
animationHandler->deltaElapsed = 0;
|
|
}
|
|
|
|
*(animationHandler->spriteTexture) = animationHandler->currentFrame->texture;
|
|
|
|
}
|
|
|
|
void AnimationReset(AnimationHandler *animationHandler){
|
|
animationHandler->currentFrame = animationHandler->animations[animationHandler->currentType][animationHandler->currentDirection]->head;
|
|
*(animationHandler->spriteTexture) = animationHandler->currentFrame->texture;
|
|
}
|
|
|
|
void AnimationChangeAnimation(AnimationHandler *animationHandler, int animationType, int direction){
|
|
if(animationHandler->currentType != animationType || animationHandler->currentDirection != direction){
|
|
animationHandler->currentType = animationType;
|
|
animationHandler->currentDirection = direction;
|
|
AnimationReset(animationHandler);
|
|
}
|
|
}
|
|
|
|
void AnimationChangeType(AnimationHandler *animationHandler, int animationType){
|
|
if(animationHandler->currentType != animationType){
|
|
animationHandler->currentType = animationType;
|
|
AnimationReset(animationHandler);
|
|
}
|
|
}
|
|
|
|
void AnimationChangeDirection(AnimationHandler *animationHandler, int direction){
|
|
if(animationHandler->currentDirection != direction){
|
|
animationHandler->currentDirection = direction;
|
|
AnimationReset(animationHandler);
|
|
}
|
|
}
|