Exemplo n.º 1
0
void InitOpponent( void )
{
	MRect    littleRect = {0, 0, 64, 64}, bigRect = {0, 0, 64, 64*(kOppFrames*3) };
	SDL_Rect sdlRect;
	double   index, value;
	
	opponentDrawSurface = SDLU_InitSurface( SDLU_MRectToSDLRect( &littleRect, &sdlRect ), 16 );
	opponentSurface     = SDLU_InitSurface( SDLU_MRectToSDLRect( &bigRect, &sdlRect ), 16 );

	bigRect.bottom *= kGlows + 1;
	opponentMaskSurface = SDLU_InitSurface( SDLU_MRectToSDLRect( &bigRect, &sdlRect ), 1 );
	
	opponentWindowZRect.top = opponentWindowZRect.left = 0;
	opponentWindowZRect.bottom = opponentWindowZRect.right = 64;
	opponentWindowRect = opponentWindowZRect;
	CenterRectOnScreen( &opponentWindowRect, 0.5, 0.5 );
		
	opponentMood = 0;
	
	for( index=0; index<kGlowArraySize; index++ )
	{
		value = sin( index*pi/kGlowArraySize );
		value *= value;
		
		heavyGlowArray[(int)index] = (int)(value * 24.0);
		glowArray     [(int)index] = (int)(value * 16.0);
		lightGlowArray[(int)index] = (int)(value * 12.0);
	}
}
Exemplo n.º 2
0
void DrawFrozenOpponent( void )
{
	SDL_Rect   sourceSDLRect, destSDLRect;
	MRect      myRect = {0, 0, 64, 64};

	OffsetMRect( &myRect, opponentFrame * 64, 0 );

	SDLU_BlitFrontSurface( opponentSurface, 
	                       SDLU_MRectToSDLRect( &myRect, &sourceSDLRect ),
	                       SDLU_MRectToSDLRect( &opponentWindowRect, &destSDLRect ) );
}
Exemplo n.º 3
0
void UpdateBalloon( void )
{
	SDL_Rect balloonSDLRect;
	
	if( control[0] != kAutoControl ) return;
	if( GameTickCount() < balloonTime ) return;
	
	if( balloonChar )
	{
		char in = *balloonChar++;
				
		switch( in )
		{
			case 0:
				OpponentChatter( false );
				balloonChar = NULL;
				balloonTime += 120;
				break;
				
			case '\n':
				balloonPt.h = balloonRect.left + 10;
				balloonPt.v += 20;
				break;
				
			default:
				if( balloonFont->width[in] > 0 )
				{
					SDLU_AcquireSurface( balloonSurface );
					SurfaceBlitCharacter( balloonFont, in, &balloonPt, 0, 0, 0, 0 );
					SDLU_ReleaseSurface( balloonSurface );
					
					SDLU_MRectToSDLRect( &balloonRect, &balloonSDLRect );
					SDLU_BlitFrontSurface( balloonSurface, &balloonSDLRect, &balloonSDLRect );

					balloonTime += 2;
				}
				break;			
		}	
	}
	else
	{
		SDLU_MRectToSDLRect( &balloonRect, &balloonSDLRect );
		SDLU_BlitFrontSurface( backdropSurface, &balloonSDLRect, &balloonSDLRect );
		                    
		StopBalloon();
	}
}
Exemplo n.º 4
0
void CleanSpriteArea( int player, MRect *myRect )
{
	SDL_Rect sdlRect;

	SDLU_MRectToSDLRect( myRect, &sdlRect );
	
	SDLU_BlitSurface( playerSurface[player],       &sdlRect,
	                  playerSpriteSurface[player], &sdlRect  );
		
	SetUpdateRect( player, myRect );
}
Exemplo n.º 5
0
void StartBalloon( const char *message )
{
	MPoint      balloonTip, balloonFill;
	int         replace;
	const char* match[] = { "~~", "||", "``", "{{" };
	char*       search;
	SDL_Rect    balloonSDLRect, balloonContentsSDLRect;
	MRect       balloonContentsRect;
	
	strcpy( balloonMsg, message );
	for( replace=0; replace<4; replace++ )
	{
		search = strstr( balloonMsg, match[replace] );
		if( search )
		{
			char temp[256];
			
			search[0] = '%';
			search[1] = 's';
			sprintf( temp, balloonMsg, SDL_GetKeyName( playerKeys[1][replace] ) );
			strcpy( balloonMsg, temp );
		}
	}
	
	// Erase previous balloons
	SDLU_MRectToSDLRect( &balloonRect, &balloonSDLRect );
	SDLU_BlitFrontSurface( backdropSurface, &balloonSDLRect, &balloonSDLRect );

	// Draw empty balloon outline
	SDLU_AcquireSurface( balloonSurface );

	balloonRect.left = balloonRect.right - 25 - CalculateBalloonWidth ( balloonMsg );
	balloonRect.top = balloonRect.bottom - 25 - CalculateBalloonHeight( balloonMsg );

	SDLU_MRectToSDLRect( &balloonRect, &balloonSDLRect );
	SDLU_BlitSurface( backdropSurface, &balloonSDLRect,
	                  balloonSurface,  &balloonSDLRect  );
	
	balloonContentsRect = balloonRect;
	balloonContentsRect.bottom -= 25;
		
	SurfaceGetEdges( balloonSurface, &balloonContentsRect );
	SDL_FillRect( balloonSurface, 
				  SDLU_MRectToSDLRect( &balloonContentsRect, &balloonContentsSDLRect ), 
				  SDL_MapRGB( balloonSurface->format, 0xFF, 0xFF, 0xFF ) );
	SurfaceCurveEdges( balloonSurface, &balloonContentsRect );
	
	balloonTip.v = balloonContentsRect.bottom - 2;
	balloonTip.h = balloonContentsRect.right - 40;
	balloonFill = balloonTip;

	SurfaceBlitCharacter( balloonFont, '\x01', &balloonFill,  0,  0,  0,  0 );
	SurfaceBlitCharacter( balloonFont, '\x02', &balloonTip,  31, 31, 31,  0 );
	
	SDLU_ReleaseSurface( balloonSurface );

	// Blit empty balloon to screen
	SDLU_MRectToSDLRect( &balloonRect, &balloonSDLRect );
	SDLU_BlitFrontSurface( balloonSurface, &balloonSDLRect, &balloonSDLRect );
	
	balloonPt.h = balloonRect.left + 10;
	balloonPt.v = balloonRect.top + 10;
	balloonChar = balloonMsg;
	balloonTime = GameTickCount( );
	
	OpponentChatter( true );
}
Exemplo n.º 6
0
void UpdateOpponent( void )
{
	MRect    myRect = {0,0,64,64}, dstRect = {0,0,64,64}, maskRect;
	int      emotiMap[] = {0, 1, 2, 1}, draw = false, count;
	SDL_Rect srcSDLRect, dstSDLRect;
	
	if( GameTickCount( ) > opponentTime )
	{
		switch( opponentMood )
		{
			case 0: 				// Idle
				opponentTime += 60 + RandomBefore(180);
				opponentMood = RandomBefore(2) + 1;
				opponentFrame = (emotiMap[emotions[1]] * kOppFrames);
				break;
			
			case 1:					// Shifty Eyes
				opponentTime += 40 + RandomBefore(60);
				opponentMood = 0;
				opponentFrame = (emotiMap[emotions[1]] * kOppFrames) + RandomBefore(2) + 1;
				break;

			case 2:					// Blinks
				opponentTime += 3;
				opponentMood = 3;
				opponentFrame = (emotiMap[emotions[1]] * kOppFrames) + 3;
				break;
			
			case 3:					// Blinks (more)
				opponentTime += 3;
				opponentMood = 4;
				opponentFrame = (emotiMap[emotions[1]] * kOppFrames) + 4;
				break;
			
			case 4: 				// Blinks (more)
				opponentTime += 3;
				opponentMood = 0;
				opponentFrame = (emotiMap[emotions[1]] * kOppFrames) + 3;
				break;
			
			case 5:                 // Chatter (only good for tutorial)
				opponentTime += 8;
				opponentMood = 6;
				opponentFrame = 5;
				break;

			case 6:					// Chatter 2 (only good for tutorial)
				opponentTime += 8;
				opponentMood = 5;
				opponentFrame = 6;
				break;
			
			case 7:					// Pissed (when hit with punishments)
				opponentTime += 60;
				opponentFrame = 7;
				opponentMood = 0;
				break;
		}
		
		draw = true;
	}
	
	if( GameTickCount( ) > panicTime )
	{
		panicTime += 2;
		
		if( emotions[1] == kEmotionPanic )
		{
			if( ++panicFrame >= kGlowArraySize ) panicFrame = 0;
			draw = true;
		}
		else
		{
			panicFrame = 0;
		}
	}
	
	for( count=0; count<kGlows; count++ )
	{
		if( GameTickCount( ) > glowTime[count] )
		{
			glowTime[count] += character[1].glow[count].time;
			
			if( character[1].glow[count].color )
			{
				if( ++glowFrame[count] >= kGlowArraySize ) glowFrame[count] = 0;
				draw = true;
			}
			else
			{
				glowFrame[count] = 0;
			}
		}
	}
	
	if( draw )
	{
		OffsetMRect( &myRect, 64*opponentFrame, 0 );
		
		SDLU_AcquireSurface( opponentDrawSurface );
		
		SDLU_BlitSurface( opponentSurface,     SDLU_MRectToSDLRect( &myRect, &srcSDLRect ),
		                  opponentDrawSurface, SDLU_MRectToSDLRect( &dstRect, &dstSDLRect )  );
		
		maskRect = myRect;
		for( count=0; count<kGlows; count++ )
		{
			OffsetMRect( &maskRect, 0, 64 );

			if( glowFrame[count] )
			{
				if( character[1].glow[count].color & 0x8000 )
				{
					SurfaceBlitColor(  opponentMaskSurface,  opponentDrawSurface,
					                  &maskRect,            &dstRect, 
					                   (character[1].glow[count].color & 0x7C00) >> 10,
									   (character[1].glow[count].color & 0x03E0) >> 5,
									   (character[1].glow[count].color & 0x001F),
									   heavyGlowArray[glowFrame[count]] );
				}
				else
				{
					SurfaceBlitColor(  opponentMaskSurface,  opponentDrawSurface,
					                  &maskRect,            &dstRect, 
					                   (character[1].glow[count].color & 0x7C00) >> 10,
									   (character[1].glow[count].color & 0x03E0) >> 5,
									   (character[1].glow[count].color & 0x001F),
									   lightGlowArray[glowFrame[count]] );
				}
			}
		}
Exemplo n.º 7
0
Arquivo: main.cpp Projeto: boredzo/CCX
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 );
}