From: Ivan Hernandez Date: Sun, 9 Jan 2011 20:24:02 +0000 (-0600) Subject: edited level to use pointers sized and point2d now can create eachother X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=9948b6702afd856b8a2bdd238d205c3fc95b2eb1;p=IvanGame.git edited level to use pointers sized and point2d now can create eachother --- diff --git a/Game.cpp b/Game.cpp index a9697a1..99a8e00 100644 --- a/Game.cpp +++ b/Game.cpp @@ -45,7 +45,7 @@ Game::~Game() Level* Game::getCurrentLevel() { - if (mCurrentLevel < (ssize_t)mLevels.size()) { + if (mCurrentLevel < (size_t)mLevels.size()) { return mLevels[mCurrentLevel]; } else { return NULL; diff --git a/Level.cpp b/Level.cpp index 00cf727..1d83b1a 100644 --- a/Level.cpp +++ b/Level.cpp @@ -92,10 +92,11 @@ void Level::addSprite(Sprite* sp){ } void Level::removeSprite(Sprite* sp){ - for(int i=0; i::iterator ptr = mSprites.begin(); ptr != mSprites.end(); ptr++){ + if(*ptr == sp){ + mSprites.erase(ptr); + return; + } } } diff --git a/fns.cpp b/fns.cpp index 77c1115..844b467 100644 --- a/fns.cpp +++ b/fns.cpp @@ -47,18 +47,22 @@ double Point2D::length(){ Point2D Point2D::add(Point2D pt){ X += pt.X; Y += pt.Y; + return *this; } Point2D Point2D::sub(Point2D pt){ X -= pt.X; Y -= pt.Y; + return *this; } Point2D Point2D::mult(double d){ X *= d; Y *= d; + return *this; } Point2D Point2D::div(double d){ X /= d; Y /= d; + return *this; } diff --git a/fns.h b/fns.h index d9d6423..35870c2 100644 --- a/fns.h +++ b/fns.h @@ -9,6 +9,7 @@ using namespace std; SDL_Surface* LoadImage( std::string filename );/**< Loads supported images. */ +class SizeD; /** 2D position or vector placed here because of general access*/ class Point2D { @@ -21,7 +22,8 @@ class Point2D X = copy.X; Y = copy.Y; } - Point2D (/*const SizeD& copy*/int i);///< Copy object \todo make SizeD work here + + Point2D (const SizeD& copy);///< Copy object /** \todo add typical vector functionality like length, nomal vectors etc. */ double X;/**< X position */ @@ -59,4 +61,6 @@ class SizeD //template string to_string(const T& t); + + #endif diff --git a/main.cpp b/main.cpp index 8524052..d55b70f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,97 +1,98 @@ -#include -#include -#include -#include -#include -#include -#include -#include "fns.h" -#include "Game.h" - -using namespace std; - -template string to_string(const T& t) -{ - ostringstream os; - os << t; - return os.str(); -} -//locks the screen for drawing pixels to the screen -void Slock(SDL_Surface *screen) -{ - if ( SDL_MUSTLOCK(screen) ) - { - if ( SDL_LockSurface(screen) < 0 ) - { - return; - } - } -} - -void Sulock(SDL_Surface *screen) -{ - if ( SDL_MUSTLOCK(screen) ) - { - SDL_UnlockSurface(screen); - } -} - -void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B) -{ -Uint32 color = SDL_MapRGB(screen->format, R, G, B); - switch (screen->format->BytesPerPixel) - { - case 1: // Assuming 8-bpp - { - Uint8 *bufp; - bufp = (Uint8 *)screen->pixels + y*screen->pitch + x; - *bufp = color; - } - break; - case 2: // Probably 15-bpp or 16-bpp - { - Uint16 *bufp; - bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x; - *bufp = color; - } - break; - case 3: // Slow 24-bpp mode, usually not used - { - Uint8 *bufp; - bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3; - if(SDL_BYTEORDER == SDL_LIL_ENDIAN) - { -bufp[0] = color; - bufp[1] = color >> 8; - bufp[2] = color >> 16; - } else { - bufp[2] = color; - bufp[1] = color >> 8; - bufp[0] = color >> 16; - } - } - break; - case 4: // Probably 32-bpp - { - Uint32 *bufp; - bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x; - *bufp = color; - } - break; - } -} - - -//-------------------------------------------------------------------// -// Function : main() - Params : argc, argv -// Main program function -// This function calls the init() function then loops on draw function -// until an escape condition is reached -int main (int argc, char *argv[]) -{ - Game g; - - g.run(); - - return 0; -} +#include +#include +#include +#include +#include +#include +#include +#include "fns.h" +#include "Game.h" + +using namespace std; + +template string to_string(const T& t) +{ + ostringstream os; + os << t; + return os.str(); +} +//locks the screen for drawing pixels to the screen +void Slock(SDL_Surface *screen) +{ + if ( SDL_MUSTLOCK(screen) ) + { + if ( SDL_LockSurface(screen) < 0 ) + { + return; + } + } +} + +void Sulock(SDL_Surface *screen) +{ + if ( SDL_MUSTLOCK(screen) ) + { + SDL_UnlockSurface(screen); + } +} + +void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B) +{ +Uint32 color = SDL_MapRGB(screen->format, R, G, B); + switch (screen->format->BytesPerPixel) + { + case 1: // Assuming 8-bpp + { + Uint8 *bufp; + bufp = (Uint8 *)screen->pixels + y*screen->pitch + x; + *bufp = color; + } + break; + case 2: // Probably 15-bpp or 16-bpp + { + Uint16 *bufp; + bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x; + *bufp = color; + } + break; + case 3: // Slow 24-bpp mode, usually not used + { + Uint8 *bufp; + bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3; + if(SDL_BYTEORDER == SDL_LIL_ENDIAN) + { +bufp[0] = color; + bufp[1] = color >> 8; + bufp[2] = color >> 16; + } else { + bufp[2] = color; + bufp[1] = color >> 8; + bufp[0] = color >> 16; + } + } + break; + case 4: // Probably 32-bpp + { + Uint32 *bufp; + bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x; + *bufp = color; + } + break; + } +} + + +//-------------------------------------------------------------------// +// Function : main() - Params : argc, argv +// Main program function +// This function calls the init() function then loops on draw function +// until an escape condition is reached +int main (int argc, char *argv[]) +{ + Game g; + + g.run(); + + return 0; +} +