I've got an algorithm that cycles through a tileset of a Mech
walking. It uses 3 variables: TimeCounter, AnimFrame, Footing.
TimeCounter is just an incrimental counter used for delay.
AnimFrame represents where in the tileset to get the source image.
Footing represents which step (ie: 0 = left foot first, 1 = right)
Code:
long TimeCounter, AnimFrame, Footing;
//in the main game loop
TimeCounter++;
if(TimeCounter==150000)
{
if(AnimFrame==0) //center point, legs even
{
if(Footing==0)
{
AnimFrame=1;
}
else
{
AnimFrame=5;
}
}
else if(AnimFrame>=1 && AnimFrame<=3)
{
if(Footing==0)
{
AnimFrame++;
}
else
{
AnimFrame--;
}
}
else if(AnimFrame==4)
{
Footing=1;
AnimFrame=3;
}
else if(AnimFrame==5)
{
if(Footing==0)
{
AnimFrame=0;
}
else
{
AnimFrame=6;
}
}
else if(AnimFrame>=6 && AnimFrame <=7)
{
if(Footing==0)
{
AnimFrame--;
}
else
{
AnimFrame++;
}
}
else if(AnimFrame==8)
{
Footing=0;
AnimFrame=7;
}
TimeCounter=0;
}
This works fine for me, but I was wondering what any of you
guys thought. Any suggestions on how to optimize it?
I've attached the sprite tileset I used in testing it. Forgive the
artwork, it's pre-Alpha stage of a game I'm working on so it's not very detailed (ie: just basic textures, etc.).
By the way, to give you an idea of the speed of C++ vs. VB (and
I'm sure I'm not telling you somethin you don't already know),
this is an algorithm I had written in VB and the TimeCounter
check value was 30 there (here I had to set it to 150000,
because it would run TOO FAST otherwise)! Man, I love C++!!!