/***************** "ANIM.C" Sprite animation package 27/1/99 ScoTT Campbell ****************/ #include "../headers/anim.h" /**************** Function Definitions ****************/ void InitialiseSpriteAnimation(sprite_anim_type* anim, GsSPRITE* spriteArray, int arraySize, int startX, int startY, animation_type animType) { anim->currentX = startX; anim->currentY = startY; anim->animationType = animType; printf("Anim type = %d\n", anim->animationType); anim->currentSprite = arraySize/2; printf("current sprite = %d\n", anim->currentSprite); anim->amountFrames = arraySize; printf("Frames = %d\n", anim->amountFrames); anim->sprites = spriteArray; }/* InitialiseSpriteAnimation */ void UpdateCurrentSprite(sprite_anim_type* anim, int animationDirection) { // Check if moving up or down array of sprites if(animationDirection < 0) // down array { if(anim->currentSprite == 0) { if(anim->animationType == CONTINUOUS) // Loop to last element in array anim->currentSprite = anim->amountFrames - 1; else if(anim->animationType == NON_CONTINUOUS) { // leave current sprite } } else anim->currentSprite--; } else if(animationDirection > 0) // up arry { if(anim->currentSprite == (anim->amountFrames - 1)) { if(anim->animationType == CONTINUOUS) // Loop to first element in array anim->currentSprite = 0; else if(anim->animationType == NON_CONTINUOUS) { // leave current sprite } } else anim->currentSprite++; } }/* UpdateCurrentSprite */ void UpdateSpriteAnimation(sprite_anim_type* anim, int animationDirection, int xAmount, int yAmount) { anim->currentX += xAmount; anim->currentY += yAmount; UpdateCurrentSprite(anim, animationDirection); }/* UpdateSpriteAnimation */ void MoveSpriteAnimation(sprite_anim_type* anim, int xAmount, int yAmount) { anim->currentX += xAmount; anim->currentY += yAmount; }/* MoveSpriteAnimation */ void DrawSpriteAnimation(sprite_anim_type* anim, GsOT* otPtr, int otPriority) { GsSPRITE* currentSprite = &anim->sprites[anim->currentSprite]; currentSprite->x = anim->currentX; currentSprite->y = anim->currentY; GsSortSprite(currentSprite, otPtr, otPriority); GsSortSprite(currentSprite, otPtr, otPriority); }/* DisplaySpriteAnimation */ /************* End of Function Definitions **************/