Code: Select all
void StateManager::DrawState()
{
if( state == MAIN_MENU )
{
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0, 0, 0 ) );
//TTF_SetFontStyle( comicsans, TTF_STYLE_UNDERLINE );
title = TTF_RenderText_Solid( comicsans, "_________", orange );
ApplySurface( 320 - ( title->clip_rect.w / 2 ), 50, title, screen );
//TTF_SetFontStyle( comicsans, TTF_STYLE_NORMAL );
title = TTF_RenderText_Solid( comicsans, "DUCK HUNT", cyan );
ApplySurface( 320 - ( title->clip_rect.w / 2 ), 50, title, screen );
screen = TTF_RenderCenteredText_Solid( arial, "Start!", white, startDuckHunt.button, screen );
ApplySurface( 272, 224, startDuckHunt.GetImage(), screen, startDuckHunt.nextClip );
screen = TTF_RenderCenteredText_Solid( arial, "High Scores", white, highScores.button, screen );
ApplySurface( 272, 258, highScores.GetImage(), screen, highScores.nextClip );
highestScore = TTF_RenderText_Solid( arcadeclassic, scoresList[0].c_str(), white );
ApplySurface( screen->clip_rect.w / 2 - highestScore->clip_rect.w / 2, 430, highestScore, screen );
SDL_Flip( screen );
}
if( state == DUCK_HUNT )
{
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0, 0, 0 ) );
ApplySurface( 0, 410, gUI, screen );
ApplySurface( 30, 415, gUIShot, screen );
switch( shotsRemaining )
{
case 1: ApplySurface( 15, 440, gUIBullet, screen ); break;
case 2: ApplySurface( 15, 440, gUIBullet, screen ); ApplySurface( 42, 440, gUIBullet, screen ); break;
case 3: ApplySurface( 15, 440, gUIBullet, screen ); ApplySurface( 42, 440, gUIBullet, screen ); ApplySurface( 70, 440, gUIBullet, screen ); break;
}
gUIPoints = TTF_RenderText_Solid( arialLarge, scoreBuf.c_str(), white );
if( atoi( scoreBuf.c_str() ) != score )
{
scoreBuf = intToString( score );
}
ApplySurface( 120, 415, gUIHit, screen );
ApplySurface( 555, 415, gUIScore, screen );
ApplySurface( 543, 435, gUIPoints, screen );
SDL_Flip( screen );
}
if( state == HIGH_SCORES )
{
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0, 0, 0 ) );
if( score > (unsigned int)atoi( scores[1].c_str() ) )
{
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 128, 128, 255 ) );
name.Show( 250, 380, screen, false );
}
highestScore = TTF_RenderText_Solid( arcadeclassic, scoresList[0].c_str(), white );
ApplySurface( 250, 40, highestScore, screen );
highestScore = TTF_RenderText_Solid( arcadeclassic, scoresList[1].c_str(), white );
ApplySurface( 250, 100, highestScore, screen );
highestScore = TTF_RenderText_Solid( arcadeclassic, scoresList[2].c_str(), white );
ApplySurface( 250, 160, highestScore, screen );
highestScore = TTF_RenderText_Solid( arcadeclassic, scoresList[3].c_str(), white );
ApplySurface( 250, 220, highestScore, screen );
highestScore = TTF_RenderText_Solid( arcadeclassic, scoresList[4].c_str(), white );
ApplySurface( 250, 280, highestScore, screen );
screen = TTF_RenderCenteredText_Solid( arial, "Back", white, back.button, screen );
ApplySurface(20, 444, back.GetImage(), screen, back.nextClip );
SDL_Flip( screen );
}
}
void StateManager::SoundState()
{
if( state == MAIN_MENU )
{
}
}
void StateManager::EventState()
{
if( state == MAIN_MENU )
{
time = SDL_GetTicks();
previousState = MAIN_MENU;
while( SDL_PollEvent( &event ) )
{
if( startDuckHunt.Check( event ) )
{
state = DUCK_HUNT;
SDL_WM_SetCaption( "Duck Hunt", NULL );
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0, 0, 0 ) );
}
if( highScores.Check( event ) )
{
back.Reset();
state = HIGH_SCORES;
SDL_WM_SetCaption( "High Scores", NULL );
SDL_FillRect( screen, &screen->clip_rect, SDL_MapRGB( screen->format, 0, 0, 0 ) );
}
if( event.type == SDL_QUIT )
{
quit = true;
}
}
stateManager.DrawState();
while( framesPerSecond / 1000 > SDL_GetTicks() - time )
{
}
}
if( state == DUCK_HUNT )
{
time = SDL_GetTicks();
previousState = DUCK_HUNT;
while( SDL_PollEvent( &event ) )
{
if( event.type == SDL_KEYDOWN )
{
if( event.key.keysym.sym == SDLK_TAB )
{
back.Reset();
state = HIGH_SCORES;
}
}
if( event.type == SDL_QUIT )
{
quit = true;
}
}
stateManager.DrawState();
}
if( state == HIGH_SCORES )
{
time = SDL_GetTicks();
while( SDL_PollEvent( &event ) )
{
if( score > (unsigned int)atoi( scores[1].c_str() ) && previousHuntState == GAME_OVER )
{
if( event.type == SDL_KEYDOWN )
{
name.HandleInput( event, arcadeclassic, white );
}
if( name.GetString().length() == 3 && score > (unsigned int)atoi( scores[1].c_str() ) )
{
newHighScore( name.GetString().c_str(), score );
}
}
if( back.Check( event ) )
{
state = previousState;
highScores.Reset();
startDuckHunt.Reset();
}
if( event.type == SDL_QUIT )
{
quit = true;
}
}
stateManager.DrawState();
}
}