New BonusBlock content: 'explode' - a coin explosion.
authorLMH <lmh.0013@gmail.com>
Sat, 13 Jul 2013 21:22:45 +0000 (11:22 -1000)
committerLMH <lmh.0013@gmail.com>
Sat, 13 Jul 2013 21:32:16 +0000 (11:32 -1000)
Causes ten coins to be hurled through the air as an alternative to coin rain in covered areas such as cave levels.  These coins are included in the level stats.  Testable in test/bonusblock.stl.

data/images/objects/bonus_block/bonus-explode.png [new file with mode: 0644]
data/images/tiles.strf
data/levels/test/bonusblock.stl
src/object/bonus_block.cpp
src/object/bonus_block.hpp
src/object/coin.cpp
src/object/coin_explode.cpp [new file with mode: 0644]
src/object/coin_explode.hpp [new file with mode: 0644]
src/supertux/level.cpp
src/supertux/object_factory.cpp

diff --git a/data/images/objects/bonus_block/bonus-explode.png b/data/images/objects/bonus_block/bonus-explode.png
new file mode 100644 (file)
index 0000000..cdc07f9
Binary files /dev/null and b/data/images/objects/bonus_block/bonus-explode.png differ
index 6f30151..8661a3b 100644 (file)
 ;;    src/tile.cpp, unisolid is 3 not 2
 (supertux-tiles
   (tile
+    (id 2948)
+    (images
+      "objects/bonus_block/full-0.png"
+      "objects/bonus_block/full-1.png"
+      "objects/bonus_block/full-2.png"
+      "objects/bonus_block/full-3.png"
+      "objects/bonus_block/full-4.png"
+      "objects/bonus_block/full-3.png"
+      "objects/bonus_block/full-2.png"
+      "objects/bonus_block/full-1.png"
+      "objects/bonus_block/full-0.png"
+      "objects/bonus_block/full-0.png"
+      "objects/bonus_block/full-0.png"
+    )
+    (solid #t)
+    (fullbox #t)
+    (next-tile 84)
+    (editor-images "objects/bonus_block/bonus-explode.png")
+    (data 11)
+    (fps 15)
+  )
+
+  (tile
     (id 2947)
     (images
       "objects/bonus_block/full-0.png"
@@ -36,7 +59,7 @@
     (data 10)
     (fps 15)
   )
-  
+
   (tile
     (id 2946)
     (images
@@ -59,7 +82,7 @@
     (data 9)
     (fps 15)
   )
-  
+
   (tile
     (id 2945)
     (images
     (data 8)
     (fps 15)
   )
-  
+
   (tile
     (id 2944)
     (images
     (data 7)
     (fps 15)
   )
-  
+
   (tile
     (id 2943)
     (images
     (data 6)
     (fps 15)
   )
-  
+
   (tilegroup
     (name "Pipe: Green")
     (tiles
   )
   (tilegroup
     (name "Block")
-    (tiles 27 28 29 47 48 50 49 211 77 51 52 212 78 62 61 213 44 83 2947 84 102 140 103 104 105 112 128 2943 2944 2945 2946 1311 2153)
+    (tiles 27 28 29 47 48 50 49 211 77 51 52 212 78 62 61 213 44 83 2947 2948 84 102 140 103 104 105 112 128 2943 2944 2945 2946 1311 2153)
   )
   (tilegroup
     (name "Background")
     (image "tiles/snow/slope-upper.png" )
   )
 
-;; next-id: 2948
+;; next-id: 2949
 )
index 7464250..c8510ca 100755 (executable)
@@ -30,7 +30,7 @@
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       384
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       416
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       448
-0      0       0       0       2946    0       0       0       2947    0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       480
+0      0       0       0       2946    0       0       0       2947    0       0       0       2948    0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       480
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       512
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       544
 0      0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       0       ;       576
 11     11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      ;       864
 11     11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      ;       896
 11     11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      11      ;       928
-               ))
-
-       (bonusblock
-               (x      256     )
-               (y      640     )
-               (contents       "coin"  )
-               (count  3       )
-       )
-
+               ))                                                                                                                                                                                                                                                                                                                                      
+                                                                                                                                                                                                                                                                                                                                                       
+       (bonusblock                                                                                                                                                                                                                                                                                                                                             
+               (x      256     )                                                                                                                                                                                                                                                                                                                       
+               (y      640     )                                                                                                                                                                                                                                                                                                                       
+               (contents       "coin"  )                                                                                                                                                                                                                                                                                                                       
+               (count  3       )                                                                                                                                                                                                                                                                                                                       
+       )                                                                                                                                                                                                                                                                                                                                               
+                                                                                                                                                                                                                                                                                                                                                       
        (bonusblock                                                                                                                                                                                                                                                                                                                                             
                (x      384     )                                                                                                                                                                                                                                                                                                                       
                (y      640     )                                                                                                                                                                                                                                                                                                                       
index fa94cb1..36d7558 100644 (file)
@@ -22,6 +22,7 @@
 #include "object/broken_brick.hpp"
 #include "object/flower.hpp"
 #include "object/bouncy_coin.hpp"
+#include "object/coin_explode.hpp"
 #include "object/coin_rain.hpp"
 #include "object/growup.hpp"
 #include "object/oneup.hpp"
@@ -61,6 +62,7 @@ BonusBlock::BonusBlock(const Vector& pos, int data) :
     case 8: contents = CONTENT_PORTTRAMPOLINE; break;
     case 9: contents = CONTENT_ROCK; break;
     case 10: contents = CONTENT_RAIN; break;
+    case 11: contents = CONTENT_EXPLODE; break;
     default:
       log_warning << "Invalid box contents" << std::endl;
       contents = CONTENT_COIN;
@@ -120,6 +122,8 @@ BonusBlock::BonusBlock(const Reader& lisp) :
         contents = CONTENT_ROCK;
       } else if(contentstring == "rain") {
         contents = CONTENT_RAIN;
+      } else if(contentstring == "explode") {
+        contents = CONTENT_EXPLODE;
       } else {
         log_warning << "Invalid box contents '" << contentstring << "'" << std::endl;
       }
@@ -301,6 +305,14 @@ BonusBlock::try_open(Player *player)
       hit_counter = 1; // multiple hits of coin rain is not allowed
       Sector::current()->add_object(new CoinRain(get_pos(), true));
       sound_manager->play("sounds/upgrade.wav");
+      break;
+    }
+    case CONTENT_EXPLODE:
+    {
+      hit_counter = 1; // multiple hits of coin explode is not allowed
+      Sector::current()->add_object(new CoinExplode(get_pos() + Vector (0, -40), 1));
+      sound_manager->play("sounds/upgrade.wav");
+      break;
     }
   }
 
index 127965e..4e3be52 100644 (file)
@@ -42,7 +42,8 @@ public:
     CONTENT_TRAMPOLINE,
     CONTENT_PORTTRAMPOLINE,
     CONTENT_ROCK,
-    CONTENT_RAIN
+    CONTENT_RAIN,
+    CONTENT_EXPLODE
   };
 
 protected:
index a1eea59..c87c938 100644 (file)
@@ -194,10 +194,14 @@ HeavyCoin::collision_solid(const CollisionHit& hit)
 {
   if(hit.bottom) {
     physic.set_velocity_y(0);
+    physic.set_velocity_x(0);
   }
   if(hit.right || hit.left) {
     physic.set_velocity_x(-physic.get_velocity_x());
   }
+  if(hit.top) {
+    physic.set_velocity_y(0);
+  }
 }
 
 /* EOF */
diff --git a/src/object/coin_explode.cpp b/src/object/coin_explode.cpp
new file mode 100644 (file)
index 0000000..e1853cf
--- /dev/null
@@ -0,0 +1,55 @@
+//  CoinExplode - several coins are hurled through the air
+//  Copyright (C) 2013 LMH <lmh.0013@gmail.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#include "object/coin_explode.hpp"
+
+#include "math/random_generator.hpp"
+#include "object/coin.hpp"
+#include "supertux/sector.hpp"
+
+CoinExplode::CoinExplode(const Vector& pos, const int vert) :
+  position(pos), 
+  y_velocity_weight(vert) // should generally be +/- 1 to send coins up or down respectively
+{
+}
+
+void
+CoinExplode::update(float )
+{
+  int mag = 100; // madnitude that coins are to be thrown
+  int rand = 30; // max variation to be subtracted from magnitide
+
+  //TODO: this needs its own snazzy sound
+  Sector::current()->add_object(new HeavyCoin(position, Vector (2.5,-4.5)*(mag-gameRandom.rand(rand))));
+  Sector::current()->add_object(new HeavyCoin(position, Vector (2,-5)*(mag-gameRandom.rand(rand))));
+  Sector::current()->add_object(new HeavyCoin(position, Vector (1.5,-5.5)*(mag-gameRandom.rand(rand))));
+  Sector::current()->add_object(new HeavyCoin(position, Vector (1,-6)*(mag+gameRandom.rand(rand))));
+  Sector::current()->add_object(new HeavyCoin(position, Vector (0.5,-6.5)*(mag-gameRandom.rand(rand))));
+  Sector::current()->add_object(new HeavyCoin(position, Vector (-2.5,-4.5)*(mag-gameRandom.rand(rand))));
+  Sector::current()->add_object(new HeavyCoin(position, Vector (-2,-5)*(mag-gameRandom.rand(rand))));
+  Sector::current()->add_object(new HeavyCoin(position, Vector (-1.5,-5.5)*(mag-gameRandom.rand(rand))));
+  Sector::current()->add_object(new HeavyCoin(position, Vector (-1,-6)*(mag+gameRandom.rand(rand))));
+  Sector::current()->add_object(new HeavyCoin(position, Vector (-0.5,-6.5)*(mag-gameRandom.rand(rand))));
+
+  remove_me();
+}
+
+void
+CoinExplode::draw(DrawingContext &)
+{
+}
+
+/* EOF */
diff --git a/src/object/coin_explode.hpp b/src/object/coin_explode.hpp
new file mode 100644 (file)
index 0000000..227215c
--- /dev/null
@@ -0,0 +1,39 @@
+//  CoinExplode - several coins are hurled through the air
+//  Copyright (C) 2013 LMH <lmh.0013@gmail.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_OBJECT_COIN_EXPLODE_HPP
+#define HEADER_SUPERTUX_OBJECT_COIN_EXPLODE_HPP
+
+#include <memory>
+
+#include "math/vector.hpp"
+#include "supertux/game_object.hpp"
+
+class CoinExplode : public GameObject
+{
+public:
+  CoinExplode(const Vector& pos, const int vert);
+  virtual void update(float elapsed_time);
+  virtual void draw(DrawingContext& context);
+
+private:
+  Vector position;
+  int y_velocity_weight;
+};
+
+#endif
+
+/* EOF */
index e63b4a6..fbd16c3 100644 (file)
@@ -206,6 +206,9 @@ Level::get_total_coins()
         } else if (block->contents == BonusBlock::CONTENT_RAIN) {
           total_coins += 10;
           continue;
+        } else if (block->contents == BonusBlock::CONTENT_EXPLODE) {
+          total_coins += 10;
+          continue;
         }
 #if 0
         // FIXME: do we want this? q.v. src/object/oneup.cpp
index 318389f..42fe344 100644 (file)
@@ -86,6 +86,7 @@
 #include "object/candle.hpp"
 #include "object/cloud_particle_system.hpp"
 #include "object/coin.hpp"
+#include "object/coin_explode.hpp"
 #include "object/coin_rain.hpp"
 #include "object/comet_particle_system.hpp"
 #include "object/decal.hpp"