New flying platform object.
[supertux.git] / src / world.cpp
index 97edbeb..91acb66 100644 (file)
@@ -165,6 +165,9 @@ World::add_object(GameObject* object)
   Trampoline* trampoline = dynamic_cast<Trampoline*> (object);
   if(trampoline)
     trampolines.push_back(trampoline);
+  FlyingPlatform* flying_platform = dynamic_cast<FlyingPlatform*> (object);
+  if(flying_platform)
+    flying_platforms.push_back(flying_platform);
 
   gameobjects.push_back(object);
 }
@@ -180,7 +183,11 @@ World::parse_objects(lisp_object_t* cur)
 
     if(object_type == "trampoline") {
       add_object(new Trampoline(displaymanager, reader));
-    } else {
+    }
+    else if(object_type == "flying-platform") {
+      add_object(new FlyingPlatform(displaymanager, reader));
+    }
+    else {
       BadGuyKind kind = badguykind_from_string(object_type);
       add_object(new BadGuy(displaymanager, kind, reader));
     }
@@ -259,6 +266,12 @@ World::action(float elapsed_time)
             std::remove(trampolines.begin(), trampolines.end(), trampoline),
             trampolines.end());
       }
+      FlyingPlatform* flying_platform= dynamic_cast<FlyingPlatform*> (*i);
+      if(flying_platform) {
+        flying_platforms.erase(
+            std::remove(flying_platforms.begin(), flying_platforms.end(), flying_platform),
+            flying_platforms.end());
+      }
       
       delete *i;
       i = gameobjects.erase(i);
@@ -485,6 +498,24 @@ World::collision_handler()
       }
     }
   }
+
+  // CO_FLYING_PLATFORM & (CO_PLAYER or CO_BADGUY)
+  for (FlyingPlatforms::iterator i = flying_platforms.begin(); i != flying_platforms.end(); ++i)
+  {
+    if (rectcollision((*i)->base, tux->base))
+    {
+      if (tux->previous_base.y < tux->base.y &&
+          tux->previous_base.y + tux->previous_base.height 
+          < (*i)->base.y + (*i)->base.height/2)
+      {
+        (*i)->collision(tux, CO_PLAYER, COLLISION_SQUISH);
+        tux->collision(*i, CO_FLYING_PLATFORM);
+      }
+/*      else if (tux->previous_base.y <= tux->base.y)
+      {
+      }*/
+    }
+  }
 }
 
 void
@@ -538,18 +569,18 @@ World::add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind)
   add_object(new Upgrade(displaymanager, pos, dir, kind));
 }
 
-void 
+bool
 World::add_bullet(const Vector& pos, float xm, Direction dir)
 {
   if(tux->got_power == Player::FIRE_POWER)
     {
     if(bullets.size() > MAX_FIRE_BULLETS-1)
-      return;
+      return false;
     }
   else if(tux->got_power == Player::ICE_POWER)
     {
     if(bullets.size() > MAX_ICE_BULLETS-1)
-      return;
+      return false;
     }
 
   Bullet* new_bullet = 0;
@@ -562,6 +593,8 @@ World::add_bullet(const Vector& pos, float xm, Direction dir)
   add_object(new_bullet);
   
   play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
+
+  return true;
 }
 
 void