Finish making powerups drop out of bonus blocks when hit with butt-jump
authorLMH <lmh.0013@gmail.com>
Wed, 21 Aug 2013 19:59:13 +0000 (09:59 -1000)
committerTobias Markus <tobbi@mozilla-uk.org>
Sat, 26 Oct 2013 16:45:18 +0000 (18:45 +0200)
Allows bonus_blocks to drop contents when opened with a butt-jump.  This makes obtaining powerups while big less-trivial.  Note that bonus_blocks on the ground will still send their contents up (with the exception of the Tux doll).
There is some room for improvement here: a sort of "drop riser" would make it look nicer, and currently dolls are unobtainable on butt-jump which might be a little to harsh.

src/object/bonus_block.cpp
src/object/oneup.cpp
src/object/powerup.cpp
src/object/powerup.hpp

index 47cc964..3f58dc5 100644 (file)
@@ -28,6 +28,7 @@
 #include "object/oneup.hpp"
 #include "object/player.hpp"
 #include "object/portable.hpp"
+#include "object/powerup.hpp"
 #include "object/specialriser.hpp"
 #include "object/star.hpp"
 #include "object/trampoline.hpp"
@@ -200,7 +201,7 @@ BonusBlock::try_open(Player *player)
 
   if (player == NULL)
     player = sector->player;
-  
+
   if (player == NULL)
     return;
 
@@ -341,16 +342,25 @@ BonusBlock::try_drop(Player *player)
   Sector* sector = Sector::current();
   assert(sector);
 
+  // First what's below the bonus block, if solid send it up anyway (excepting doll)
+  Rectf dest;
+  dest.p1.x = bbox.get_left() + 1;
+  dest.p1.y = bbox.get_bottom() + 1;
+  dest.p2.x = bbox.get_right() - 1;
+  dest.p2.y = dest.p1.y + 30;
+  if (!Sector::current()->is_free_of_statics(dest, this, true) && !(contents == CONTENT_1UP)) {
+    try_open(player);
+    return;
+  }
+
   if (player == NULL)
     player = sector->player;
-  
+
   if (player == NULL)
     return;
 
   Direction direction = (player->get_bbox().get_middle().x > get_bbox().get_middle().x) ? LEFT : RIGHT;
 
-  //TODO: when solid below send up
-
   switch(contents) {
     case CONTENT_COIN:
     {
@@ -360,30 +370,14 @@ BonusBlock::try_drop(Player *player)
 
     case CONTENT_FIREGROW:
     {
-      //TODO: drop flowers
-      if(player->get_status()->bonus == NO_BONUS) {
-        SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp(direction));
-        sector->add_object(riser);
-      } else {
-        SpecialRiser* riser = new SpecialRiser(
-          get_pos(), new Flower(FIRE_BONUS));
-        sector->add_object(riser);
-      }
+      sector->add_object(new PowerUp(get_pos() + Vector(0, 32), "images/powerups/fireflower/fireflower.sprite"));
       sound_manager->play("sounds/upgrade.wav");
       break;
     }
 
     case CONTENT_ICEGROW:
     {
-      //TODO: drop flowers
-      if(player->get_status()->bonus == NO_BONUS) {
-        SpecialRiser* riser = new SpecialRiser(get_pos(), new GrowUp(direction));
-        sector->add_object(riser);
-      } else {
-        SpecialRiser* riser = new SpecialRiser(
-          get_pos(), new Flower(ICE_BONUS));
-        sector->add_object(riser);
-      }
+      sector->add_object(new PowerUp(get_pos() + Vector(0, 32), "images/powerups/iceflower/iceflower.sprite"));
       sound_manager->play("sounds/upgrade.wav");
       break;
     }
@@ -396,17 +390,16 @@ BonusBlock::try_drop(Player *player)
 
     case CONTENT_1UP:
     {
-      //TODO: drop doll straight down
-      sector->add_object(new OneUp(get_pos(), direction));
+      sector->add_object(new OneUp(get_pos(), DOWN));
       break;
     }
 
     case CONTENT_CUSTOM:
     {
-      //TODO: drop custom contents
-      SpecialRiser* riser = new SpecialRiser(get_pos(), object);
+      //TODO: confirm this works
+      object->set_pos(get_pos() +  Vector(0, 32));
+      sector->add_object(object);
       object = 0;
-      sector->add_object(riser);
       sound_manager->play("sounds/upgrade.wav");
       break;
     }
index cea25b0..281aca7 100644 (file)
@@ -23,6 +23,8 @@ OneUp::OneUp(const Vector& pos, Direction direction) :
   physic()
 {
   physic.set_velocity((direction == LEFT)?-100:100, -400);
+  if(direction == DOWN) // this causes the doll to drop when opened with a butt-jump
+    physic.set_velocity(0, -100);
 }
 
 void
index 927001b..67deb2e 100644 (file)
@@ -55,6 +55,31 @@ PowerUp::PowerUp(const Reader& lisp) :
 
 }
 
+PowerUp::PowerUp(const Vector& pos, const std::string& sprite_name) :
+  MovingSprite(pos, sprite_name, LAYER_OBJECTS, COLGROUP_MOVING),
+  physic(),
+  script(),
+  no_physics(false),
+  light(0.0f,0.0f,0.0f),
+  lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite"))
+{
+  physic.enable_gravity(true);
+  sound_manager->preload("sounds/grow.ogg");
+  sound_manager->preload("sounds/fire-flower.wav");
+  //set default light for glow effect for standard sprites
+  lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
+  lightsprite->set_color(Color(0.0f, 0.0f, 0.0f));
+  if (sprite_name == "images/powerups/egg/egg.sprite") {
+    lightsprite->set_color(Color(0.2f, 0.2f, 0.0f));
+  } else if (sprite_name == "images/powerups/fireflower/fireflower.sprite") {
+    lightsprite->set_color(Color(0.3f, 0.0f, 0.0f));
+  } else if (sprite_name == "images/powerups/iceflower/iceflower.sprite") {
+    lightsprite->set_color(Color(0.0f, 0.1f, 0.2f));
+  } else if (sprite_name == "images/powerups/star/star.sprite") {
+    lightsprite->set_color(Color(0.4f, 0.4f, 0.4f));
+  }
+}
+
 void
 PowerUp::collision_solid(const CollisionHit& hit)
 {
index a1d814b..6c20d68 100644 (file)
@@ -23,6 +23,7 @@ class PowerUp : public MovingSprite
 {
 public:
   PowerUp(const Reader& lisp);
+  PowerUp(const Vector& pos, const std::string& sprite_name);
 
   virtual void update(float elapsed_time);
   virtual void draw(DrawingContext& context);