Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Splash.h"
- #include "Globals.h"
- namespace Game
- {
- Splash::Splash( sf::RenderWindow *Window, KeyHelper *KH )
- : Finished( false ),
- Win( Window ),
- KeyHelp( KH ),
- Frame( 0 ),
- DisplayTime( 60 ),
- FadeFrames( 30 ),
- StartDelay( 60 ),
- Bg( sf::Shape::Rectangle( 0.f, 0.f, ( float )MAX_X, ( float )MAX_Y, sf::Color( 0, 0, 0 ) ) )
- {
- Bg.SetColor( sf::Color( 0, 0, 0, 255 ) );
- sf::Text *Sc1T1 = new sf::Text( "I'M NOT A RACIST!", sf::Font::GetDefaultFont(), MENU_FONT_SIZE );
- Sc1T1->SetPosition( MAX_X / 2.f - Sc1T1->GetRect().Width / 2.f, MAX_Y / 2.f - Sc1T1->GetRect().Height / 2.f );
- Sc1T1->SetOrigin( 0.f, Sc1T1->GetRect().Height / 2.f );
- SplashScreen *Screen1 = new SplashScreen;
- Screen1->Obj.push_back( Sc1T1 );
- sf::Text *Sc2T1 = new sf::Text( "I'm a melting pot of friendship.", sf::Font::GetDefaultFont(), MENU_FONT_SIZE );
- Sc2T1->SetPosition( MAX_X / 2.f - Sc2T1->GetRect().Width / 2.f, MAX_Y / 2.f - Sc2T1->GetRect().Height / 2.f );
- Sc2T1->SetOrigin( 0.f, Sc2T1->GetRect().Height / 2.f );
- SplashScreen *Screen2 = new SplashScreen;
- Screen2->Obj.push_back( Sc2T1 );
- Screens.push_back( Screen1 );
- Screens.push_back( Screen2 );
- ULoop();
- }
- Splash::~Splash()
- {
- for( std::vector<SplashScreen *>::iterator iter = Screens.begin(); iter != Screens.end(); iter++ )
- {
- for( std::vector<sf::Drawable *>::iterator iter2 = ( *iter )->Obj.begin(); iter2 != ( *iter )->Obj.end(); iter2++ )
- delete *iter2;
- delete *iter;
- }
- }
- void Splash::ULoop()
- {
- while( !Finished )
- {
- if( KeyHelp->KeyClick( sf::Key::Escape ) )
- Finished = true;
- sf::Event event;
- while ( Win->GetEvent( event ) )
- {
- switch( event.Type )
- {
- case( sf::Event::Closed ): Win->Close(); break;
- }
- }
- Win->Clear( sf::Color::Black );
- if( StartDelay > 0 )
- StartDelay--;
- else
- {
- Frame++;
- Draw( ( unsigned int )floor( ( float )Frame / ( float )( DisplayTime + FadeFrames * 2 ) ) );
- Win->Draw( Bg );
- }
- Win->Display();
- }
- }
- void Splash::Draw( unsigned int Pos )
- {
- if( Pos > Screens.size() - 1 )
- {
- Finished = true;
- return;
- }
- DoFade( Pos );
- for( std::vector<sf::Drawable *>::iterator iter = Screens[Pos]->Obj.begin(); iter != Screens[Pos]->Obj.end(); iter++ )
- Win->Draw( **iter );
- }
- void Splash::DoFade( int Pos )
- {
- if( ( Frame - Pos * ( DisplayTime + FadeFrames * 2 ) ) <= FadeFrames )
- Bg.SetColor( sf::Color( 0, 0, 0, ClampInt( Bg.GetColor().a - ( int )( 255.f / ( float )FadeFrames ), 0, 255 ) ) );
- if( ( Frame - Pos * ( DisplayTime + FadeFrames * 2 ) ) >= DisplayTime + FadeFrames )
- Bg.SetColor( sf::Color( 0, 0, 0, ClampInt( Bg.GetColor().a + ( int )( 255.f / ( float )FadeFrames ), 0, 255 ) ) );
- }
- }
Add Comment
Please, Sign In to add comment