void loop () {
	//Handle events on queue
	while( SDL_PollEvent( &e ) != 0 )
	{
		//User requests quit
		if( e.type == SDL_QUIT )
		{
			quit = true;
		}
		
		//Handle input for the dot
		dot.handleEvent( e );
	}
	
	//Calculate time step
	float timeStep = stepTimer.getTicks() / 1000.f;

	//Move for time step
	dot.move( timeStep );

	//Restart step timer
	stepTimer.start();

	//Clear screen
	SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
	SDL_RenderClear( gRenderer );

	//Render dot
	dot.render();

	//Update screen
	SDL_RenderPresent( gRenderer );
}
示例#2
0
void loop () {
	//Handle events on queue
	while( SDL_PollEvent( &e ) != 0 )
	{
		//User requests quit
		if( e.type == SDL_QUIT )
		{
			quit = true;
		}
		
		//Handle input for the dot
		dot.handleEvent( e );
	}
	
	//Move the dot
	dot.move( tileSet );
	dot.setCamera( camera );

	//Clear screen
	SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
	SDL_RenderClear( gRenderer );

	//Render level
	for( int i = 0; i < TOTAL_TILES; ++i )
	{
		tileSet[ i ]->render( camera );
	}

	//Render dot
	dot.render( camera );

	//Update screen
	SDL_RenderPresent( gRenderer );
}
int main( int argc, char* args[] ) {
  //Start up SDL and create window
  if( !init() ) {
    printf( "Failed to initialize!\n" );
  } else {
    //Load media
    if( !loadMedia() ) {
      printf( "Failed to load media!\n" );
    } else {
      //Main loop flag
      bool quit = false;

      //Event handler
      SDL_Event e;

      //The dot that will be moving around on the screen
      Dot dot;

      //While application is running
      while( !quit ) {
        //Handle events on queue
        while( SDL_PollEvent( &e ) != 0 ) {
          //User requests quit
          if( e.type == SDL_QUIT ) {
            quit = true;
          }

          //Handle input for the dot
          dot.handleEvent( e );
        }

        //Move the dot
        dot.move();

        //Clear screen
        SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
        SDL_RenderClear( gRenderer );

        //Render objects
        dot.render();

        //Update screen
        SDL_RenderPresent( gRenderer );
      }
    }
  }

  //Free resources and close SDL
  close();

  return 0;
}
void Picture::mousePressEvent(QMouseEvent *e)
{
    if (e->button() == Qt::LeftButton) {
           if (selectedPoints.size() < 8)
           {
               Dot* dot = new Dot(this);
               dot->show();
               update();
               dot->move(e->x(), e->y());
               Vector3i *newPoint = new Vector3i(e->x(), e->y(), 1);
               selectedPoints.push_back(*newPoint);
           }
           else
           {
               double w = (double)boardDimensions->x();
               double h = (double)boardDimensions->y();

               double divisor = w;
               if(w>h)
                divisor = h;

               w = ((double)boardDimensions->x()/divisor);
               h = ((double)boardDimensions->y()/divisor);

               realWorldPoints.push_back(Vector3d(0, 0, 1));
               realWorldPoints.push_back(Vector3d(0, h, 1));
               realWorldPoints.push_back(Vector3d(w, h, 1));
               realWorldPoints.push_back(Vector3d(w, 0, 1));

               // Calculate H Matrix
               MatrixXd H = Utils::calculateHomographyMatrix(selectedPoints, realWorldPoints);

               QImage inputImage = QImage("/home/fschuindt/dev/qt-persperctive-distortion-remotion/work-1/MyActions/brahma01.jpg");
               QImage outputImage = Utils::applyHomography(H, inputImage, vector<Vector3i>(selectedPoints.begin()+4, selectedPoints.end()));
               Utils::saveImage(outputImage, "/home/fschuindt/teste.jpg");

           }
    }

}
void loop () {
	//Handle events on queue
	while( SDL_PollEvent( &e ) != 0 )
	{
		//User requests quit
		if( e.type == SDL_QUIT )
		{
			quit = true;
		}

		//Handle input for the dot
		dot.handleEvent( e );
	}
	
	//Move the dot
	dot.move();

	//Scroll background
	--scrollingOffset;
	if( scrollingOffset < -gBGTexture.getWidth() )
	{
		scrollingOffset = 0;
	}

	//Clear screen
	SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
	SDL_RenderClear( gRenderer );

	//Render background
	gBGTexture.render( scrollingOffset, 0 );
	gBGTexture.render( scrollingOffset + gBGTexture.getWidth(), 0 );

	//Render objects
	dot.render();

	//Update screen
	SDL_RenderPresent( gRenderer );
}
示例#6
0
int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{
		//Load media
		if( !loadMedia() )
		{
			printf( "Failed to load media!\n" );
		}
		else
		{	
			//Main loop flag
			bool quit = false;

			//Event handler
			SDL_Event e;

			//The dot that will be moving around on the screen
			Dot dot;

			//The camera area
			SDL_Rect camera = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };

			//While application is running
			while( !quit )
			{
				//Handle events on queue
				while( SDL_PollEvent( &e ) != 0 )
				{
					//User requests quit
					if( e.type == SDL_QUIT )
					{
						quit = true;
					}

					//Handle input for the dot
					dot.handleEvent( e );
				}

				//Move the dot
				dot.move();

				//Center the camera over the dot
				camera.x = ( dot.getPosX() + Dot::DOT_WIDTH / 2 ) - SCREEN_WIDTH / 2;
				camera.y = ( dot.getPosY() + Dot::DOT_HEIGHT / 2 ) - SCREEN_HEIGHT / 2;

				//Keep the camera in bounds
				if( camera.x < 0 )
				{ 
					camera.x = 0;
				}
				if( camera.y < 0 )
				{
					camera.y = 0;
				}
				if( camera.x > LEVEL_WIDTH - camera.w )
				{
					camera.x = LEVEL_WIDTH - camera.w;
				}
				if( camera.y > LEVEL_HEIGHT - camera.h )
				{
					camera.y = LEVEL_HEIGHT - camera.h;
				}

				//Clear screen
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
				SDL_RenderClear( gRenderer );

				//Render background
				gBGTexture.render( 0, 0, &camera );

				//Render objects
				dot.render( camera.x, camera.y );

				//Update screen
				SDL_RenderPresent( gRenderer );
			}
		}
	}

	//Free resources and close SDL
	close();

	return 0;
}
示例#7
0
int main ( int argc, char** argv )
{
    Setup setup1;
    //cerr << "address of Setup: " << &setup1 << '\n';
    ImageManager im1;
    SoundManager sm1;
    Dot myDot;
    World world1;
    cout << "rest of main \n";

    if(setup1.init() == false)
    {
        return 1;
    }
    //newScreen = setup1.getScreen();

    if(im1.loadFont() == false)
    {
        return 1;
    }


    if(im1.getFiles() == false)
    {
        cout << "error  loading images" << endl;
        return 1;
    }


    if(sm1.soundFiles() == false)
    {
        cout << "error loading sounds \n";
        return 1;
    }

    if(world1.set_tiles() == false)
    {
    	cout  << "error loading map \n";
    	return 1;
    }
    //Mix_Music* bgm = sm1.getTrack(0);
    // make sure SDL cleans up before exit
    atexit(SDL_Quit);

    // centre the bitmap on screen
    //SDL_Rect dstrect;
    //dstrect.x = (screen->w - bmp->w) / 2;
    //dstrect.y = (screen->h - bmp->h) / 2;

    Timer frames1;
    Timer delta;
    delta.start();

    // program main loop
    bool done = false;
    while (done == false)
    {
        frames1.start();
        // message processing loop
        SDL_Event event;
        while (SDL_PollEvent(&event))
        {
            //cout << &event << endl;
            //SDL_Event *e = &event;

            myDot.change_heading(event);
            myDot.handle_input(event);

            if(event.type == SDL_QUIT)
            {
                done = true;
            }
            // get keystates
            //Uint8 *keystates = SDL_GetKeyState(NULL);

            if(event.type == SDL_KEYDOWN)
            {

                if(event.key.keysym.sym == SDLK_p)
                {
                    if(Mix_PlayingMusic() == 0)
                    {
                        sm1.playAll();
                    }
                    else
                    {
                        if(Mix_PausedMusic() == 1)
                        {
                            Mix_ResumeMusic();
                        }
                        else
                        {
                            Mix_PauseMusic();
                        }
                    }
                }

                if(event.key.keysym.sym == SDLK_ESCAPE)
                {
                    done = true;
                }
            }
        }

        myDot.move(setup1, world1, delta.get_ticks());
        myDot.shoot(setup1);
        delta.start();
        myDot.setCamera(setup1);

        im1.drawAll(myDot, setup1, world1);
        myDot.showParticleD(im1, setup1);

        im1.drawPlayer(setup1, myDot);
        myDot.showBulletD(im1, setup1);



        /**
        Uint8 *keystates = SDL_GetKeyState(NULL);
        if(keystates[SDLK_p])
        {
            // key state template
        }
        **/


        //SDL_Surface* test = TTF_RenderText_Solid(im1.getFont(), "test", im1.getColour());
        //im1.applySurface(10, 10, test, newScreen);



        if(SDL_Flip(setup1.getScreen()) == -1)
        {
            return 1;
        }

        //framecount++;

        //cout << "frames" << SDL_GetTicks() << endl;

        if(frames1.get_ticks() < 1000 / setup1.getFPS())
        {
            SDL_Delay((1000 / setup1.getFPS()) - frames1.get_ticks());
            //cout << "delay" << 1000 / setup1.getFPS() - frames1.get_ticks();
        }

    }// end main loop

    //Mix_FreeMusic(bgm);
    setup1.freeScreen();
    im1.clean();
    sm1.cleanSound();

    // all is well ;)
    printf("Exited cleanly\n");
    return 0;
}
示例#8
0
/*Foo::Foo()
{
          offSet = 0;
          velocity = 0;
          
          frame = 0;
          status = FOO_RIGHT;
}
void Foo::move()
{
     offSet += velocity;
     
     if( ( offSet < 0 ) || ( offSet + FOO_WIDTH > SCREEN_WIDTH ) )
         offSet -= velocity;
}
void Foo::show()
{
     if( velocity < 0 )
     {
         status = FOO_LEFT;
         
         frame++;
     }
     else if( velocity > 0 )
     {
          status = FOO_RIGHT;
          
          frame++;
     }
     else
         frame = 0;
         
     if( frame >= 4 )
         frame = 0;
         
     if( status == FOO_RIGHT )
         apply_surface( offSet, SCREEN_HEIGHT - FOO_HEIGHT, foo, screen, &clipsRight[frame] );
     else if( status == FOO_LEFT )
          apply_surface( offSet, SCREEN_HEIGHT - FOO_HEIGHT, foo, screen, &clipsLeft[frame] );
}
void Foo::handle_events()
{
    //If a key was pressed
    if( event.type == SDL_KEYDOWN )
    {
        //Set the velocity
        switch( event.key.keysym.sym )
        {
            case SDLK_RIGHT: velocity += FOO_WIDTH / 4; break;
            case SDLK_LEFT: velocity -= FOO_WIDTH / 4; break;
        }
    }
    //If a key was released
    else if( event.type == SDL_KEYUP )
    {
        //Set the velocity
        switch( event.key.keysym.sym )
        {
            case SDLK_RIGHT: velocity -= FOO_WIDTH / 4; break;
            case SDLK_LEFT: velocity += FOO_WIDTH / 4; break;
        }
    }
}

void set_clips()
{
     //clip the sprite sheet
     clipsRight[0].x = 0;
     clipsRight[0].y = 0;
     clipsRight[0].w = FOO_WIDTH;
     clipsRight[0].h = FOO_HEIGHT;
     
     clipsRight[1].x = FOO_WIDTH;
     clipsRight[1].y = 0;
     clipsRight[1].w = FOO_WIDTH;
     clipsRight[1].h = FOO_HEIGHT;
     
     clipsRight[2].x = FOO_WIDTH * 2;
     clipsRight[2].y = 0;
     clipsRight[2].w = FOO_WIDTH;
     clipsRight[2].h = FOO_HEIGHT;
     
     clipsRight[3].x = FOO_WIDTH * 3;
     clipsRight[3].y = 0;
     clipsRight[3].w = FOO_WIDTH;
     clipsRight[3].h = FOO_HEIGHT;
     
     clipsLeft[0].x = 0;
     clipsLeft[0].y = FOO_HEIGHT;
     clipsLeft[0].w = FOO_WIDTH;
     clipsLeft[0].h = FOO_HEIGHT;
     
     clipsLeft[1].x = FOO_WIDTH;
     clipsLeft[1].y = FOO_HEIGHT;
     clipsLeft[1].w = FOO_WIDTH;
     clipsLeft[1].h = FOO_HEIGHT;
     
     clipsLeft[2].x = FOO_WIDTH * 2;
     clipsLeft[2].y = FOO_HEIGHT;
     clipsLeft[2].w = FOO_WIDTH;
     clipsLeft[2].h = FOO_HEIGHT;
     
     clipsLeft[3].x = FOO_WIDTH * 3;
     clipsLeft[3].y = FOO_HEIGHT;
     clipsLeft[3].w = FOO_WIDTH;
     clipsLeft[3].h = FOO_HEIGHT;
}*/
int main( int argc, char* args[] )
{
     bool quit = false;
     
     int frame = 0;
     
     bool cap = true;
     
     Timer fps;
     Timer update;
     
     
     
     if( init() == false )
         return 1;
     
     if( load_files() == false )
         return 1;
     //set_clips();
     Dot myDot;
     
     update.start();
     
     while( quit == false)
     {
            fps.start();
            while( SDL_PollEvent(&event) )
            {
                   myDot.handle_input();
                                  
                   if( event.type == SDL_QUIT )
                       quit = true;
            }
            
            myDot.move();
            myDot.set_camera();
            //std::stringstream fpsm;
            //fpsm << "FPS: " << frame / ( fps.get_ticks() / 1000.f );
            apply_surface( 0, 0, background, screen, &camera );
            //SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );
            myDot.show();
            
            if( update.get_ticks() > 1000.f )
            {
                
                std::stringstream fpsm;
                
                fpsm << "FPS: " <<  ( frame );
                fpsmessage = TTF_RenderText_Solid(font, fpsm.str().c_str(), textColor );
                
                frame = 0;
                update.start();
            }
            apply_surface( 10, 10, fpsmessage, screen);
            if( SDL_Flip( screen ) == -1 )
                return 1;
            
            frame++;
            if( ( ( fps.get_ticks() ) < 1000 / FRAMES_PER_SECOND ) )
                SDL_Delay( ( 1000 / FRAMES_PER_SECOND ) - ( fps.get_ticks() ) );
                
            
        
     }
     
     clean_up();
     return 0;
}
示例#9
0
文件: demo.cpp 项目: marekzajac92/cjs
int main(int argc, char* args[]) {
	//Quit flag
	bool quit = false;

	//Make the dot
	Dot myDot;

	//The frame rate regulator
	Timer fps;

	//Initialize
	if (init() == false) {
		return 1;
	}

	//Load the files
	if (load_files() == false) {
		return 1;
	}

	//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 dot
			myDot.handle_input();

			//If the user has Xed out the window
			if (event.type == SDL_QUIT) {
				//Quit the program
				quit = true;
			}
		}

		//Move the dot
		myDot.move();

		//Fill the screen white
		SDL_FillRect(screen, &screen->clip_rect,
				SDL_MapRGB(screen->format, 0xFF, 0xFF, 0xFF));

		//Show the dot on the screen
		myDot.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;
}
示例#10
0
int main( int argc, char* args[] )
{
    //Quit flag
    bool quit = false;

    //The dot that will be used
    Dot myDot;

    //Keeps track of time since last rendering
    Timer delta;

    //Initialize
    if( init() == false )
    {
        return 1;
    }

    //Load the files
    if( load_files() == false )
    {
        return 1;
    }

    //Start delta timer
    delta.start();

    //While the user hasn't quit
    while( quit == false )
    {
        //While there's events to handle
        while( SDL_PollEvent( &event ) )
        {
            //Handle events for the dot
            myDot.handle_input();

            //If the user has Xed out the window
            if( event.type == SDL_QUIT )
            {
                //Quit the program
                quit = true;
            }
        }

        //Move the dot
        myDot.move( delta.get_ticks() );

        //Restart delta timer
        delta.start();

        //Fill the screen white
        SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0xFF, 0xFF, 0xFF ) );

        //Show the dot on the screen
        myDot.show();

        //Update the screen
        if( SDL_Flip( screen ) == -1 )
        {
            return 1;
        }
    }

    //Clean up
    clean_up();

    return 0;
}
示例#11
0
int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{
		//Load media
		if( !loadMedia() )
		{
			printf( "Failed to load media!\n" );
		}
		else
		{	
			//Main loop flag
			bool quit = false;

			//Event handler
			SDL_Event e;

			//The background scrolling offset
            int scrollingOffset = 0;

			//Angle of rotation
			double degrees = 0;

			//The dot that will be moving around on the screen
			Dot dot ( 100, 300);

			//Opening Fonts and message
			TTF_Font *times;
			times = TTF_OpenFont("arial.ttf", 14);

			SDL_Color white = {255, 255, 255};
			
			std::stringstream health;
			health <<"Health:" << dot.hp << "    Points: " << POINTS;

			const std::string str = health.str();

			SDL_Surface *surface = TTF_RenderText_Solid(times,
									health.str().c_str(), white);


			 SDL_Texture * texture = SDL_CreateTextureFromSurface(gRenderer,
					 surface);

			  int texW = 0;
			  int texH = 0;
			  SDL_QueryTexture(texture, NULL, NULL, &texW, &texH);
			  SDL_Rect dstrect = { 0, 0, texW, texH };

			
			//creating enemies
			std::vector<Enemy*> enemies;

			for (int i = 0; i < NumberEnemies; i++)
			{
				enemies.push_back(new Enemy(i*100, 0));
			}
			
			//Flip type
			SDL_RendererFlip flipType = SDL_FLIP_NONE;

			//While application is running
			while( !quit)
			{

				//Handle events on queue
				while( SDL_PollEvent( &e ) != 0 )
				{
					//User requests quit
				if( e.type == SDL_QUIT )
					{
						quit = true;
					}

					dot.handleEvent(e);
				}

				//rotating
					degrees += 1;


					//collision between enemies and bullets
				for (int i = 0; i < enemies.size(); i++)
				{
					for (int j = 0; j < bulletsUp.size(); j++)
					{
						enemies[i]->move(bulletsUp[j]->getColliders());
					}

					for (int j = 0; j < bulletsLeft.size(); j++)
					{
						enemies[i]->move(bulletsLeft[j]->getColliders());
					}

					for (int j = 0; j < bulletsRight.size(); j++)
					{
						enemies[i]->move(bulletsRight[j]->getColliders());
					}

					enemies[i]->move(dot.getColliders());

					enemies[i]->shoot(enemies[i]->mPosX, enemies[i]->mPosY);

					dot.move( enemies[i]->getColliders());
				}


				//moving of bullets
				for (int i = 0; i < bulletsUp.size(); i++)
				{
					bulletsUp[i]->moveUp(dot.getColliders());
				}

				for (int i = 0; i < bulletsLeft.size(); i++)
				{
					bulletsLeft[i]->moveLeft(dot.getColliders());
				}

				for (int i = 0; i < bulletsRight.size(); i++)
				{
					bulletsRight[i]->moveRight(dot.getColliders());
				}

				for (int i = 0; i < enemyBullets.size(); i++)
				{
					enemyBullets[i]->enemyMove(dot.getColliders());
				}

				//Scroll background
                --scrollingOffset;
                if( scrollingOffset < -gBGTexture.getWidth() )
                {
                    scrollingOffset = 0;
                }

				//Clear screen
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );

				SDL_RenderClear( gRenderer );

				//Render background
                gBGTexture.render( scrollingOffset, 0 );
				SDL_RenderCopy(gRenderer, texture, NULL, &dstrect);
                gBGTexture.render( scrollingOffset + gBGTexture.getWidth(), 0 );

				//Render Dot
				dot.render();

				//displaying enemeies and bullets
				for (int i = 0; i < enemies.size(); i++)
				{
					enemies[i]->render(degrees,flipType);
				}

				for (int i = 0; i < bulletsUp.size(); i++)
				{
					bulletsUp[i]->render();
				}

				for (int i = 0; i < bulletsLeft.size(); i++)
				{
					bulletsLeft[i]->render();
				}

				for (int i = 0; i < bulletsRight.size(); i++)
				{
					bulletsRight[i]->render();
				}

				for (int i = 0; i < enemyBullets.size(); i++)
				{
					enemyBullets[i]->render();
				}

				//Update screen
				SDL_RenderPresent( gRenderer );
			}
		}
	}

	//Free resources and close SDL
	close();

	return 0;
}
示例#12
0
int
main(int argc, char *argv[])
{
	int quit = 0;
	/* event handler */
	SDL_Event event;

	/* the dot that will be moving around the screen */
	Dot dot;

	/* set the wall */
	SDL_Rect wall;
	wall.x = 300;
	wall.y = 40;
	wall.w = 40;
	wall.h = 400;

	/* starts up SDL and create window */
	if (init_sdl() == -1) {
		fprintf(stderr, "Failed to initialize SDL!\n");
		return -1;
	}

	/* load media */
	if (load_media() == -1) {
		fprintf(stderr, "Failed to load media!\n");
		return -2;
	}


	/* main loop */
	while (quit == 0) {
		/* handle events on queue */
		while (SDL_PollEvent(&event) != 0) {
			/* users request quit */
			if (event.type == SDL_QUIT)
				quit = 1;

			/* handle user key press */
			dot.handleEvent(event);
		}

		/* move the dot and check collision */
		dot.move(wall);


		/* clear screen */
		SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
		SDL_RenderClear(gRenderer);

		/* render wall */
		SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0xFF);
		SDL_RenderDrawRect(gRenderer, &wall);

		/* render dot */
		dot.render();

		/* update screen */
		SDL_RenderPresent(gRenderer);
	}

	/* free resources and close */
	close_sdl();

	return 0;
}
示例#13
0
文件: main.cpp 项目: geniusnut/SDL
int main( int argc, char* args[] )
{
    //Quit flag
    bool quit = false;

    //The dot
    Dot myDot;

    //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();

    //Set the tiles
    if( set_tiles( tiles ) == false )
    {
        return 1;
    }

    //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 dot
            myDot.handle_input();

            //If the user has Xed out the window
            if( event.type == SDL_QUIT )
            {
                //Quit the program
                quit = true;
            }
        }

        //Move the dot
        myDot.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();

        //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( tiles );

    return 0;
}
示例#14
0
int main( int argc, char* args[] )
{
	//Start up SDL and create window
	if( !init() )
	{
		printf( "Failed to initialize!\n" );
	}
	else
	{
		//The level tiles
		Tile* tileSet[ TOTAL_TILES ];

		//Load media
		if( !loadMedia( tileSet ) )
		{
			printf( "Failed to load media!\n" );
		}
		else
		{	
			//Main loop flag
			bool quit = false;

			//Event handler
			SDL_Event e;

			//The dot that will be moving around on the screen
			Dot dot;

			//Level camera
			SDL_Rect camera = { 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT };

			//While application is running
			while( !quit )
			{
				//Handle events on queue
				while( SDL_PollEvent( &e ) != 0 )
				{
					//User requests quit
					if( e.type == SDL_QUIT )
					{
						quit = true;
					}

					//Handle input for the dot
					dot.handleEvent( e );
				}

				//Move the dot
				dot.move( tileSet );
				dot.setCamera( camera );

				//Clear screen
				SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
				SDL_RenderClear( gRenderer );

				//Render level
				for( int i = 0; i < TOTAL_TILES; ++i )
				{
					tileSet[ i ]->render( camera );
				}

				//Render dot
				dot.render( camera );

				//Update screen
				SDL_RenderPresent( gRenderer );
			}
		}
		
		//Free resources and close SDL
		close( tileSet );
	}

	return 0;
}
示例#15
0
int main( int argc, char* args[] )
{
    //Quit flag
    bool quit = false;

    //The dot
    Dot myDot;

    //The frame rate regulator
    Timer fps;

    //Initialize
    if( init() == false )
    {
        return 1;
    }

    //Load the files
    if( load_files() == false )
    {
        return 1;
    }

    //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 dot
            myDot.handle_input();

            //If the user has Xed out the window
            if( event.type == SDL_QUIT )
            {
                //Quit the program
                quit = true;
            }
        }

        //Move the dot
        myDot.move();

        //Set the camera
        myDot.set_camera();

        //Show the background
        apply_surface( 0, 0, background, screen, &camera );

        //Show the dot on the screen
        myDot.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;
}