Пример #1
0
int SDLU_EventFilter( const SDL_Event *event )
{
	switch( event->type ) {
		// Put keydowns in a buffer
		case SDL_KEYDOWN:
			if(    s_interestedInTyping
			    && event->key.keysym.sym < 300
			    && s_keyBufferFilled < sizeof(s_keyBufferASCII) )
			{
				s_keyBufferFilled++;
				s_keyBufferASCII[s_keyBufferPutAt] = event->key.keysym.unicode;
				s_keyBufferSDL  [s_keyBufferPutAt] = event->key.keysym.sym;
				s_keyBufferPutAt = (s_keyBufferPutAt + 1) % sizeof(s_keyBufferASCII);
			}

			if( ((event->key.keysym.sym == SDLK_F4) &&
			    (event->key.keysym.mod & (KMOD_LALT | KMOD_RALT))) ||
			    ((event->key.keysym.sym == SDLK_q) &&
			    (event->key.keysym.mod & (KMOD_LMETA | KMOD_RMETA))) )
			{
				finished = true;
			}

			break;

		case SDL_MOUSEBUTTONDOWN:
			if( event->button.button == SDL_BUTTON_LEFT )
				s_mouseButton = true;

			s_mousePosition.y = event->button.y;
			s_mousePosition.x = event->button.x;
			break;

		case SDL_MOUSEBUTTONUP:
			if( event->button.button == SDL_BUTTON_LEFT )
				s_mouseButton = false;

			s_mousePosition.y = event->button.y;
			s_mousePosition.x = event->button.x;
			break;

		case SDL_MOUSEMOTION:
			s_mousePosition.y = event->motion.y;
			s_mousePosition.x = event->motion.x;
			s_mouseButton = event->motion.state & SDL_BUTTON(1);
			break;

		case SDL_QUIT:
			finished = true;
			break;

		// Handle gaining and losing focus (kind of cheesy)
		case SDL_ACTIVEEVENT:
			if( (event->active.state & SDL_APPINPUTFOCUS) )
			{
				if( !event->active.gain && s_isForeground )
				{
					FreezeGameTickCount();
					PauseMusic();
					s_isForeground = false;
				}
				else if( event->active.gain && !s_isForeground )
				{
					UnfreezeGameTickCount();
					ResumeMusic();
					s_isForeground = true;

					DoFullRepaint();
				}
			}
			break;
	}
	return 0;
}
Пример #2
0
int main(int argc, char *argv[])
{
	// Initialize the SDL library
	// This is required to avoid _main errors at runtime.
#ifdef UseSDLMixer
	if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) {
#else
	if ( SDL_Init(SDL_INIT_VIDEO ) < 0 ) {
#endif		
		fprintf(stderr, "Couldn't initialize SDL: %s\n",
				SDL_GetError());
		exit(1);
	}

	// Init SDL_Image - only applies above 1.2.7
	// load support for the JPG and PNG image formats
	int IMGflags=IMG_INIT_JPG|IMG_INIT_PNG;
	int initted=IMG_Init(IMGflags);
	if(initted && IMGflags != IMGflags) {
		printf("IMG_Init: Failed to init required jpg and png support!\n");
		printf("IMG_Init: %s\n", IMG_GetError());
		// handle error
	}

		
#ifdef UseSDLMixer
	// Initialize SDL mixer.
	if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) != 0) {
		fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError());
		exit(1);
	}
#endif
    
    // Retrieve display gamma for reference in fade in/fade out routines.
    SDL_GetGammaRamp(redGamma, greenGamma, blueGamma);
//    printf("%u", *redGamma);
	Initialize( );	

	LoadPrefs( );
	
	ReserveMonitor( );	
	ShowTitle( );
	
	ChooseMusic( 13 );
	
	while( !finished )
	{
		if( showStartMenu )
		{
			GameStartMenu( );
			showStartMenu = false;
		}
		
		if( !finished )
		{
			DoFullRepaint = NeedRefresh;
			CheckKeys( );
			HandlePlayers( );
			UpdateOpponent( );
			UpdateBalloon( );
			UpdateSound( );
			DoFullRepaint = NoPaint;
			
			if( needsRefresh )
			{
				RefreshAll();
				needsRefresh = false;
			}
			
			if( !showStartMenu && pauseKey )
			{
				FreezeGameTickCount( );
				PauseMusic( );
				MaskRect( &playerWindowRect[0] );
				MaskRect( &playerWindowRect[1] );
				WaitForRelease( );
				
				HandleDialog( kPauseDialog );
								
				WaitForRelease( );
				RefreshPlayerWindow( 0 );
				RefreshPlayerWindow( 1 );
				ResumeMusic( );
				UnfreezeGameTickCount( );
			}
		}
	}
	
	SavePrefs( );
	ReleaseMonitor( );
	
	return 0;
}

void NoPaint( void )
{
}

void MaskRect( MRect *r )
{
	SDL_Rect sdlRect;
	SDLU_MRectToSDLRect( r, &sdlRect );
	SDLU_BlitFrontSurface( backdropSurface, &sdlRect, &sdlRect );
}