Guest User

Untitled

a guest
Nov 24th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. #include "Splash.h"
  2. #include "Globals.h"
  3.  
  4. namespace Game
  5. {
  6. Splash::Splash( sf::RenderWindow *Window, KeyHelper *KH )
  7. : Finished( false ),
  8. Win( Window ),
  9. KeyHelp( KH ),
  10. Frame( 0 ),
  11. DisplayTime( 60 ),
  12. FadeFrames( 30 ),
  13. StartDelay( 60 ),
  14. Bg( sf::Shape::Rectangle( 0.f, 0.f, ( float )MAX_X, ( float )MAX_Y, sf::Color( 0, 0, 0 ) ) )
  15. {
  16. Bg.SetColor( sf::Color( 0, 0, 0, 255 ) );
  17.  
  18. sf::Text *Sc1T1 = new sf::Text( "I'M NOT A RACIST!", sf::Font::GetDefaultFont(), MENU_FONT_SIZE );
  19. Sc1T1->SetPosition( MAX_X / 2.f - Sc1T1->GetRect().Width / 2.f, MAX_Y / 2.f - Sc1T1->GetRect().Height / 2.f );
  20. Sc1T1->SetOrigin( 0.f, Sc1T1->GetRect().Height / 2.f );
  21. SplashScreen *Screen1 = new SplashScreen;
  22. Screen1->Obj.push_back( Sc1T1 );
  23.  
  24. sf::Text *Sc2T1 = new sf::Text( "I'm a melting pot of friendship.", sf::Font::GetDefaultFont(), MENU_FONT_SIZE );
  25. Sc2T1->SetPosition( MAX_X / 2.f - Sc2T1->GetRect().Width / 2.f, MAX_Y / 2.f - Sc2T1->GetRect().Height / 2.f );
  26. Sc2T1->SetOrigin( 0.f, Sc2T1->GetRect().Height / 2.f );
  27. SplashScreen *Screen2 = new SplashScreen;
  28. Screen2->Obj.push_back( Sc2T1 );
  29.  
  30. Screens.push_back( Screen1 );
  31. Screens.push_back( Screen2 );
  32.  
  33. ULoop();
  34. }
  35.  
  36. Splash::~Splash()
  37. {
  38. for( std::vector<SplashScreen *>::iterator iter = Screens.begin(); iter != Screens.end(); iter++ )
  39. {
  40. for( std::vector<sf::Drawable *>::iterator iter2 = ( *iter )->Obj.begin(); iter2 != ( *iter )->Obj.end(); iter2++ )
  41. delete *iter2;
  42.  
  43. delete *iter;
  44. }
  45. }
  46.  
  47. void Splash::ULoop()
  48. {
  49. while( !Finished )
  50. {
  51. if( KeyHelp->KeyClick( sf::Key::Escape ) )
  52. Finished = true;
  53.  
  54. sf::Event event;
  55. while ( Win->GetEvent( event ) )
  56. {
  57. switch( event.Type )
  58. {
  59. case( sf::Event::Closed ): Win->Close(); break;
  60. }
  61. }
  62.  
  63. Win->Clear( sf::Color::Black );
  64.  
  65. if( StartDelay > 0 )
  66. StartDelay--;
  67. else
  68. {
  69. Frame++;
  70. Draw( ( unsigned int )floor( ( float )Frame / ( float )( DisplayTime + FadeFrames * 2 ) ) );
  71. Win->Draw( Bg );
  72. }
  73.  
  74. Win->Display();
  75. }
  76. }
  77.  
  78. void Splash::Draw( unsigned int Pos )
  79. {
  80. if( Pos > Screens.size() - 1 )
  81. {
  82. Finished = true;
  83. return;
  84. }
  85.  
  86. DoFade( Pos );
  87. for( std::vector<sf::Drawable *>::iterator iter = Screens[Pos]->Obj.begin(); iter != Screens[Pos]->Obj.end(); iter++ )
  88. Win->Draw( **iter );
  89. }
  90.  
  91. void Splash::DoFade( int Pos )
  92. {
  93. if( ( Frame - Pos * ( DisplayTime + FadeFrames * 2 ) ) <= FadeFrames )
  94. Bg.SetColor( sf::Color( 0, 0, 0, ClampInt( Bg.GetColor().a - ( int )( 255.f / ( float )FadeFrames ), 0, 255 ) ) );
  95.  
  96. if( ( Frame - Pos * ( DisplayTime + FadeFrames * 2 ) ) >= DisplayTime + FadeFrames )
  97. Bg.SetColor( sf::Color( 0, 0, 0, ClampInt( Bg.GetColor().a + ( int )( 255.f / ( float )FadeFrames ), 0, 255 ) ) );
  98. }
  99. }
Add Comment
Please, Sign In to add comment