Advertisement
Felanpro

final paste on collision

Apr 25th, 2019
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.92 KB | None | 0 0
  1.         sf::FloatRect player_boundingBox = player.getGlobalBounds();
  2.         sf::FloatRect overlap;
  3.         if (player_boundingBox.intersects(object.getGlobalBounds(), overlap))
  4.         {
  5.             cout << overlap.height << endl;
  6.             cout << overlap.width << endl;
  7.  
  8.             if (overlap.height > overlap.width)
  9.             {
  10.                 if (player.getPosition().x < object.getPosition().x)
  11.                     cout << "The player just hit the object from the left side" << endl;
  12.                 else if (player.getPosition().x > object.getPosition().x)
  13.                     cout << "The player just hit the object from the right side" << endl;
  14.  
  15.                 direction = 0;
  16.             }
  17.             else if (overlap.height < overlap.width)
  18.             {
  19.                 if (player.getPosition().y < object.getPosition().y)
  20.                     cout << "The player just hit the object from the top side" << endl;
  21.                 else if (player.getPosition().y > object.getPosition().y)
  22.                     cout << "The player just hit the object from the bottom side" << endl;
  23.                
  24.                 direction = 0;
  25.             }
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement