void Render(const int* runAnimationTemp, int& index) { glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); ship.DrawSpriteSheetSprite(ship.textureID, runAnimationTemp[index], 8, 4); SDL_GL_SwapWindow(displayWindow); }
int main(int argc, char *argv[]) { bool done = false; bool gameOn = false; float lastFrameTicks = 0.0f; float ballAngle = 0.0f; const int runAnimation[] = { 8, 9, 10, 11, 12, 13, 14, 15 }; const int numFrames = 8; float animationElapsed = 0.0f; float framesPerSecond = 30.0f; int currentIndex = 0; Setup(); while (!done) { float ticks = (float)SDL_GetTicks() / 1000.0f; float elapsed = ticks - lastFrameTicks; lastFrameTicks = ticks; animationElapsed += elapsed; if (animationElapsed > 1.0 / framesPerSecond) { currentIndex++; animationElapsed = 0.0; if (currentIndex > numFrames - 1) { currentIndex = 0; } } ProcessEvents(done, elapsed, gameOn); Update(); Render(runAnimation, currentIndex); } ship.DrawSpriteSheetSprite(ship.textureID, runAnimation[currentIndex], 8, 4); SDL_Quit(); return 0; }