- added object support (untested)
[supertux.git] / src / gameloop.cpp
index 099643a..ba8ec36 100644 (file)
@@ -100,33 +100,16 @@ void start_timers(void)
 
 void activate_bad_guys(void)
 {
-  // Activate badguys the new style
   for (std::vector<BadGuyData>::iterator i = current_level.badguy_data.begin();
        i != current_level.badguy_data.end();
        ++i)
     {
       add_bad_guy(i->x, i->y, i->kind);
     }
-
-  // FIXME: should be removed;
-  // Activate bad guys the old style
-  for (int y = 0; y < 15; y++)
-    {
-      for (int x = 0; x < current_level.width; x++)
-        {
-          if (current_level.ia_tiles[y][x] >= 1000 && current_level.ia_tiles[y][x] <= 1010)
-            {
-              add_bad_guy(x * 32, y * 32,  
-                          static_cast<BadGuyKind>(current_level.ia_tiles[y][x] - 1000));
-              current_level.ia_tiles[y][x] = 0;
-            }
-        }
-    }
 }
 
 void activate_particle_systems(void)
 {
-  printf("PSys: %s\n", current_level.particle_system.c_str());
   if(current_level.particle_system == "clouds")
     {
       particle_systems.push_back(new CloudParticleSystem);
@@ -147,6 +130,9 @@ void game_event(void)
 {
   while (SDL_PollEvent(&event))
     {
+          /* Check for menu-events, if the menu is shown */
+          if(show_menu)
+            menu_event(event);
       switch(event.type)
         {
         case SDL_QUIT:        /* Quit event - quit: */
@@ -155,10 +141,6 @@ void game_event(void)
         case SDL_KEYDOWN:     /* A keypress! */
           key = event.key.keysym.sym;
 
-          /* Check for menu-events, if the menu is shown */
-          if(show_menu)
-            menu_event(&event.key.keysym);
-
           if(tux.key_event(key,DOWN))
             break;
 
@@ -283,16 +265,8 @@ void game_event(void)
                 tux.input.down = UP;
               else
                 tux.input.down = UP;
-
-              /* Handle joystick for the menu */
-              if(show_menu)
-                {
-                  if(tux.input.down == DOWN)
-                    menuaction = MENU_ACTION_DOWN;
-                  else
-                    menuaction = MENU_ACTION_UP;
-                }
-              break;
+              
+             break;
             default:
               break;
             }
@@ -308,9 +282,7 @@ void game_event(void)
             tux.input.up = UP;
           else if (event.jbutton.button == JOY_B)
             tux.input.fire = UP;
-
-          if(show_menu)
-            menuaction = MENU_ACTION_HIT;
+           
           break;
 
         default:
@@ -494,7 +466,7 @@ int game_action(void)
 
 void game_draw(void)
 {
-int y,x;
+  int y,x;
 
   /* Draw screen: */
   if (tux.dying && (global_frame_counter % 4) == 0)
@@ -535,7 +507,6 @@ int y,x;
     }
 
   /* Draw interactive tiles: */
-
   for (y = 0; y < 15; ++y)
     {
       for (x = 0; x < 21; ++x)
@@ -546,7 +517,6 @@ int y,x;
     }
 
   /* (Bouncy bricks): */
-
   for (unsigned int i = 0; i < bouncy_bricks.size(); ++i)
     bouncy_brick_draw(&bouncy_bricks[i]);
 
@@ -565,13 +535,12 @@ int y,x;
     upgrade_draw(&upgrades[i]);
 
   for (unsigned int i = 0; i < bouncy_distros.size(); ++i)
-      bouncy_distro_draw(&bouncy_distros[i]);
+    bouncy_distro_draw(&bouncy_distros[i]);
 
   for (unsigned int i = 0; i < broken_bricks.size(); ++i)
     broken_brick_draw(&broken_bricks[i]);
 
   /* Draw foreground: */
-
   for (y = 0; y < 15; ++y)
     {
       for (x = 0; x < 21; ++x)
@@ -1161,7 +1130,21 @@ void loadshared(void)
                "/images/shared/bag-right-1.png",
                USE_ALPHA);
 
+  /* Mr. Bomb */
+  for(int i=0; i<4; ++i) {
+      char num[4];
+      snprintf(num, 4, "%d", i);
+      texture_load(&img_mrbomb_left[i],
+              datadir + "/images/shared/mrbomb-left-" + num + ".png", USE_ALPHA);
+      texture_load(&img_mrbomb_right[i],
+              datadir + "/images/shared/mrbomb-right-" + num + ".png", USE_ALPHA);
+  }
 
+  /* stalactite */
+  texture_load(&img_stalactite, 
+          datadir + "/images/shared/stalactite.png", USE_ALPHA);
+  texture_load(&img_stalactite_broken,
+          datadir + "/images/shared/stalactite-broken.png", USE_ALPHA);
 
   /* Upgrades: */
 
@@ -1288,6 +1271,14 @@ void unloadshared(void)
       texture_free(&img_money_right[i]);
     }
 
+  for(i = 0; i < 4; i++) {
+      texture_free(&img_mrbomb_left[i]);
+      texture_free(&img_mrbomb_right[i]);
+  }
+
+  texture_free(&img_stalactite);
+  texture_free(&img_stalactite_broken);
+
   texture_free(&img_box_full);
   texture_free(&img_box_empty);
 
@@ -1421,7 +1412,7 @@ unsigned int shape(float x, float y)
       c = current_level.ia_tiles[yy][xx];
     }
   else
-    c = '.';
+    c = 0;
 
   return(c);
 }
@@ -1431,9 +1422,6 @@ Tile* gettile(float x, float y)
   return TileManager::instance()->get(shape(x, y));
 }
 
-/* Is is ground? */
-
-
 bool issolid(float x, float y)
 {
   Tile* tile = TileManager::instance()->get
@@ -1575,7 +1563,6 @@ void bumpbrick(float x, float y)
 
 
 /* Empty a box: */
-
 void tryemptybox(float x, float y, int col_side)
 {
   Tile* tile = gettile(x,y);
@@ -1583,13 +1570,11 @@ void tryemptybox(float x, float y, int col_side)
     return;
 
   // according to the collision side, set the upgrade direction
-
   if(col_side == LEFT)
     col_side = RIGHT;
   else
     col_side = LEFT;
 
-  // FIXME: Content of boxes must be handled otherwise
   switch(tile->data)
     {
     case 1: //'A':      /* Box with a distro! */
@@ -1598,6 +1583,7 @@ void tryemptybox(float x, float y, int col_side)
       score = score + SCORE_DISTRO;
       distros++;
       break;
+
     case 2: // 'B':      /* Add an upgrade! */
       if (tux.size == SMALL)     /* Tux is small, add mints! */
         add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_MINTS);
@@ -1605,6 +1591,7 @@ void tryemptybox(float x, float y, int col_side)
         add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_COFFEE);
       play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER);
       break;
+
     case 3:// '!':     /* Add a golden herring */
       add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_HERRING);
       break;
@@ -1616,9 +1603,7 @@ void tryemptybox(float x, float y, int col_side)
   level_change(&current_level,x, y, TM_IA, tile->next_tile);
 }
 
-
 /* Try to grab a distro: */
-
 void trygrabdistro(float x, float y, int bounciness)
 {
   Tile* tile = gettile(x, y);
@@ -1639,30 +1624,21 @@ void trygrabdistro(float x, float y, int bounciness)
 }
 
 /* Try to bump a bad guy from below: */
-
 void trybumpbadguy(float x, float y)
 {
-  unsigned int i;
-
   /* Bad guys: */
-  for (i = 0; i < bad_guys.size(); i++)
+  for (unsigned int i = 0; i < bad_guys.size(); i++)
     {
       if (bad_guys[i].base.x >= x - 32 && bad_guys[i].base.x <= x + 32 &&
           bad_guys[i].base.y >= y - 16 && bad_guys[i].base.y <= y + 16)
         {
-          if (bad_guys[i].kind == BAD_BSOD ||
-              bad_guys[i].kind == BAD_LAPTOP)
-            {
-              bad_guys[i].dying = DYING_FALLING;
-              bad_guys[i].base.ym = -8;
-              play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
-            }
+          bad_guys[i].collision(&tux, CO_PLAYER, COLLISION_BUMP);
         }
     }
 
 
   /* Upgrades: */
-  for (i = 0; i < upgrades.size(); i++)
+  for (unsigned int i = 0; i < upgrades.size(); i++)
     {
       if (upgrades[i].base.height == 32 &&
           upgrades[i].base.x >= x - 32 && upgrades[i].base.x <= x + 32 &&
@@ -1771,7 +1747,6 @@ void savegame(int slot)
   if (fi == NULL)
     {
       fprintf(stderr, "Warning: I could not open the slot file ");
-
     }
   else
     {