edited level to use pointers sized and point2d now can create eachother
authorIvan Hernandez <iturtleman128@gmail.com>
Sun, 9 Jan 2011 20:24:02 +0000 (14:24 -0600)
committerIvan Hernandez <iturtleman128@gmail.com>
Sun, 9 Jan 2011 20:24:02 +0000 (14:24 -0600)
Game.cpp
Level.cpp
fns.cpp
fns.h
main.cpp

index a9697a1..99a8e00 100644 (file)
--- 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;
index 00cf727..1d83b1a 100644 (file)
--- 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<mSprites.size();++i){
-               if(mSprites[i] == sp)///< \todo test
-                       return;///< \todo find the vector.remove
-               cout<<mSprites[i]<<endl;
+       for(vector<Sprite*>::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 (file)
--- 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 (file)
--- 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<class T> string to_string(const T& t);
+
+
 #endif
index 8524052..d55b70f 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -1,97 +1,98 @@
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string>\r
-#include <SDL/SDL.h>\r
-#include <iostream>\r
-#include <sstream>\r
-#include <vector>\r
-#include "fns.h"\r
-#include "Game.h"\r
-\r
-using namespace std;\r
-\r
-template<class T> string to_string(const T& t)\r
-{\r
-    ostringstream os;\r
-    os << t;\r
-    return os.str();\r
-}\r
-//locks the screen for drawing pixels to the screen\r
-void Slock(SDL_Surface *screen)\r
-{   \r
-    if ( SDL_MUSTLOCK(screen) )\r
-    {   \r
-        if ( SDL_LockSurface(screen) < 0 )\r
-        {\r
-            return;\r
-        }\r
-    }\r
-}\r
-\r
-void Sulock(SDL_Surface *screen)\r
-{   \r
-    if ( SDL_MUSTLOCK(screen) )\r
-    {\r
-        SDL_UnlockSurface(screen);\r
-    }\r
-}\r
-\r
-void DrawPixel(SDL_Surface *screen, int x, int y, Uint8 R, Uint8 G, Uint8 B)\r
-{\r
-Uint32 color = SDL_MapRGB(screen->format, R, G, B);\r
-    switch (screen->format->BytesPerPixel)\r
-    {\r
-    case 1: // Assuming 8-bpp\r
-        {\r
-            Uint8 *bufp;\r
-            bufp = (Uint8 *)screen->pixels + y*screen->pitch + x;\r
-            *bufp = color;\r
-        }\r
-        break;\r
-    case 2: // Probably 15-bpp or 16-bpp\r
-        {\r
-            Uint16 *bufp;\r
-            bufp = (Uint16 *)screen->pixels + y*screen->pitch/2 + x;\r
-            *bufp = color;\r
-        }\r
-        break;\r
-    case 3: // Slow 24-bpp mode, usually not used\r
-        {\r
-            Uint8 *bufp;\r
-            bufp = (Uint8 *)screen->pixels + y*screen->pitch + x * 3;\r
-            if(SDL_BYTEORDER == SDL_LIL_ENDIAN)\r
-            {\r
-bufp[0] = color;\r
-                bufp[1] = color >> 8;\r
-                bufp[2] = color >> 16;\r
-            } else {\r
-                bufp[2] = color;\r
-                bufp[1] = color >> 8;\r
-                bufp[0] = color >> 16;\r
-            }\r
-        }\r
-        break;\r
-    case 4: // Probably 32-bpp\r
-        {\r
-            Uint32 *bufp;\r
-            bufp = (Uint32 *)screen->pixels + y*screen->pitch/4 + x;\r
-            *bufp = color;\r
-        }\r
-        break;\r
-    }\r
-}\r
-\r
-\r
-//-------------------------------------------------------------------//\r
-// Function : main()    - Params : argc, argv\r
-// Main program function\r
-// This function calls the init() function then loops on draw function \r
-// until an escape condition is reached\r
-int main (int argc, char *argv[])\r
-{\r
-       Game g;\r
-\r
-       g.run();\r
-\r
-    return 0;\r
-}\r
+#include <stdio.h>
+#include <stdlib.h>
+#include <string>
+#include <SDL/SDL.h>
+#include <iostream>
+#include <sstream>
+#include <vector>
+#include "fns.h"
+#include "Game.h"
+
+using namespace std;
+
+template<class T> 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;
+}
+