- moved some more stuff into the world class
[supertux.git] / src / badguy.cpp
index 37d1968..f1c5df6 100644 (file)
@@ -16,6 +16,7 @@
 #include "badguy.h"
 #include "scene.h"
 #include "screen.h"
+#include "world.h"
 #include "tile.h"
 
 texture_type img_bsod_squished_left[1];
@@ -28,8 +29,8 @@ texture_type img_laptop_falling_left[1];
 texture_type img_laptop_falling_right[1];
 texture_type img_bsod_left[4];
 texture_type img_bsod_right[4];
-texture_type img_laptop_left[3];
-texture_type img_laptop_right[3];
+texture_type img_laptop_left[4];
+texture_type img_laptop_right[4];
 texture_type img_money_left[2];
 texture_type img_money_right[2];
 texture_type img_mrbomb_left[4];
@@ -48,8 +49,8 @@ texture_type img_flyingsnowball[2];
 texture_type img_flyingsnowball_squished[1];
 texture_type img_spiky_left[3];
 texture_type img_spiky_right[3];
-texture_type img_snowball_left[3];
-texture_type img_snowball_right[3];
+texture_type img_snowball_left[4];
+texture_type img_snowball_right[4];
 texture_type img_snowball_squished_left[1];
 texture_type img_snowball_squished_right[1];
 
@@ -57,7 +58,7 @@ BadGuyKind  badguykind_from_string(const std::string& str)
 {
   if (str == "money")
     return BAD_MONEY;
-  else if (str == "laptop")
+  else if (str == "laptop" || str == "mriceblock")
     return BAD_LAPTOP;
   else if (str == "bsod")
     return BAD_BSOD;
@@ -157,7 +158,7 @@ BadGuy::init(float x, float y, BadGuyKind kind_)
     set_texture(img_mrbomb_left, img_mrbomb_right, 4);
   } else if (kind == BAD_LAPTOP) {
     physic.set_velocity(-1.3, 0);
-    set_texture(img_laptop_left, img_laptop_right, 3);
+    set_texture(img_laptop_left, img_laptop_right, 4, 5);
   } else if(kind == BAD_MONEY) {
     set_texture(img_money_left, img_money_right, 1);
   } else if(kind == BAD_BOMB) {
@@ -178,14 +179,14 @@ BadGuy::init(float x, float y, BadGuyKind kind_)
     set_texture(img_fish, img_fish, 2, 1);
     physic.enable_gravity(true);
   } else if(kind == BAD_FLYINGSNOWBALL) {
-    set_texture(img_flyingsnowball, img_flyingsnowball, 2);
+    set_texture(img_flyingsnowball, img_flyingsnowball, 2, 5);
     physic.enable_gravity(false);
   } else if(kind == BAD_SPIKY) {
     physic.set_velocity(-1.3, 0);
     set_texture(img_spiky_left, img_spiky_right, 3);
   } else if(kind == BAD_SNOWBALL) {
     physic.set_velocity(-1.3, 0);
-    set_texture(img_snowball_left, img_snowball_right, 3);
+    set_texture(img_snowball_left, img_snowball_right, 4, 5);
   }
 
   // if we're in a solid tile at start correct that now
@@ -296,7 +297,7 @@ BadGuy::action_laptop()
       if(!timer_check(&timer))
         {
           mode = NORMAL;
-          set_texture(img_laptop_left, img_laptop_right, 3);
+          set_texture(img_laptop_left, img_laptop_right, 4, 5);
           physic.set_velocity( (dir == LEFT) ? -1.3 : 1.3, 0);
         }
     }
@@ -372,13 +373,14 @@ BadGuy::fall()
 void
 BadGuy::remove_me()
 {
-  std::vector<BadGuy>::iterator i;
-  for(i = bad_guys.begin(); i != bad_guys.end(); ++i) {
-    if( & (*i) == this) {
-      bad_guys.erase(i);
-      return;
+  for(std::vector<BadGuy>::iterator i = World::current()->bad_guys.begin(); 
+      i != World::current()->bad_guys.end(); ++i) 
+    {
+      if( & (*i) == this) {
+        World::current()->bad_guys.erase(i);
+        return;
+      }
     }
-  }
 }
 
 void
@@ -783,7 +785,7 @@ BadGuy::squish_me(Player* player)
 {
   make_player_jump(player);
     
-  add_score(base.x - scroll_x, base.y, 50 * score_multiplier);
+  World::current()->add_score(base.x - scroll_x, base.y, 50 * score_multiplier);
   play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
   score_multiplier++;
 
@@ -796,58 +798,58 @@ void
 BadGuy::squish(Player* player)
 {
   if(kind == BAD_MRBOMB) {
-      // mrbomb transforms into a bomb now
-      add_bad_guy(base.x, base.y, BAD_BOMB);
-      
-      make_player_jump(player);
-      add_score(base.x - scroll_x, base.y, 50 * score_multiplier);
-      play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
-      score_multiplier++;
+    // mrbomb transforms into a bomb now
+    World::current()->add_bad_guy(base.x, base.y, BAD_BOMB);
+    
+    make_player_jump(player);
+    World::current()->add_score(base.x - scroll_x, base.y, 50 * score_multiplier);
+    play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER);
+    score_multiplier++;
       
-      remove_me();
-      return;
+    remove_me();
+    return;
 
   } else if(kind == BAD_BSOD) {
-      squish_me(player);
-      set_texture(img_bsod_squished_left, img_bsod_squished_right, 1);
-      physic.set_velocity(0, physic.get_velocity_y());
-      return;
+    squish_me(player);
+    set_texture(img_bsod_squished_left, img_bsod_squished_right, 1);
+    physic.set_velocity(0, physic.get_velocity_y());
+    return;
       
   } else if (kind == BAD_LAPTOP) {
-      if (mode == NORMAL || mode == KICK)
+    if (mode == NORMAL || mode == KICK)
       {
-          /* Flatten! */
-          play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
-          mode = FLAT;
-          set_texture(img_laptop_flat_left, img_laptop_flat_right, 1);
-          physic.set_velocity(0, physic.get_velocity_y());
+        /* Flatten! */
+        play_sound(sounds[SND_STOMP], SOUND_CENTER_SPEAKER);
+        mode = FLAT;
+        set_texture(img_laptop_flat_left, img_laptop_flat_right, 1);
+        physic.set_velocity(0, physic.get_velocity_y());
 
-          timer_start(&timer, 4000);
+        timer_start(&timer, 4000);
       } else if (mode == FLAT) {
-          /* Kick! */
-          play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
-
-          if (player->base.x < base.x + (base.width/2)) {
-              physic.set_velocity(5, physic.get_velocity_y());
-              dir = RIGHT;
-          } else {
-              physic.set_velocity(-5, physic.get_velocity_y());
-              dir = LEFT;
-          }
-
-          mode = KICK;
-          set_texture(img_laptop_flat_left, img_laptop_flat_right, 1);
+        /* Kick! */
+        play_sound(sounds[SND_KICK], SOUND_CENTER_SPEAKER);
+
+        if (player->base.x < base.x + (base.width/2)) {
+          physic.set_velocity(5, physic.get_velocity_y());
+          dir = RIGHT;
+        } else {
+          physic.set_velocity(-5, physic.get_velocity_y());
+          dir = LEFT;
+        }
+
+        mode = KICK;
+        set_texture(img_laptop_flat_left, img_laptop_flat_right, 1);
       }
 
-      make_player_jump(player);
+    make_player_jump(player);
              
-      add_score(base.x - scroll_x, base.y, 25 * score_multiplier);
-      score_multiplier++;
-      return;
+    World::current()->add_score(base.x - scroll_x, base.y, 25 * score_multiplier);
+    score_multiplier++;
+    return;
   } else if(kind == BAD_FISH) {
     make_player_jump(player);
              
-    add_score(base.x - scroll_x, base.y, 25 * score_multiplier);
+    World::current()->add_score(base.x - scroll_x, base.y, 25 * score_multiplier);
     score_multiplier++;
      
     // simply remove the fish...
@@ -885,11 +887,11 @@ BadGuy::kill_me()
 
   /* Gain some points: */
   if (kind == BAD_BSOD)
-    add_score(base.x - scroll_x, base.y,
-              50 * score_multiplier);
+    World::current()->add_score(base.x - scroll_x, base.y,
+                    50 * score_multiplier);
   else 
-    add_score(base.x - scroll_x, base.y,                                 
-              25 * score_multiplier);
+    World::current()->add_score(base.x - scroll_x, base.y,                                 
+                    25 * score_multiplier);
 
   /* Play death sound: */
   play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
@@ -986,32 +988,18 @@ void load_badguy_gfx()
 
   /* (Laptop) */
 
-  texture_load(&img_laptop_left[0], datadir +
-               "/images/shared/laptop-left-0.png",
-               USE_ALPHA);
-
-  texture_load(&img_laptop_left[1], datadir +
-               "/images/shared/laptop-left-1.png",
-               USE_ALPHA);
-
-  texture_load(&img_laptop_left[2], datadir +
-               "/images/shared/laptop-left-2.png",
-               USE_ALPHA);
-
-  texture_load(&img_laptop_right[0], datadir +
-               "/images/shared/laptop-right-0.png",
-               USE_ALPHA);
-
-  texture_load(&img_laptop_right[1], datadir +
-               "/images/shared/laptop-right-1.png",
-               USE_ALPHA);
-
-  texture_load(&img_laptop_right[2], datadir +
-               "/images/shared/laptop-right-2.png",
-               USE_ALPHA);
+  texture_load(&img_laptop_left[0], datadir + "/images/shared/mriceblock-left-0.png", USE_ALPHA);
+  texture_load(&img_laptop_left[1], datadir + "/images/shared/mriceblock-left-1.png", USE_ALPHA);
+  texture_load(&img_laptop_left[2], datadir + "/images/shared/mriceblock-left-2.png", USE_ALPHA);
+  texture_load(&img_laptop_left[3], datadir + "/images/shared/mriceblock-left-1.png", USE_ALPHA);
 
-  texture_load(&img_laptop_flat_left[0], datadir +
-               "/images/shared/laptop-flat-left.png",
+  texture_load(&img_laptop_right[0], datadir + "/images/shared/mriceblock-right-0.png", USE_ALPHA);
+  texture_load(&img_laptop_right[1], datadir + "/images/shared/mriceblock-right-1.png", USE_ALPHA);
+  texture_load(&img_laptop_right[2], datadir + "/images/shared/mriceblock-right-2.png", USE_ALPHA);
+  texture_load(&img_laptop_right[3], datadir + "/images/shared/mriceblock-right-1.png", USE_ALPHA);
+  
+  texture_load(&img_laptop_flat_left[0], 
+               datadir + "/images/shared/laptop-flat-left.png",
                USE_ALPHA);
 
   texture_load(&img_laptop_flat_right[0], datadir +
@@ -1114,16 +1102,16 @@ void load_badguy_gfx()
   }
 
   /** snowball */
-  for(int i = 0; i < 3; ++i) {
-        char num[4];
-        snprintf(num, 4, "%d", i);
-        texture_load(&img_snowball_left[i],
-                datadir + "/images/shared/snowball-left-" + num + ".png",
-                USE_ALPHA);
-        texture_load(&img_snowball_right[i],
-                datadir + "/images/shared/snowball-right-" + num + ".png",
-                USE_ALPHA);
-  }
+  texture_load(&img_snowball_left[0], datadir + "/images/shared/snowball-left-0.png", USE_ALPHA);
+  texture_load(&img_snowball_left[1], datadir + "/images/shared/snowball-left-1.png", USE_ALPHA);
+  texture_load(&img_snowball_left[2], datadir + "/images/shared/snowball-left-2.png", USE_ALPHA);
+  texture_load(&img_snowball_left[3], datadir + "/images/shared/snowball-left-1.png", USE_ALPHA);
+
+  texture_load(&img_snowball_right[0], datadir + "/images/shared/snowball-right-0.png", USE_ALPHA);
+  texture_load(&img_snowball_right[1], datadir + "/images/shared/snowball-right-1.png", USE_ALPHA);
+  texture_load(&img_snowball_right[2], datadir + "/images/shared/snowball-right-2.png", USE_ALPHA);
+  texture_load(&img_snowball_right[3], datadir + "/images/shared/snowball-right-1.png", USE_ALPHA);
+
   texture_load(&img_snowball_squished_left[0],
           datadir + "/images/shared/bsod-squished-left.png", USE_ALPHA);
   texture_load(&img_snowball_squished_right[0],
@@ -1144,7 +1132,7 @@ void free_badguy_gfx()
   texture_free(&img_bsod_falling_left[0]);
   texture_free(&img_bsod_falling_right[0]);
 
-  for (int i = 0; i < 3; i++)
+  for (int i = 0; i < 4; i++)
     {
       texture_free(&img_laptop_left[i]);
       texture_free(&img_laptop_right[i]);
@@ -1194,7 +1182,7 @@ void free_badguy_gfx()
     texture_free(&img_spiky_left[i]);
     texture_free(&img_spiky_right[i]);
   }
-  for(int i = 0; i<3; ++i) {
+  for(int i = 0; i<4; ++i) {
     texture_free(&img_snowball_left[i]);
     texture_free(&img_snowball_right[i]);
   }