Collision doesn't freak out. Continue implementing.
authorunknown <Ivan Lloyd@.(none)>
Mon, 17 Jan 2011 00:38:56 +0000 (18:38 -0600)
committerunknown <Ivan Lloyd@.(none)>
Mon, 17 Jan 2011 00:38:56 +0000 (18:38 -0600)
Animation.cpp
Background.h
Collision.cpp
Collision.h
Frame.h

index 6f78126..515ad08 100644 (file)
@@ -83,7 +83,7 @@ int Animation::loadAnimation(std::string animFile)
                                                value>>yOffset;
                                                double radius;
                                                value>>radius;
-                                               mAnim[count].bounds.push_back(CollisionCircle(Point2D(xOffset, yOffset), radius));
+                                               mAnim[count].bounds.push_back(new CollisionCircle(Point2D(xOffset, yOffset), radius));
                                        }
                                        else if(c == 'r')
                                        {
@@ -93,7 +93,7 @@ int Animation::loadAnimation(std::string animFile)
                                                double width = 0.0 , height = 0.0;
                                                value>>width;
                                                value>>height;
-                                               mAnim[count].bounds.push_back(CollisionRectangle(Point2D(xOffset, yOffset), width, height));
+                                               mAnim[count].bounds.push_back(new CollisionRectangle(Point2D(xOffset, yOffset), width, height));
                                        }
                                        value>>c;
                                }
index f2361d3..671984e 100644 (file)
@@ -27,7 +27,7 @@ class Background{
        SizeD mScreenSize;///<This is the size of the screen to be drawn to. used to get the sections of the background when moving and for screen-at-a-time scrolling.
        SDL_Rect source;///< This is the rectangle that gets taken from the actual background image (h,w) determine the size of the rectangle to sample from the background image. (x,y) determine the position of the rectangle's top left corner on the actual background image.
        bool wrapping;
-       vector<Collision> collisionData;///<The collision data for this Background \todo implement collisions
+       vector<Collision*> collisionData;///<The collision data for this Background \todo implement collisions
 
        
        public:
index 380e45c..40afa4a 100644 (file)
@@ -1,11 +1,19 @@
 #include "Collision.h"
 
-bool CollisionRectangle::collision(CollisionRectangle &c){
+bool CollisionRectangle::collision(const Collision *c){
+       if(dynamic_cast<const CollisionRectangle*>(c)){
+       }
+       else if(dynamic_cast<const CollisionCircle*>(c)){
+       }
+       
+       return false;
 }
-bool CollisionRectangle::collision(CollisionCircle &c){
-}
-bool CollisionCircle::collision(CollisionRectangle &c){
-}
-bool CollisionCircle::collision(CollisionCircle &c){
+bool CollisionCircle::collision(const Collision *c){
+       if (dynamic_cast<const CollisionRectangle*>(c)) {
+       }
+       else if(dynamic_cast<const CollisionCircle*>(c)){
+       }
+
+       return false;
 }
 
index 1a652b9..8a28592 100644 (file)
@@ -19,8 +19,7 @@ class Collision
 public:
        Collision():pos(0.0,0.0){}
        Point2D pos;/**< The position of the center of the collision data */
-       virtual bool collision(CollisionRectangle &c);/**< Check collision with Rectangle */
-       virtual bool collision(CollisionCircle &c);/**< Check collision with Circle */
+       virtual bool collision(const Collision *c) = 0; /**< Check collision with objects */
        /// \todo See this http://www.metanetsoftware.com/technique/tutorialA.html
 protected:
        string name;///< Name of this behavior \todo make this actually be useful
@@ -42,9 +41,7 @@ public:
        CollisionRectangle(Point2D pt, double w, double h):width(w),height(h){ pos = pt;}
        double width;/**< Rectangle's width */
        double height;/**< Rectangle's height */
-
-       bool collision(CollisionRectangle &c);/**< Check collision with Rectangle */
-       bool collision(CollisionCircle &c);/**< Check collision with Circle */
+       virtual bool collision(const Collision *c);/**< Check collision with objects */
 };
 
 /**
@@ -60,10 +57,9 @@ class CollisionCircle : public Collision
 {
 public:
        CollisionCircle();
-       CollisionCircle(Point2D pt, double r):radius(r){ pos = pt; }
-       double radius;/**< The raidus of the circle */
-
-       bool collision(CollisionRectangle &c);/**< Check collision with Rectangle */
-       bool collision(CollisionCircle &c);/**< Check collision with Circle */
+       CollisionCircle(Point2D pt, double r) : radius(r){ pos = 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 */
 };
 #endif
diff --git a/Frame.h b/Frame.h
index b6c9c95..be2e080 100644 (file)
--- a/Frame.h
+++ b/Frame.h
@@ -13,7 +13,7 @@ struct SpriteFrame{
        int height;/**< Base height of the frame's image. */
        vector<Point2D> hotSpots;/**< Hot spots that can be used for locating objects on the sprite default is tagged to center of the sprite \todo implement default*/
        Point2D animationPeg;/**< The offeset from position to place the image. Defaults to (0,0) \todo implement */
-       vector<Collision> bounds;/**< The collision data for this sprite */
+       vector<Collision*> bounds;/**< The collision data for this sprite */
 };
 
 #endif
\ No newline at end of file