piexil

Untitled

Jan 19th, 2013
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.28 KB | None | 0 0
  1. int main(int argc, char* args[])
  2. {
  3.     bool quit = false;
  4.  
  5.     // The dot
  6.     Dot myDot;
  7.  
  8.     // Projectiles.
  9.     vector<projectile*> myProj;
  10.  
  11.     //The tiles that will be used
  12.     Tile* tiles[TOTAL_TILES];
  13.         //The frame rate regulator
  14.     Timer fps;
  15.  
  16.     //Initialize
  17.     if( init() == false )
  18.     {
  19.         return 1;
  20.     }
  21.  
  22.     //Load the files
  23.     if( load_files() == false )
  24.     {
  25.         return 1;
  26.     }
  27.      //Clip the tile sheet
  28.     clip_tiles();
  29.        
  30.     // You still need to load tiles and whatnot in order to
  31.     // not get a segfault accessing the above array.
  32.     // This may be different than what you intended.
  33.    
  34.     // Game loop
  35.     while(!quit)
  36.     {
  37.         fps.start();
  38.         // While there's events to handle
  39.         while(SDL_PollEvent(&event))
  40.         {
  41.             if(!set_tiles(tiles))
  42.             {
  43.                 return 1;
  44.             }
  45.  
  46.             // Handle events for the dot
  47.             myDot.handle_input();
  48.                    
  49.             // Handle input for projectiles
  50.             for(size_t i = 0; i < myProj.size(); ++i)
  51.             {
  52.                 myProj[i]->handle_input();
  53.             }
  54.    
  55.             // If the user has Xed out the window
  56.             quit = (event.type == SDL_QUIT);
  57.         }
  58.  
  59.         //Move the dot
  60.         myDot.move(tiles);
  61.    
  62.         // Fire projectiles
  63.         for(size_t i = 0; i < myProj.size(); ++i)
  64.         {
  65.             myProj[i]->move(tiles);
  66.         }
  67.  
  68.         // Set the camera
  69.         myDot.set_camera();
  70.  
  71.         // Show the tiles
  72.         for( int t = 0; t < TOTAL_TILES; t++ )
  73.         {
  74.             tiles[ t ]->show();
  75.         }
  76.  
  77.         // Show the dot on the screen              
  78.         myDot.show();
  79.  
  80.         // Show projectiles on screen if enabled.
  81.         if(projectile_show)
  82.         {
  83.             for(size_t i = 0; i < myProj.size(); ++i)
  84.             {
  85.                 myProj[i]->show();
  86.             }                    
  87.         }              
  88.  
  89.         // Update the screen
  90.         SDL_Flip(screen);
  91.     }
  92.     //Cap the frame rate
  93.         if( fps.get_ticks() < 1000 / FRAMES_PER_SECOND )
  94.         {
  95.             SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - fps.get_ticks() );
  96.         }
  97.      //Clean up
  98.     clean_up( tiles );
  99.  
  100.     return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment