-renamed ViewPort to Camera
[supertux.git] / src / badguy.cpp
index 1f626a6..0e4b7de 100644 (file)
@@ -35,6 +35,7 @@
 #include "gameloop.h"
 #include "display_manager.h"
 #include "lispwriter.h"
+#include "camera.h"
 
 Sprite* img_mriceblock_flat_left;
 Sprite* img_mriceblock_flat_right;
@@ -315,6 +316,8 @@ BadGuy::action_mriceblock(double elapsed_time)
       check_horizontal_bump();
       if(mode == KICK && changed != dir)
         {
+          float scroll_x = World::current()->camera->get_translation().x;
+          
           /* handle stereo sound (number 10 should be tweaked...)*/
           if (base.x < scroll_x + screen->w/2 - 10)
             play_sound(sounds[SND_RICOCHET], SOUND_LEFT_SPEAKER);
@@ -514,6 +517,8 @@ BadGuy::action_bomb(double elapsed_time)
       dying = DYING_NOT; // now the bomb hurts
       timer.start(EXPLODETIME);
 
+      float scroll_x = World::current()->camera->get_translation().x;                 
+
       /* play explosion sound */  // FIXME: is the stereo all right? maybe we should use player cordinates...
       if (base.x < scroll_x + screen->w/2 - 10)
         play_sound(sounds[SND_EXPLODE], SOUND_LEFT_SPEAKER);
@@ -746,13 +751,9 @@ BadGuy::action_snowball(double elapsed_time)
 void
 BadGuy::action(float elapsed_time)
 {
-  // Remove if it's far off the screen:
-  if (base.x < scroll_x - OFFSCREEN_DISTANCE)
-    {
-      remove_me();                                                
-      return;
-    }
-
+  float scroll_x = World::current()->camera->get_translation().x;
+  float scroll_y = World::current()->camera->get_translation().y;
+  
   // BadGuy fall below the ground
   if (base.y > World::current()->get_level()->height * 32) {
     remove_me();
@@ -771,7 +772,10 @@ BadGuy::action(float elapsed_time)
       }
 
   // Once it's on screen, it's activated!
-  if (base.x <= scroll_x + screen->w + OFFSCREEN_DISTANCE)
+  if (base.x > scroll_x - X_OFFSCREEN_DISTANCE &&
+       base.x < scroll_x + screen->w + X_OFFSCREEN_DISTANCE &&
+       base.y > scroll_y - Y_OFFSCREEN_DISTANCE &&
+       base.y < scroll_y + screen->h + Y_OFFSCREEN_DISTANCE)
     seen = true;
 
   if(!seen)
@@ -828,7 +832,7 @@ BadGuy::action(float elapsed_time)
 }
 
 void
-BadGuy::draw(ViewPort& viewport, int)
+BadGuy::draw(Camera& viewport, int)
 {
   float scroll_x = viewport.get_translation().x;
   float scroll_y = viewport.get_translation().y;