]> git.mmlx.us Git - IvanGame.git/commitdiff
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 6f7812665634a81ad2ec48c48b0e52365bd915dc..515ad08b0fbbad9804372c8c97f3f04bb49b8751 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 f2361d369ba9bb35c066869044f6d017224949dd..671984ecec0b4a835685f1b1b0a04cc443ac7107 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 380e45ce850f9e9562c04b0fbee325ae4765b78d..40afa4ad68903496c94d0b78249ffe12b9f8e349 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 1a652b9f3f1a03eb1dbf6ae1b357516675614b3b..8a28592dfdf199c06cdb4200fe6b910f11b96c9b 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 b6c9c951af0200abe7387353646f7a850a513d4b..be2e0802338030d2a81fe65c63046818abf3c06e 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