Advertisement
spacechase0

Shiny Key

Jan 9th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. Bonus::Bonus( const std::string& theName, sf::Texture& mainTex, sf::Texture& shineTex, sf::Vector2f pos )
  2.    : name( theName ),
  3.      doesShine( true ),
  4.      shineCounter( 0 )
  5. {
  6.     spr.SetTexture( mainTex );
  7.     spr.SetPosition( pos );
  8.    
  9.     shineSpr.SetTexture( shineTex );
  10.     shineSpr.SetPosition( pos.x + 10, pos.y + 4 );
  11.     shineSpr.SetScale( 0.1, 0.1 );
  12.     shineSpr.SetOrigin( 10, 4 );
  13. }
  14.  
  15. void Bonus::Render( sf::RenderWindow& window )
  16. {
  17.     Object::Render( window );
  18.    
  19.     if ( ( shineCounter == 0 and rand() % 750 == 0 ) or shineCounter > 0 )
  20.     {
  21.         ++shineCounter;
  22.        
  23.         float scale = shineSpr.GetScale().x;
  24.         if ( shineCounter < 25 / 2.f )
  25.         {
  26.             scale += 0.1;
  27.         }
  28.         else
  29.         {
  30.             scale -= 0.1;
  31.         }
  32.         shineSpr.SetScale( scale, scale );
  33.        
  34.         shineSpr.Rotate( 5 );
  35.     }
  36.    
  37.     if ( shineCounter > 0 and shineCounter <= 25 )
  38.     {
  39.         window.Draw( shineSpr );
  40.     }
  41.     else if ( shineCounter > 25 )
  42.     {
  43.         shineCounter = 0;
  44.         shineSpr.SetScale( 0.1, 0.1 );
  45.         shineSpr.SetRotation( 0 );
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement