From: unknown Date: Tue, 18 Jan 2011 06:24:47 +0000 (-0600) Subject: Trying to add Collision drawing. and fixing the This so that it will work correctly. X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=ddd1fb2a6a1a0b23f12f175aa5271bb286f0788c;p=IvanGame.git Trying to add Collision drawing. and fixing the This so that it will work correctly. --- diff --git a/Collision.cpp b/Collision.cpp index 40afa4a..f0860cd 100644 --- a/Collision.cpp +++ b/Collision.cpp @@ -1,4 +1,13 @@ #include "Collision.h" +#include + +void CollisionRectangle::draw(){ + Draw_Rect(This->Screen(), pos.x, pos.y, width, height, color); +} + +void CollisionCircle::draw(){ + Draw_Circle(This->Screen(), pos.x, pos.y, radius, color); +} bool CollisionRectangle::collision(const Collision *c){ if(dynamic_cast(c)){ diff --git a/Collision.h b/Collision.h index 8a28592..0b7d34f 100644 --- a/Collision.h +++ b/Collision.h @@ -17,12 +17,14 @@ using std::string; class Collision { public: - Collision():pos(0.0,0.0){} + Collision():pos(0.0,0.0),color(0xFF00FF00){ } Point2D pos;/**< The position of the center of the collision data */ virtual bool collision(const Collision *c) = 0; /**< Check collision with objects */ /// \todo See this http://www.metanetsoftware.com/technique/tutorialA.html + virtual void draw() = 0;/**< Draws the collision data to the screen */ protected: string name;///< Name of this behavior \todo make this actually be useful + Uint32 color;///< The collision box color }; /** @@ -42,6 +44,7 @@ public: double width;/**< Rectangle's width */ double height;/**< Rectangle's height */ virtual bool collision(const Collision *c);/**< Check collision with objects */ + virtual void draw();/**< Draws the collision data to the screen */ }; /** @@ -61,5 +64,6 @@ public: 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 */ + virtual void draw();/**< Draws the collision data to the screen */ }; #endif diff --git a/Game.h b/Game.h index 4553850..8dee6db 100644 --- a/Game.h +++ b/Game.h @@ -33,6 +33,9 @@ public: /** Makes the game loop begin and load objects. */ void run(); + + /** Returns the main screen to allow for drawing */ + SDL_Surface* Screen(){ return mScreen; } private: static const Uint32 waitTime; diff --git a/WorldObject.cpp b/WorldObject.cpp new file mode 100644 index 0000000..da2c48e --- /dev/null +++ b/WorldObject.cpp @@ -0,0 +1,9 @@ +#include "WorldObject.h" +#include "fns.h" + + +void WorldObject::drawCollisions(vector *vec){ + for(int i=0; i < vec->size(); i++){ + (*vec)[i]->draw(); + } +} diff --git a/WorldObject.h b/WorldObject.h index 8dc0dbb..3477005 100644 --- a/WorldObject.h +++ b/WorldObject.h @@ -1,20 +1,24 @@ #ifndef WORLDOBJECT #define WORLDOBJECT +#include "fns.h" +#include "Collision.h" + class WorldObject { - public: - WorldObject(int z = 0) : - ZOrder(z), - mVisible(true) - {} - virtual void draw() = 0;/**< draws object. */ - void xadd(int num) {mPos.x += num;}/**< Increase x coordiante by a given amount. */ - void yadd(int num) {mPos.y += num;}/**< Increase y coordinate by a given amount. */ - void xset(int x) {mPos.x = x;}/**< Sets the Sprite's x Coordinate. */ - void yset(int y) {mPos.y = y;}/**< Sets the Sprite's y coordinate. */ - void setPosition(int x, int y) {mPos.x = x; mPos.y = y;}/**< Sets the Sprite's x an y coordinate. */ +public: + WorldObject(int z = 0) : + ZOrder(z), + mVisible(true) + {} + virtual void draw() = 0;/**< Draws the Object. */ + void drawCollisions(vector *vec);/**< Draws Collision data for the Object */ + void xadd(int num) {mPos.x += num;}/**< Increase x coordiante by a given amount. */ + void yadd(int num) {mPos.y += num;}/**< Increase y coordinate by a given amount. */ + void xset(int x) {mPos.x = x;}/**< Sets the Sprite's x Coordinate. */ + void yset(int y) {mPos.y = y;}/**< Sets the Sprite's y coordinate. */ + void setPosition(int x, int y) {mPos.x = x; mPos.y = y;}/**< Sets the Sprite's x an y coordinate. */ - protected: +protected: Point2D mPos;/**< The current (x,y) position */ bool mVisible;/**< Determine if Object should be visible */ int ZOrder;/**< Stacking order. Determines what draws on top. \todo implement. */ diff --git a/fns.h b/fns.h index 8885d4b..2ddbab1 100644 --- a/fns.h +++ b/fns.h @@ -2,10 +2,12 @@ #define FNS #include #include - /// \todo remove this this is just to make testing easy w/o gdb #include using namespace std; +class Game; +///This is a pointer so that all objects in-game can obtain data that is needed everywhere. \todo make so that we have This.game or This->game +Game* This; SDL_Surface* LoadImage( std::string filename );/**< Loads supported images. */ diff --git a/main.cpp b/main.cpp index 23bec13..93b8214 100644 --- a/main.cpp +++ b/main.cpp @@ -81,9 +81,6 @@ bufp[0] = color; } } -///This is a pointer so that all objects in-game can obtain data that is needed everywhere. \todo make so that we have This.game or This->game -Game* This; - //-------------------------------------------------------------------// // Function : main() - Params : argc, argv // Main program function