Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main(int argc, char* args[])
- {
- bool quit = false;
- // The dot
- Dot myDot;
- // Projectiles.
- vector<projectile*> myProj;
- //The tiles that will be used
- Tile* tiles[TOTAL_TILES];
- //The frame rate regulator
- Timer fps;
- //Initialize
- if( init() == false )
- {
- return 1;
- }
- //Load the files
- if( load_files() == false )
- {
- return 1;
- }
- //Clip the tile sheet
- clip_tiles();
- // You still need to load tiles and whatnot in order to
- // not get a segfault accessing the above array.
- // This may be different than what you intended.
- // Game loop
- while(!quit)
- {
- fps.start();
- // While there's events to handle
- while(SDL_PollEvent(&event))
- {
- if(!set_tiles(tiles))
- {
- return 1;
- }
- // Handle events for the dot
- myDot.handle_input();
- // Handle input for projectiles
- for(size_t i = 0; i < myProj.size(); ++i)
- {
- myProj[i]->handle_input();
- }
- // If the user has Xed out the window
- quit = (event.type == SDL_QUIT);
- }
- //Move the dot
- myDot.move(tiles);
- // Fire projectiles
- for(size_t i = 0; i < myProj.size(); ++i)
- {
- myProj[i]->move(tiles);
- }
- // Set the camera
- myDot.set_camera();
- // Show the tiles
- for( int t = 0; t < TOTAL_TILES; t++ )
- {
- tiles[ t ]->show();
- }
- // Show the dot on the screen
- myDot.show();
- // Show projectiles on screen if enabled.
- if(projectile_show)
- {
- for(size_t i = 0; i < myProj.size(); ++i)
- {
- myProj[i]->show();
- }
- }
- // Update the screen
- SDL_Flip(screen);
- }
- //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( tiles );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment