Advertisement
Guest User

Random Location

a guest
Jul 11th, 2011
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.38 KB | None | 0 0
  1. sf::Vector2f randomLocation(sf::Rect<float> rect)
  2. {
  3.         int randx = -1;
  4.     int randy = -1;
  5.     int left = (int)rect.Left;
  6.     int right = (int)rect.Width;
  7.     int top = (int)rect.Top;
  8.     int bottom = (int)rect.Height;
  9.    
  10.     while(rand > right || rand < left)
  11.     {
  12.         randx = rand();
  13.     }
  14.     while(rand > bottom || rand < top)
  15.     {
  16.         randy = rand();
  17.     }
  18.  
  19.     return sf::Vector2f(randx, randy);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement