Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //random() and isColliding() courtesy of ulfben, used with permission.
- // https://pastebin.com/TLEZK0M8
- // RNG in C++11: https://isocpp.org/files/papers/n3551.pdf
- //returns random number between min-max (inclusive)
- int random(int min, int max) {
- static std::random_device rd; //obtain a random seed from hardware
- static std::mt19937 eng(rd()); //seed the generator
- std::uniform_int_distribution<> distr(min, max); //define the range
- /*std::uniform_real_distribution<>*/ //use if you want floats!
- return distr(eng);
- }
- //AABB intersection test
- bool isColliding(const SDL_Rect& lhs, const SDL_Rect& rhs) {
- SDL_assert(&lhs != &rhs);
- return !(lhs.x + lhs.w < rhs.x //!(lhs.right < rhs.left
- || rhs.x + rhs.w < lhs.x //|| rhs.right < lhs.left
- || lhs.y + lhs.h < rhs.y //|| lhs.bottom < rhs.top
- || rhs.y + rhs.h < lhs.y); //|| rhs.bottom < lhs.top)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement