How do I create the bounding boxes and set the condition such that a sprite when given user input moves in 2D space but within the the boundaries of another sprite? Here's my code so far:
sf::FloatRect bound1 = sprite1.getGlobalBounds();
sf::FloatRect bound2 = sprite2.getGlobalBounds();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down))
sprite2.move(0.f, speed * time);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
sprite2.move(0.f, -speed * time);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
sprite2.move(speed * time, 0.f);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
sprite2.move(-speed * time, 0.f);
Please help!