using namespace std;
using namespace sf;
No.//C++ Feature template allows us to create a generic funtion to check if two shapes are intersecting or colliding.
template <class T1, class T2>
bool isIntersecting(T1& mA, T2& mB)
{
return mA.right() >= mB.left() && mA.left() <= mB.right() &&
mA.bottom() >= mB.top() && mA.top() <= mB.bottom();
}
Using templates like this can be problematic. Aside from the fact that you'll probably end up with cryptic compiler errors at one point or another, you could just do something like this:
struct CollisionShape
{
CollisionShape(float left, float right, float top, float bottom) : left(left), right(right), top(top), bottom(bottom) { }
CollisionShape() { }
float left, right, top, bottom;
};
operator CollisionShape(const Paddle& paddle)
{
return CollisionShape(paddle.left(), paddle.right(), paddle.top(), paddle.bottom());
}
bool isIntersecting(const CollisionShape& l, const CollisionShape& r)
{
return l.right >= r.left && l.left <= r.right &&
l.bottom >= r.top && l.top <= r.bottom;
}
//Here we use an unconditiional goto statement to allow the user to restart the game.
restart:
Using a
goto to restart the game is just bad program structure.