예제 #1
0
파일: game.cpp 프로젝트: jd264/IT276
int main( int argc, char* args[])
{
	//player
	Player myPlayer;

	//fps
	FPS fps;

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

	//load
	if(loadFiles() != false)
	{
		loadLevel(lvlScene);
	}
	else
	{
		return 1;
	}

	//while no quit
	while(quit == false)
	{
		//start timer
		fps.startFPS();

		while(SDL_PollEvent(&event))
		{
			//player event
			myPlayer.getInputPlayer();

			//x out window
			if(event.type == SDL_QUIT)
			{
				quit = true;
			}
		}
		
		//lvlupdate
		updateLevel();

		//player controls
		myPlayer.movePlayer();
		myPlayer.showPlayer(pAlpha);
		
		//SDL_FillRect( screen, &wall, SDL_MapRGB( screen->format, 0x77, 0x77, 0x77 ) );

		//nextlvl
		/*if(nextlvl == true)
		{
			cleanUp();
			nextlvl == false;
		}*/

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

		//cap
		if(fps.getT() < 1000 / fpsNum)
		{
			SDL_Delay((1000 / fpsNum) - fps.getT());
		}
	}

	cleanUp();

	return 0;
}
예제 #2
0
파일: main.cpp 프로젝트: mcteapot/Astroids
//MAIN//
int main( int argc, char* args[] ) {
	//Init Rand to clock 
	srand ( time(NULL) );	
    //Initialize Window
    initSDLWindow( SCREENWIDTH, SCREENHEIGHT, SCREENBPP );
	
    //Load Files
	loadFiles();
	//Create Text
	createText();
	
	//Init classes
    Timer fps;
	Level *theLevel;


    //GAME LOOP//
    while( run ) {
        //Start the frame timer
        fps.start();

		//Init Events for keyboard 
		initSDLEvents();
		
        //Apply the background
        applySurface( 0, 0, background, screen, NULL );
		//MENU
		if ( menu ) {
			applySurface( ( SCREENWIDTH - menuTitle->w ) / 2, (SCREENHEIGHT / 5), menuTitle, screen, NULL );
			applySurface( ( SCREENWIDTH - menuScreen->w ) / 2, (SCREENHEIGHT / 6)*4, menuScreen, screen, NULL );
			if (initSDLEvents() == 'e') {
				menu = 0;
				game = 1;
				theLevel = new Level(screen, SCREENWIDTH, SCREENHEIGHT);
			}
	
		}//MENU END
		//GAME
		if ( game ) {
			
			if ((theLevel->play(frame)) == true) {
				menu = 1;
				game = 0;
				delete theLevel;
			}
			
		}//GAME END

        //Update the screen
        if( SDL_Flip( screen ) == -1 ) {
            return 1;
        }
		//Set frame rate
		setTimer( fps, FRAMESPERSECOND, frame, true );
		
		//check for quit
		checkQuit(initSDLEvents());	
    }//GAME LOOP END//
	
    //Clean up
	quitSDL();
	
    return 0;
}//END MAIN//