//Functions int main(int argc, char* args[]) { bool quit = false; if(init() == false) { return 1; } //Load the files if(load_files() == false) { return 1; } set_clips(); Timer fps; Foo walk; //While user hasn't quit while(quit == false) { fps.start(); while(SDL_PollEvent(&event)) { walk.handle_events(); if(event.type == SDL_QUIT) { quit = true; } } walk.move(); SDL_FillRect(screen, &screen->clip_rect, SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF)); walk.show(); if(SDL_Flip(screen) == -1) { return 1; } if(fps.get_ticks() < 1000 / FRAMES_PER_SECOND) { SDL_Delay((1000 / FRAMES_PER_SECOND) - fps.get_ticks()); } } clean_up(); return 0; }
int main( int argc, char* args[] ) { //Quit flag bool quit = false; //Initialize if( init() == false ) { return 1; } //Load the files if( load_files() == false ) { return 1; } //Clip the sprite sheet set_clips(); //The frame rate regulator Timer fps; //The stick figure Foo walk; //While the user hasn't quit while( quit == false ) { //Start the frame timer fps.start(); //While there's events to handle while( SDL_PollEvent( &event ) ) { //Handle events for the stick figure walk.handle_events(); //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Move the stick figure walk.move(); //Fill the screen white SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) ); //Show the stick figure on the screen walk.show(); //Update the screen if( SDL_Flip( screen ) == -1 ) { return 1; } //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } //Clean up clean_up(); return 0; }
void dino_main() { start= SDL_GetTicks(); for(int i=0; i<600; i++) { randx[i]= rand()%600 + 1; randy[i]= rand()%420 + 1; if (randy[i]>220 && randy[i]<270) { randx[i]=randx[i-1]; randy[i]=randx[i-1]; } } bool quit = false; set_clips(); //The frame rate regulator Timer fps; //The stick figure Foo walk; //While the user hasn't quit while( quit == false ) { //Start the frame timer fps.start(); //While there's events to handle while( SDL_PollEvent( &event ) ) { //Handle events for the stick figure walk.handle_events(); //If the user has Xed out the window if( event.type == SDL_QUIT ) { //Quit the program quit = true; } } //Move the stick figure walk.move(randx,randy); //Fill the screen white //SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0, 0xFF, 0xFF ) ); apply_surface(0,0,back_grass,screen); score_dis = TTF_RenderText_Solid( font, "Score", textColor ); apply_surface( 460, 450, score_dis, screen ); SDL_FillRect( screen, &wall, SDL_MapRGB( screen->format, 0, 0xFF, 0xFF ) ); SDL_FillRect( screen, &wall2, SDL_MapRGB( screen->format, 0, 0xFF, 0xFF )); walk.show(); //Update the screen if( SDL_Flip( screen ) == -1 ) { } //Cap the frame rate if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND ) { SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() ); } } }