made drawCollisions and draw for collisions const and rearranged
authorIvan Hernandez <iturtleman128@gmail.com>
Fri, 21 Jan 2011 01:14:44 +0000 (19:14 -0600)
committerIvan Hernandez <iturtleman128@gmail.com>
Fri, 21 Jan 2011 01:14:44 +0000 (19:14 -0600)
makelist

CMakeLists.txt
Collision.cpp
Collision.h
Sprite.cpp
WorldObject.cpp
WorldObject.h
main.cpp

index 1661778..b7cb69c 100644 (file)
@@ -4,6 +4,6 @@ project(game)
 find_package(SDL REQUIRED)
 find_package(SDL_image REQUIRED)
 
-add_executable(game Animation.cpp fns.cpp Game.cpp Level.cpp main.cpp Sprite.cpp Text.cpp Actor.cpp Background.cpp LevelWorld.cpp WorldObject.cpp Collision.cpp)
+add_executable(game Animation.cpp fns.cpp Game.cpp Level.cpp main.cpp WorldObject.cpp Sprite.cpp Text.cpp Actor.cpp Background.cpp LevelWorld.cpp Collision.cpp)
 
 target_link_libraries(game ${SDL_LIBRARY} ${SDLIMAGE_LIBRARY})
index b38b360..72ae4bd 100644 (file)
@@ -6,7 +6,7 @@ void CollisionRectangle::draw(Point2D& pos){
        Draw_Rect(Game::game()->Screen(), pos.x + mPos.x, pos.y + mPos.y, width, height, color);
 }
 
-void CollisionCircle::draw(Point2D& pos){
+void CollisionCircle::draw(const Point2D& pos){
        Draw_Circle(Game::game()->Screen(), pos.x + mPos.x, pos.y + mPos.y, radius, color);
 }
 
index 9296342..5a0481b 100644 (file)
@@ -21,7 +21,7 @@ public:
        Point2D mPos;/**< 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(Point2D& pos) = 0;/**< Draws the collision data to the screen */
+       virtual void draw(const Point2D& pos) = 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
@@ -44,7 +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(Point2D& pos);/**< Draws the collision data to the screen */
+       virtual void draw(const Point2D& pos);/**< Draws the collision data to the screen */
 };
 
 /**
@@ -64,6 +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(Point2D& pos);/**< Draws the collision data to the screen */
+       virtual void draw(const Point2D& pos);/**< Draws the collision data to the screen */
 };
 #endif
index 1899da9..b175306 100644 (file)
@@ -43,6 +43,8 @@ void Sprite::draw()
        dest.y = mPos.y;
        if(mVisible == true)
                SDL_BlitSurface(frame.image,NULL,mScreen,&dest);
-       if(Game::game()->ShowCollisions)
-               drawCollisions(frame.collisionData, mPos + frame.animationPeg);
+       if(Game::game()->ShowCollisions){
+               Point2D pt =mPos + frame.animationPeg;
+               drawCollisions(frame.collisionData, pt);
+       }
 }
index 973a5d6..4dbffa8 100644 (file)
@@ -2,7 +2,7 @@
 #include "fns.h"
 
 
-void WorldObject::drawCollisions(vector<Collision*> &vec, Point2D& pos){
+void WorldObject::drawCollisions(vector<Collision*> &vec, const Point2D& pos){
        for(int i=0; i < vec.size(); i++){
                vec[i]->draw(pos);
        }
index 2fd0a1f..128d572 100644 (file)
@@ -10,13 +10,13 @@ public:
          ZOrder(z),
                  mVisible(true)
          {}
-         virtual void draw() = 0;/**< Draws the Object. */
-         void drawCollisions(vector<Collision*>& vec, Point2D& pos);/**< 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. */
+       virtual void draw() = 0;/**< Draws the Object. */
+       void drawCollisions(vector<Collision*>& vec, const Point2D& pos);/**< 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:
        Point2D mPos;/**< The current (x,y) position */
index f8d63ef..39da4d7 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -61,7 +61,7 @@ Uint32 color = SDL_MapRGB(screen->format, R, G, B);
             bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3;
             if(SDL_BYTEORDER == SDL_LIL_ENDIAN)
             {
-bufp[0] = color;
+                               bufp[0] = color;
                 bufp[1] = color >> 8;
                 bufp[2] = color >> 16;
             } else {