//Using SDL and standard IO #include #include #include "texture.h" #include "renderer.h" #include "window.h" #include "timer.h" #include "keyboard.h" #include #include //void millisleep(Uint32 t){ // SDL_Delay(t); //} //Screen dimension constants const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; const int WALKING_ANIMATION_FRAMES = 7; int main( int argc, char* args[] ) { if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "SDL could not initialize: %s\n", SDL_GetError() ); } Window window {"This is the title", SCREEN_WIDTH, SCREEN_HEIGHT}; Renderer renderer; renderer.init(window.window()); const Uint32 LOOP_TIME = 20L; // milliseconds Timer timer; timer.start(); GameState game {&renderer, 2.0}; Keyboard keys; while( true ) { // Handle events SDL_Event e; while( SDL_PollEvent( &e ) != 0 ) { window.handleEvent(e)->execute(game); keys.handleEvent(e)->execute(game); } if(game.isClosed()) return 0; if(game.isPaused()) goto next; // GAME LOOP: game.update( timer.elapsed() ); game.render(); next: // Loop time calculation: timer.restart(); timer.waitUntil( LOOP_TIME ); } SDL_Quit(); return 0; }