Пример #1
0
/**
 * @function main  
 */
int main( int argc, char *argv[] ) {

	bool quit = false;
	countPath = 0;

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

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

	//-- Clip tiles
	clip_tiles();

	//-- Create grid
    Grid2D g( SIZE_X, SIZE_Y );

	//-- Create HomoPath object
    HP2D h( &g );

	//-- Put the obstacles in the borders
    createBorderingObstacles( &g );

	//-- Display options
	display_options();

	//-- Start SDL
	while( quit == false ) {
		while( SDL_PollEvent( &event ) ) {

			if( event.type == SDL_QUIT ) {
				quit = true;
			}
			else if( event.type == SDL_KEYDOWN ) {
				switch( event.key.keysym.sym ) {
					case 's': {
						printf("-- Starting planner \n"); 
						MOUSE_MODE = -1;
						CallPlanner( &g, &h );
						printf("--* To see options again press [q] \n");	
						break;
					}
					case 'v': {
						printf("-- Click one location to be the initial vertex \n");
						MOUSE_MODE = 0;
						break;
					}
					case 'o': {
						printf("-- Click one location to be obstacle \n");
						MOUSE_MODE = 1;
						break;
					}
					case 'x': {
						printf("-- Pick a grid to check the possible paths \n");
						MOUSE_MODE = 2;
						countPath = 0; // Start seeing the first path
						break;
					}
					case 'p': {
						printf("-- Check available paths for designated grid \n");
						countPath++;
						countPath = ( countPath % numPaths );
					}
					case 'q': {
						display_options();
					}
				}
			}

			else if( event.type == SDL_MOUSEBUTTONDOWN ) {
				if( event.button.button == SDL_BUTTON_LEFT ) {

					int x = event.button.x;
					int y = event.button.y;					
					Pos p = GetMousePos( x, y );

					switch( MOUSE_MODE ) {
						case 0: {
							printf("--> V0 located at (%d, %d) \n", p.x, p.y );
							p0.x = p.x; 
							p0.y = p.y;
							printf("--* To see options again press [q] \n");	
							break;
						}
						case 1: {
							printf("--> Obstacle located at (%d, %d) \n", p.x, p.y );
							if( g.GetState(p) == false ) { 	
								g.SetState( p, true ); 
							}
							else {
								g.SetState( p, false );
							}
							printf("--* To see options again press [q] \n");			
							break;
						}
						case 2: {
							printf( "--> Locating paths for (%d %d) \n", p.x, p.y );
							gPaths = h.PrintPath(p);
							numPaths = gPaths.size();
							printf("--* To see options again press [q] \n");			
							break;
						}

					}

				}
			}

		//-- Draw
		DrawScene( &g );

		} // end while SDL_PollEvent
		

	} // end while quit

	clean_up();
    return 0;
	
}
Пример #2
0
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;
}
Пример #3
0
int main( int argc, char* args[] )
{
    bool quit = false;
    bool debug = false;
    int level = 1;
    Player control(200,700);
    Ball bullet(200 + PADDLE_WIDTH/2, 500);
    int tilesDestroyed = 0;

    float startTicks = 0;
    float deltaTicks = 0;
    char ballVelX[5];
    char ballVelY[5];
    char playerLife[5];


    Tile *tiles[TOTAL_TILES];
    int destroyedTile[TOTAL_TILES];


    for( int t = 0; t < TOTAL_TILES; t++ )
    {
       destroyedTile[t] = false;
    }

    if(init() == false)
    {
        return 5;
    }

    if(load_files() == false)
    {
        return 6;
    }

   clip_tiles();

   if( set_tiles( tiles , level ) == false )
   {
       return 1;
   }   

    startTicks = SDL_GetTicks();

    while(quit == false)
    {
        tilesDestroyed = 0;
        while(SDL_PollEvent(&event))
        {
           if((event.type == SDL_KEYDOWN))
            {

                if(event.key.keysym.sym == SDLK_1 && debug == true)//Adjusting velocity via the 1 number key in debuging mode
                {
                    bullet.xVelocity += 100;
                    bullet.yVelocity += 100;
                }
                else if(event.key.keysym.sym == SDLK_2 && debug == true)//Adjusting velocity via the 2 number key in debuging mode
                {
                    bullet.xVelocity -= 100;
                    bullet.yVelocity -= 100;
                }
                else if(event.key.keysym.sym == SDLK_F1)//Enabling or disabling debuging mode ( information of velocities)
                {
                    if(debug == false)
                    {
                        debug = true;
                    }
                    else
                    {
                        debug = false;
                    }

                }
            }

            control.handle_input();//Handle the paddle's movement

            if(event.type == SDL_QUIT)
            {
                quit = true;
            }
        }

        deltaTicks = SDL_GetTicks() - startTicks;//Frame rate
        control.move(deltaTicks);
        bullet.move(control.player,tiles,deltaTicks,destroyedTile);//Moving the ball

        SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0x00, 0x00, 0x00 ) );//Black color every frame


        for( int t = 0; t < TOTAL_TILES; t++ )
        {
           if(destroyedTile[t] == 0)
           {
               tiles[ t ]->show();

           }
        }

        control.show();
        bullet.show();

        sprintf(ballVelX,"xVel %d",bullet.xVelocity);//Formating text to be displayed for the HUD
        sprintf(ballVelY,"yVel %d",bullet.yVelocity);
        sprintf(playerLife,"Life : %d",bullet.life);

        showBallvelocityX = TTF_RenderText_Solid(font,ballVelX,textColor);
        showBallvelocityY = TTF_RenderText_Solid(font,ballVelY,textColor);

        life = TTF_RenderText_Solid(font,playerLife,textColor);

        apply_surface(20, 10, life, screen );

        if(debug == true)
        {
            apply_surface(20, 50, showBallvelocityX, screen );
            apply_surface(20, 70, showBallvelocityY, screen );
            SDL_FreeSurface(showBallvelocityY);
            SDL_FreeSurface(showBallvelocityX);
        }

        startTicks = SDL_GetTicks();
        deltaTicks = 0;


        for( int t = 0; t < TOTAL_TILES; t++ )//Checking how many tiles are destroyed in the game
        {
           if(destroyedTile[t] == 1)
           {
               tilesDestroyed++;
           }
        }


        if(bullet.life == 0 || tilesDestroyed == TOTAL_TILES)//Close the game if life drops to zero or all the tiles are destroyed in the game
        {
            quit = true;
        }

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


    clean_up();
    return 0;

}
Пример #4
0
int main( int argc, char* args[] )
{

    quit = 0;
    Tile *tiles[ TOTAL_TILES ];

    Timer fps;    levelwon = 0;

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

        if( TTF_Init() == -1 )
        {
            return false;
        }


        //Initialize SDL_mixer
        if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) == -1 )
        {
            return false;
        }

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

        //Clip the tile sheeti
        if( Mix_PlayMusic( music, -1 ) == -1 ) { return 1; }

        clip_tiles();

        if(!welcome)return 1;
        SDL_BlitSurface(welcome, NULL, screen, NULL );
        SDL_Flip( screen );
        SDL_Delay(6000);

        robin robinp;

    while(quit ==false)
    {

        if(level!= 1)
        {
            SDL_BlitSurface( prepare, NULL, screen, NULL );
            SDL_Flip(screen);
            SDL_Delay(3000);
        }

        robinp.reset();

        //Set the tiles
        if( set_tiles( tiles ) == false )
        {
            return 1;
        }
       // SDL_Delay(3000);
        first=1;
    /////////////////////////////////////////////////////////////////////////////////////
        while( quit == false && levelwon == 0)///////////////////////////////////
        {

            //Start the frame timer
            fps.start();

            //While there's events to handle
            while( SDL_PollEvent( &event ) )
            {

              robinp.handle_events();


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

            SDL_BlitSurface( background, NULL, screen, NULL );


            robinp.move(tiles);
            robinp.set_camera();

         for( int t = 0; t < TOTAL_TILES; t++ )
            {
                tiles[ t ]->show();
            }


        for(int i=0;i< en_num;i++)
        {
            enemys[en_num]->show();        //robinp.reset();
        }


            robinp.show();
            showscore();

            //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(tiles);
        level++;
        levelwon = 0;
    /////////////////////////////////////////////////////////////////////////////////////
        //cout<<"out of level";
    }


        SDL_FreeSurface( background );
        SDL_FreeSurface( gameover );
         SDL_FreeSurface( tileSheet );

        //Free the music
        Mix_FreeMusic( music );
        Mix_FreeChunk( jumpsou );
        Mix_FreeChunk( coinsou );
        Mix_FreeChunk( hitsou );
        Mix_FreeChunk( diamoundsou );

        //Close the font
        TTF_CloseFont( font );

        //Quit SDL_mixer
        Mix_CloseAudio();
          SDL_Quit();
        //Quit SDL_ttf
        TTF_Quit();

    return 0;

    }