Exemplo n.º 1
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 );
}
Exemplo n.º 2
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;
}
Exemplo n.º 3
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;
}