Fixed crash.
[supertux.git] / src / gameobjs.cpp
index aaf6319..010cf1d 100644 (file)
@@ -18,7 +18,7 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //  02111-1307, USA.
-
+#include <algorithm>
 #include "world.h"
 #include "tile.h"
 #include "gameloop.h"
@@ -54,7 +54,7 @@ void
 BouncyDistro::draw()
 {
   img_distro[0]->draw(base.x - scroll_x,
-                      base.y);
+                      base.y - scroll_y);
 }
 
 
@@ -79,7 +79,12 @@ BrokenBrick::action(double frame_ratio)
 
   if (!timer.check())
     {
-      World::current()->broken_bricks.erase(static_cast<std::vector<BrokenBrick>::iterator>(this));
+      std::vector<BrokenBrick*>::iterator i
+        = std::find(World::current()->broken_bricks.begin(), 
+                    World::current()->broken_bricks.end(), 
+                    this);
+      if (i != World::current()->broken_bricks.end())
+        World::current()->broken_bricks.erase(i);
     }
 }
 
@@ -93,7 +98,7 @@ BrokenBrick::draw()
   src.h = 16;
 
   dest.x = (int)(base.x - scroll_x);
-  dest.y = (int)base.y;
+  dest.y = (int)(base.y  - scroll_y);
   dest.w = 16;
   dest.h = 16;
   
@@ -123,7 +128,14 @@ BouncyBrick::action(double frame_ratio)
 
   /* Stop bouncing? */
   if (offset >= 0)
-    World::current()->bouncy_bricks.erase(static_cast<std::vector<BouncyBrick>::iterator>(this));
+    {
+      std::vector<BouncyBrick*>::iterator i
+        = std::find(World::current()->bouncy_bricks.begin(), 
+                    World::current()->bouncy_bricks.end(), 
+                    this);
+      if (i != World::current()->bouncy_bricks.end())
+        World::current()->bouncy_bricks.erase(i);
+    }
 }
 
 void
@@ -135,7 +147,7 @@ BouncyBrick::draw()
       base.x <= scroll_x + screen->w)
     {
       dest.x = (int)(base.x - scroll_x);
-      dest.y = (int)base.y;
+      dest.y = (int)(base.y - scroll_y);
       dest.w = 32;
       dest.h = 32;
 
@@ -145,7 +157,7 @@ BouncyBrick::draw()
       // paint it later at on offseted position
       if(plevel->bkgd_image[0] == '\0')
         {
-          fillrect(base.x - scroll_x, base.y,
+          fillrect(base.x - scroll_x, base.y - scroll_y,
                    32,32, 
                    plevel->bkgd_top.red, plevel->bkgd_top.green, plevel->bkgd_top.blue, 0);
 // FIXME: doesn't respect the gradient, futhermore is this necessary at all??
@@ -158,7 +170,7 @@ BouncyBrick::draw()
         }
 
       Tile::draw(base.x - scroll_x,
-                 base.y + offset,
+                 base.y - scroll_y + offset,
                  shape);
     }
 }
@@ -179,7 +191,14 @@ FloatingScore::action(double frame_ratio)
   base.y = base.y - 2 * frame_ratio;
 
   if(!timer.check())
-    World::current()->floating_scores.erase(static_cast<std::vector<FloatingScore>::iterator>(this));
+    {
+      std::vector<FloatingScore*>::iterator i
+        = std::find(World::current()->floating_scores.begin(), 
+                    World::current()->floating_scores.end(), 
+                    this);
+      if (i != World::current()->floating_scores.end())
+        World::current()->floating_scores.erase(i);
+    }
 }
 
 void