Trying to add Collision drawing. and fixing the This so that it will work correctly.
authorunknown <Ivan Lloyd@.(none)>
Tue, 18 Jan 2011 06:24:47 +0000 (00:24 -0600)
committerunknown <Ivan Lloyd@.(none)>
Tue, 18 Jan 2011 06:24:47 +0000 (00:24 -0600)
Collision.cpp
Collision.h
Game.h
WorldObject.cpp [new file with mode: 0644]
WorldObject.h
fns.h
main.cpp

index 40afa4a..f0860cd 100644 (file)
@@ -1,4 +1,13 @@
 #include "Collision.h"
+#include <SDL/SDL_draw.h>
+
+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<const CollisionRectangle*>(c)){
index 8a28592..0b7d34f 100644 (file)
@@ -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 (file)
--- 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 (file)
index 0000000..da2c48e
--- /dev/null
@@ -0,0 +1,9 @@
+#include "WorldObject.h"
+#include "fns.h"
+
+
+void WorldObject::drawCollisions(vector<Collision*> *vec){
+       for(int i=0; i < vec->size(); i++){
+               (*vec)[i]->draw();
+       }
+}
index 8dc0dbb..3477005 100644 (file)
@@ -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<Collision*> *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 (file)
--- a/fns.h
+++ b/fns.h
@@ -2,10 +2,12 @@
 #define FNS
 #include <SDL/SDL.h>
 #include <string>
-
 /// \todo remove this this is just to make testing easy w/o gdb
 #include <iostream>
 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. */
 
index 23bec13..93b8214 100644 (file)
--- 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