From 30037cd4bab1f8ea393b5f0fdfdac3e59b48e3b6 Mon Sep 17 00:00:00 2001 From: Ivan Hernandez Date: Thu, 20 Jan 2011 19:14:44 -0600 Subject: [PATCH] made drawCollisions and draw for collisions const and rearranged makelist --- CMakeLists.txt | 2 +- Collision.cpp | 2 +- Collision.h | 6 +++--- Sprite.cpp | 6 ++++-- WorldObject.cpp | 2 +- WorldObject.h | 14 +++++++------- main.cpp | 2 +- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1661778..b7cb69c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/Collision.cpp b/Collision.cpp index b38b360..72ae4bd 100644 --- a/Collision.cpp +++ b/Collision.cpp @@ -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); } diff --git a/Collision.h b/Collision.h index 9296342..5a0481b 100644 --- a/Collision.h +++ b/Collision.h @@ -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 diff --git a/Sprite.cpp b/Sprite.cpp index 1899da9..b175306 100644 --- a/Sprite.cpp +++ b/Sprite.cpp @@ -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); + } } diff --git a/WorldObject.cpp b/WorldObject.cpp index 973a5d6..4dbffa8 100644 --- a/WorldObject.cpp +++ b/WorldObject.cpp @@ -2,7 +2,7 @@ #include "fns.h" -void WorldObject::drawCollisions(vector &vec, Point2D& pos){ +void WorldObject::drawCollisions(vector &vec, const Point2D& pos){ for(int i=0; i < vec.size(); i++){ vec[i]->draw(pos); } diff --git a/WorldObject.h b/WorldObject.h index 2fd0a1f..128d572 100644 --- a/WorldObject.h +++ b/WorldObject.h @@ -10,13 +10,13 @@ public: ZOrder(z), mVisible(true) {} - virtual void draw() = 0;/**< Draws the Object. */ - void drawCollisions(vector& 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& 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 */ diff --git a/main.cpp b/main.cpp index f8d63ef..39da4d7 100644 --- 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 { -- 2.11.0