When moving a chopper picture around the screen using 3 different chopper pictures, how does one increase the animation speed as the chopper speed increases in velocity?
The drawHelicopter function below switches between each helicopter picture using a counter and then resets. The move function is included to show you how I'm increasing the chopper's speed.
Code:
void Helicoptor::drawHelicopter(MyDrawEngine* pTheDrawEngine, MyPicture* pHelicopter, double fRate)
{
sourceRect.top = 0;
sourceRect.bottom = 32;
if(frameCounter == 0)
{
sourceRect.left = 0;
sourceRect.right = 64;
}
if(frameCounter == 1)
{
sourceRect.left = 64;
sourceRect.right = 128;
}
if(frameCounter == 2)
{
sourceRect.left = 128;
sourceRect.right = 192;
}
destRect.top = (int)yCoord;
destRect.bottom = (int)yCoord+32;
destRect.left = (int)xCoord;
destRect.right = (int)xCoord+64;
//Blit: Copy from surface to back buffer(temp draw surrface)
pTheDrawEngine->Blit(destRect, sourceRect, pHelicopter);
}
void Helicoptor::move(MyInputs* pTheInputs, double fTime)
{
yCoord = yCoord + yVelocity * fTime;
xCoord = xCoord + xVelocity * fTime;
if(yCoord < 0) yCoord = 0;
if(yCoord > 720) yCoord = 720;
if(xCoord < 0) xCoord = 0;
if(xCoord > 960) xCoord = 960;
//Move direction
if(KEYPRESSED('Q') && (yVelocity > -61))
{
yVelocity = yVelocity - pixels_per_sec;
}
if(KEYPRESSED('A') && (yVelocity < 61))
{
yVelocity = yVelocity + pixels_per_sec;
}
if(KEYPRESSED('N') && (xVelocity > -61))
{
xVelocity = xVelocity - pixels_per_sec;
}
if(KEYPRESSED('M') && (xVelocity < 61))
{
xVelocity = xVelocity + pixels_per_sec;
}
frameCounter++;
if(frameCounter == 3) frameCounter = 0;
}