1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#ifndef COLLISIONMANAGER_HPP
#define COLLISIONMANAGER_HPP
#include "boundingboxincludes.hpp"
#include <iostream>
namespace CollisionManager
{
template <typename T, typename U>
bool IsCollision(const T& boundingBox, const U& otherBoundingBox);
template <template<class> class T, class U, class V>
bool IsCollision(const T<V>& boundingBox, const U& otherBoundingBox);
template <class T, template<class> class U, class V>
bool IsCollision(const T& boundingBox, const U<V>& otherBoundingBox);
template <template<class> class T, template<class> class U, class V, class W>
bool IsCollision(const T<V>& boundingBox, const U<W>& otherBoundingBox);
}
namespace CollisionManager
{
template <typename T, typename U>
inline bool IsCollision(const T& boundingBox, const U& otherBoundingBox)
{
std::cout<<"Warning (1) : collision "<<typeid(T).name()<<" "<<typeid(U).name()<<" not defined"<<std::endl;
return false;
}
template <template<class> class T, class U, class V>
inline bool IsCollision(const T<V>& boundingBox, const U& otherBoundingBox)
{
std::cout<<"Warning (2) : collision "<<typeid(T<V>).name()<<" "<<typeid(U).name()<<" not defined"<<std::endl;
return false;
}
template <class T, template<class> class U, class V>
inline bool IsCollision(const T& boundingBox, const U<V>& otherBoundingBox)
{
std::cout<<"Warning (3) : collision "<<typeid(T).name()<<" "<<typeid(U<V>).name()<<" not defined"<<std::endl;
return false;
}
template <template<class> class T, template<class> class U, class V, class W>
inline bool IsCollision(const T<V>& boundingBox, const U<W>& otherBoundingBox)
{
std::cout<<"Warning (4) : collision "<<typeid(T<V>).name()<<" "<<typeid(U<W>).name()<<" not defined"<<std::endl;
return false;
}
template <typename U, typename V>
inline bool IsCollision(const sf::Rect<U> &boundingBox, const sf::Rect<V>& otherBoundingBox)
{
if(boundingBox.Left>otherBoundingBox.Right||boundingBox.Right<otherBoundingBox.Left||boundingBox.Top>otherBoundingBox.Bottom||boundingBox.Bottom<otherBoundingBox.Top)
return false;
return true;
}
template <>
inline bool IsCollision(const SimpleSpriteRectBox& boundingBox, const SimpleSpriteRectBox& otherBoundingBox)
{
if(boundingBox.getSprite()==NULL||boundingBox.getSprite()==NULL)
return false;
return IsCollision(boundingBox.getSprite()->GetSubRect(),otherBoundingBox.getSprite()->GetSubRect());
}
template <class V, class W>
inline bool IsCollision(const SimpleRectBox<V>& boundingBox, const SimpleRectBox<W>& otherBoundingBox)
{
return IsCollision(boundingBox.getRect(),otherBoundingBox.getRect());
}
}
#endif |