| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include "animation.h" |
| 29 |
|
| 30 |
#include "defs.h" |
| 31 |
|
| 32 |
static Animation animStanding = { |
| 33 |
ACTORANIMATION_STAND, 0, {IDLEHEAD_NORMAL}, {1}, 0, false, true}; |
| 34 |
static Animation animIdling = { |
| 35 |
ACTORANIMATION_IDLE, |
| 36 |
0, |
| 37 |
{IDLEHEAD_NORMAL, IDLEHEAD_LEFT, IDLEHEAD_RIGHT}, |
| 38 |
{90, 60, 60}, |
| 39 |
0, |
| 40 |
true, |
| 41 |
true}; |
| 42 |
static Animation animWalking = {ACTORANIMATION_WALKING, |
| 43 |
0, |
| 44 |
{0, 1, 2, 3, 4, 5, 6, 7}, |
| 45 |
{4, 4, 4, 4, 4, 4, 4, 4}, |
| 46 |
0, |
| 47 |
false, |
| 48 |
true}; |
| 49 |
|
| 50 |
Animation AnimationGetActorAnimation(const ActorAnimation aa) |
| 51 |
{ |
| 52 |
switch (aa) |
| 53 |
{ |
| 54 |
case ACTORANIMATION_STAND: |
| 55 |
return animStanding; |
| 56 |
case ACTORANIMATION_IDLE: |
| 57 |
return animIdling; |
| 58 |
case ACTORANIMATION_WALKING: |
| 59 |
return animWalking; |
| 60 |
default: |
| 61 |
CASSERT(false, "Unknown actor animation"); |
| 62 |
return animIdling; |
| 63 |
} |
| 64 |
} |
| 65 |
|
| 66 |
void AnimationUpdate(Animation *a, const float ticks) |
| 67 |
{ |
| 68 |
a->frameCounter += ticks; |
| 69 |
a->newFrame = false; |
| 70 |
if (a->frameCounter > a->ticksPerFrame[a->frame]) |
| 71 |
{ |
| 72 |
a->frameCounter -= a->ticksPerFrame[a->frame]; |
| 73 |
a->newFrame = true; |
| 74 |
|
| 75 |
if (a->randomFrames) |
| 76 |
{ |
| 77 |
|
| 78 |
|
| 79 |
if (a->frame == 0) |
| 80 |
{ |
| 81 |
|
| 82 |
do |
| 83 |
{ |
| 84 |
a->frame = (rand() % (ANIMATION_MAX_FRAMES - 1)) + 1; |
| 85 |
} while (a->ticksPerFrame[a->frame] < 0); |
| 86 |
} |
| 87 |
else |
| 88 |
{ |
| 89 |
a->frame = 0; |
| 90 |
} |
| 91 |
} |
| 92 |
else |
| 93 |
{ |
| 94 |
a->frame++; |
| 95 |
if (a->frame >= ANIMATION_MAX_FRAMES || |
| 96 |
a->ticksPerFrame[a->frame] < 0) |
| 97 |
{ |
| 98 |
a->frame = 0; |
| 99 |
} |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
int AnimationGetFrame(const Animation *a) |
| 104 |
{ |
| 105 |
return a->frames[a->frame]; |
| 106 |
} |