fixed the issues with this cast (made fn const)
authorunknown <ivan@.ne.tamu.edu>
Mon, 31 Jan 2011 17:15:22 +0000 (11:15 -0600)
committerunknown <ivan@.ne.tamu.edu>
Mon, 31 Jan 2011 17:15:22 +0000 (11:15 -0600)
rect-circle collision both go to the same fn.
changed showfps key to F10 since F12 seems to be reserved on some systems.

Collision.cpp
Collision.h
Game.cpp

index 5e39baf..e2848c3 100644 (file)
@@ -192,19 +192,21 @@ bool Collision::checkCollisions(const vector<Collision*>& c, const Point2D cPos,
        return false;//if none were found then return false.
 }
 
-bool CollisionRectangle::collision(const Collision *c, const Point2D cPos, const Point2D pos){
+bool CollisionRectangle::collision(const Collision *c, const Point2D cPos, const Point2D pos) const {
        if(dynamic_cast<const CollisionRectangle*>(c)){
                //const CollisionRectangle* rec = dynamic_cast<const CollisionRectangle*>(c);
                
        }
-       else if(const CollisionCircle* col = dynamic_cast<const CollisionCircle*>(c)){
-               ///col->collision(this, cPos, pos);/// \todo this flips a shit!!!!!!
+       else if(dynamic_cast<const CollisionCircle*>(c)){
+               c->collision(this, cPos, pos);/// \todo this flips a shit!!!!!!
        }
        
        return false;
 }
-bool CollisionCircle::collision(const Collision *c, const Point2D cPos, const Point2D pos){
-       if (dynamic_cast<const CollisionRectangle*>(c)) {
+
+bool CollisionCircle::collision(const Collision *c, const Point2D cPos, const Point2D pos) const {
+       if (const CollisionRectangle* r = dynamic_cast<const CollisionRectangle*>(c)) {
+               collision(r, cPos, pos);///call the circle rect fn
        }
        else if(const CollisionCircle* col = dynamic_cast<const CollisionCircle*>(c)){
                if(((col->mPos + cPos) - (mPos + pos)).length() <= (col->radius + radius))
@@ -216,6 +218,6 @@ bool CollisionCircle::collision(const Collision *c, const Point2D cPos, const Po
        return false;
 }
 
-bool CollisionCircle::collision(const CollisionRectangle* c, const Point2D cPos, const Point2D pos){
-
+bool CollisionCircle::collision(const CollisionRectangle* c, const Point2D cPos, const Point2D pos) const {
+       return false;
 }
\ No newline at end of file
index 6235697..cb6b518 100644 (file)
@@ -34,7 +34,7 @@ public:
                \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;
+       virtual bool collision(const Collision *c, const Point2D cPos, const Point2D pos) const = 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:
@@ -59,13 +59,13 @@ public:
        double width;/**< Rectangle's width */
        double height;/**< Rectangle's height */
        /** 
-               Check collision with objects
+               Check collision with objects implements rectangle on rectangle
                \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 bool collision(const Collision *c, const Point2D cPos, const Point2D pos) const;
        virtual void draw(const Point2D& pos);/**< Draws the collision data to the screen */
 };
 
@@ -84,22 +84,23 @@ public:
        CollisionCircle();
        CollisionCircle(Point2D pt, double r) : radius(r){ mPos = pt; }
        double radius; /**< The raidus of the circle */
-       /** 
-               Check collision with objects
+       /**
+               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  .
        */
-       virtual bool collision(const Collision *c, const Point2D cPos, const Point2D pos);
-       /**
-               This does collision between Rectangles and Circles
+       bool collision(const CollisionRectangle* c, const Point2D cPos, const Point2D pos) const;
+       /** 
+               Check collision with objects implements circle on circle
                \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* c, const Point2D cPos, const Point2D pos);
+       virtual bool collision(const Collision *c, const Point2D cPos, const Point2D pos) const;
+       
        virtual void draw(const Point2D& pos);/**< Draws the collision data to the screen */
 };
 #endif
index 3d38db4..87a84e5 100644 (file)
--- a/Game.cpp
+++ b/Game.cpp
@@ -117,7 +117,7 @@ void Game::run()
                                if (keys[SDLK_F11]) {
                                        ShowCollisions = !ShowCollisions;
                                }
-                               if (keys[SDLK_F12]) {
+                               if (keys[SDLK_F10]) {
                                        ShowFPS = !ShowFPS;
                                }
                        }