Sulock(Game::game()->Screen());
}
-bool Collision::checkCollisions(const vector<Collision*>& c){
+bool Collision::checkCollisions(const vector<Collision*>& c, const Point2D cPos, const Point2D pos){
for(int i=0; i < c.size(); i++){
- if(collision(c[i]))//if any are true return true then and there
+ if(collision(c[i], cPos, pos))//if any are true return true then and there
return true;
}
return false;//if none were found then return false.
}
-bool CollisionRectangle::collision(const Collision *c){
+bool CollisionRectangle::collision(const Collision *c, const Point2D cPos, const Point2D pos){
if(dynamic_cast<const CollisionRectangle*>(c)){
- const CollisionRectangle* rec = dynamic_cast<const CollisionRectangle*>(c);
+ //const CollisionRectangle* rec = dynamic_cast<const CollisionRectangle*>(c);
}
- else if(dynamic_cast<const CollisionCircle*>(c)){
+ else if(const CollisionCircle* col = dynamic_cast<const CollisionCircle*>(c)){
+ ///col->collision(this, cPos, pos); \todo this flips a shit!!!!!!
}
return false;
}
-bool CollisionCircle::collision(const Collision *c){
+bool CollisionCircle::collision(const Collision *c, const Point2D cPos, const Point2D pos){
if (dynamic_cast<const CollisionRectangle*>(c)) {
}
else if(const CollisionCircle* col = dynamic_cast<const CollisionCircle*>(c)){
- if((col->mPos - mPos).length() < col->radius + radius)
+ if(((col->mPos + cPos) - (mPos + pos)).length() < (col->radius + radius))
return true;
else
return false;
{
public:
Collision():mPos(0.0,0.0),color(0xFF00FF00){ }
- Point2D mPos;/**< The position of the center of the collision data \todo need the parent object's position*/
- bool checkCollisions(const vector<Collision*>& c); /**< Check collision with objects */
- virtual bool collision(const Collision *c) = 0; /**< Check collision with objects */
+ Point2D mPos;/**< The position of the center of the collision data */
+ /**
+ Check collision with objects
+ \param c the collision data associated with the sprite to check collision with.
+ \param cPos the position of the sprite we want to check collision with.
+ \param pos the current sprite's position.
+ \return Returns true if any of the object's collision datas are colliding .
+ */
+ bool checkCollisions(const vector<Collision*>& c, const Point2D cPos, const Point2D pos);
+ /**
+ Check collision with objects
+ \param c a single collision data for an object
+ \param cPos the position of the sprite we want to check collision with.
+ \param pos the current sprite's position.
+ \return Returns true if any of the object's collision datas are colliding .
+ */
+ virtual bool collision(const Collision *c, const Point2D cPos, const Point2D pos) = 0;
/// \todo See this http://www.metanetsoftware.com/technique/tutorialA.html
virtual void draw(const Point2D& pos) = 0;/**< Draws the collision data to the screen */
protected:
CollisionRectangle(Point2D pt, double w, double h):width(w),height(h){ mPos = pt;}
double width;/**< Rectangle's width */
double height;/**< Rectangle's height */
- virtual bool collision(const Collision *c);/**< Check collision with objects */
+ /**
+ Check collision with objects
+ \param c a single collision data for an object
+ \param cPos the position of the sprite we want to check collision with.
+ \param pos the current sprite's position.
+ \return Returns true if any of the object's collision datas are colliding .
+ */
+ virtual bool collision(const Collision *c, const Point2D cPos, const Point2D pos);
virtual void draw(const Point2D& pos);/**< Draws the collision data to the screen */
};
CollisionCircle();
CollisionCircle(Point2D pt, double r) : radius(r){ mPos = pt; }
double radius; /**< The raidus of the circle */
- virtual bool collision(const Collision *c);/**< Check collision with objects */
- bool collision(const CollisionRectangle*);/**< This does collision between Rectangles and Circles */
+ /**
+ Check collision with objects
+ \param c a single collision data for an object
+ \param cPos the position of the sprite we want to check collision with.
+ \param pos the current sprite's position.
+ \return Returns true if any of the object's collision datas are colliding .
+ */
+ virtual bool collision(const Collision *c, const Point2D cPos, const Point2D pos);
+ /**
+ This does collision between Rectangles and Circles
+ \param c a single collision data for an object
+ \param cPos the position of the sprite we want to check collision with.
+ \param pos the current sprite's position.
+ \return Returns true if any of the object's collision datas are colliding .
+ */
+ bool collision(const CollisionRectangle*, const Point2D cPos, const Point2D pos);/**< This does collision between Rectangles and Circles */
virtual void draw(const Point2D& pos);/**< Draws the collision data to the screen */
};
#endif