From ed74c47acdede750c2eb68b0cfb1f655da5d698e Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 16 Jan 2011 18:38:56 -0600 Subject: [PATCH] Collision doesn't freak out. Continue implementing. --- Animation.cpp | 4 ++-- Background.h | 2 +- Collision.cpp | 20 ++++++++++++++------ Collision.h | 16 ++++++---------- Frame.h | 2 +- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/Animation.cpp b/Animation.cpp index 6f78126..515ad08 100644 --- a/Animation.cpp +++ b/Animation.cpp @@ -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; } diff --git a/Background.h b/Background.h index f2361d3..671984e 100644 --- a/Background.h +++ b/Background.h @@ -27,7 +27,7 @@ class Background{ SizeD mScreenSize;/// collisionData;/// collisionData;///(c)){ + } + else if(dynamic_cast(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(c)) { + } + else if(dynamic_cast(c)){ + } + + return false; } diff --git a/Collision.h b/Collision.h index 1a652b9..8a28592 100644 --- a/Collision.h +++ b/Collision.h @@ -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 --- a/Frame.h +++ b/Frame.h @@ -13,7 +13,7 @@ struct SpriteFrame{ int height;/**< Base height of the frame's image. */ vector 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 bounds;/**< The collision data for this sprite */ + vector bounds;/**< The collision data for this sprite */ }; #endif \ No newline at end of file -- 2.11.0