Shrunk cherry bomb a little, fixed bounding boxes. /
authorChristoph Sommer <mail@christoph-sommer.de>
Wed, 5 Jul 2006 13:52:13 +0000 (13:52 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Wed, 5 Jul 2006 13:52:13 +0000 (13:52 +0000)
Bomb explosion is now bigger than the bomb

SVN-Revision: 3893

19 files changed:
data/images/creatures/mr_cherry/cherry.sprite
data/images/creatures/mr_cherry/cherrybomb1.png
data/images/creatures/mr_cherry/cherrybomb2.png
data/images/creatures/mr_cherry/cherrybomb3.png
data/images/creatures/mr_cherry/cherrybomb4.png
data/images/creatures/mr_cherry/cherrybomb5.png
data/images/creatures/mr_cherry/cherrybomb6.png
data/images/creatures/mr_cherry/cherrybomb_hit_1.png
data/images/creatures/mr_cherry/cherrybomb_hit_2.png
data/images/creatures/mr_cherry/cherrybomb_hit_3.png
data/images/creatures/mr_cherry/cherrybomb_hit_4.png
data/images/creatures/mr_cherry/cherrybomb_hit_5.png
data/images/creatures/mr_cherry/cherrybomb_hit_6.png
data/images/creatures/mr_cherry/mr_cherry.sprite
src/badguy/bomb.cpp
src/badguy/bomb.hpp
src/math/rect.hpp
src/object/moving_sprite.cpp
src/object/moving_sprite.hpp

index 950e0f9..d6590ac 100644 (file)
@@ -3,7 +3,7 @@
  (action
   (name "ticking-left")
   (fps 4.0)
-  (hitbox 7 23 38 43)
+  (hitbox 3 21 30 34)
   (images cherrybomb_hit_1.png
 cherrybomb_hit_2.png
 cherrybomb_hit_3.png
@@ -14,13 +14,13 @@ cherrybomb_hit_5.png
  (action
   (name "ticking-right")
   (fps 4.0)
-  (hitbox 7 23 38 43)
+  (hitbox 7 21 30 34)
   (mirror-action "ticking-left"))
  
  (action
   (name "explosion")
   (fps 5.0)
-  (hitbox 32 32 31.8 31.8)
+  (hitbox 13 12 44 48)
   (images sparkle-1.png
 sparkle-2.png
 sparkle-3.png
index 062ea5f..e0913f4 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb1.png and b/data/images/creatures/mr_cherry/cherrybomb1.png differ
index c9403c9..c572a35 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb2.png and b/data/images/creatures/mr_cherry/cherrybomb2.png differ
index 082f2c5..a98992e 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb3.png and b/data/images/creatures/mr_cherry/cherrybomb3.png differ
index f8bad09..58b23fc 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb4.png and b/data/images/creatures/mr_cherry/cherrybomb4.png differ
index 9b3e349..99c34ac 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb5.png and b/data/images/creatures/mr_cherry/cherrybomb5.png differ
index 1818d44..c5e7666 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb6.png and b/data/images/creatures/mr_cherry/cherrybomb6.png differ
index dd9927d..cfac58c 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_1.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_1.png differ
index a124118..f133862 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_2.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_2.png differ
index c30b86a..9a52044 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_3.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_3.png differ
index 5fcfd49..341cdcd 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_4.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_4.png differ
index 609524b..99a7af9 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_5.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_5.png differ
index 39fb01f..061f9a9 100644 (file)
Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_6.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_6.png differ
index 2e9e265..b5ed16b 100644 (file)
@@ -2,7 +2,7 @@
  (action
   (name "left")
   (fps 10.0)
-  (hitbox 7 23 38 43)
+  (hitbox 3 21 30 34)
   (images "cherrybomb1.png"
           "cherrybomb2.png"
           "cherrybomb3.png"
@@ -14,7 +14,7 @@
  (action
   (name "right")
   (fps 10.0)
-  (hitbox 7 23 38 43)
+  (hitbox 7 21 30 34)
   (mirror-action "left"))
 
 )
index 4b70b21..d7e4caa 100644 (file)
 #include "random_generator.hpp"
 #include "object/sprite_particle.hpp"
 
-static const float TICKINGTIME = 1;
-static const float EXPLOSIONTIME = 1;
-
 Bomb::Bomb(const Vector& pos, Direction dir)
        : BadGuy(pos, "images/creatures/mr_cherry/cherry.sprite")
 {
   state = STATE_TICKING;
-  timer.start(TICKINGTIME);
   this->dir = dir;
-  sprite->set_action(dir == LEFT ? "ticking-left" : "ticking-right");
+  set_action(dir == LEFT ? "ticking-left" : "ticking-right", 1);
   countMe = false;
 
   ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav"));
@@ -44,7 +40,7 @@ Bomb::Bomb(const Vector& pos, Direction dir)
 }
 
 Bomb::Bomb(const Bomb& other)
-       : BadGuy(other), state(other.state), timer(other.timer)
+       : BadGuy(other), state(other.state)
 {
   if (state == STATE_TICKING) {
     ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav"));
@@ -94,12 +90,12 @@ Bomb::active_update(float )
   switch(state) {
     case STATE_TICKING:
       ticking->set_position(get_pos());
-      if(timer.check()) {
+      if(sprite->animation_done()) {
         explode();
       }
       break;
     case STATE_EXPLODING:
-      if(timer.check()) {
+      if(sprite->animation_done()) {
         remove_me();
       }
       break;
@@ -112,22 +108,21 @@ Bomb::explode()
   ticking->stop();
   state = STATE_EXPLODING;
   set_group(COLGROUP_TOUCHABLE);
-  sprite->set_action("explosion");
   sound_manager->play("sounds/explosion.wav", get_pos());
-  timer.start(EXPLOSIONTIME);
-
-// spawn some particles
-          // TODO: provide convenience function in MovingSprite or MovingObject?
-          for (int i = 0; i < 100; i++) {
-            Vector ppos = bbox.get_middle();
-            float angle = systemRandom.randf(-M_PI_2, M_PI_2);
-            float velocity = systemRandom.randf(450, 900);
-            float vx = sin(angle)*velocity;
-            float vy = -cos(angle)*velocity;
-            Vector pspeed = Vector(vx, vy);
-            Vector paccel = Vector(0, 1000);
-            Sector::current()->add_object(new SpriteParticle("images/objects/particles/kracker.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
-          }
+  set_action_centered("explosion", 1);
+
+  // spawn some particles
+  // TODO: provide convenience function in MovingSprite or MovingObject?
+  for (int i = 0; i < 100; i++) {
+    Vector ppos = bbox.get_middle();
+    float angle = systemRandom.randf(-M_PI_2, M_PI_2);
+    float velocity = systemRandom.randf(450, 900);
+    float vx = sin(angle)*velocity;
+    float vy = -cos(angle)*velocity;
+    Vector pspeed = Vector(vx, vy);
+    Vector paccel = Vector(0, 1000);
+    Sector::current()->add_object(new SpriteParticle("images/objects/particles/kracker.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
+  }
 
 }
 
index 0bbe1c4..1bc4cb0 100644 (file)
@@ -45,7 +45,6 @@ private:
   };
   
   State state;
-  Timer timer;
 
   std::auto_ptr<SoundSource> ticking;
 
index 0f8e6c2..2a50dd9 100644 (file)
@@ -83,7 +83,11 @@ public:
   {
     set_width(width);
     set_height(height);
-  }                                         
+  }    
+  Vector get_size()
+  {
+    return Vector(get_width(), get_height());
+  }
 
   void move(const Vector& v)
   {
index 193d856..853de73 100644 (file)
@@ -110,4 +110,19 @@ MovingSprite::update(float )
 {
 }
 
+void 
+MovingSprite::set_action(const std::string& action, int loops)
+{
+  sprite->set_action(action, loops);
+  set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
+}
+
+void 
+MovingSprite::set_action_centered(const std::string& action, int loops)
+{
+  Vector old_size = bbox.get_size();
+  sprite->set_action(action, loops);
+  set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
+  set_pos(get_pos() - (bbox.get_size() - old_size) / 2);
+}
 
index df1743d..503f949 100644 (file)
@@ -47,6 +47,17 @@ protected:
   Sprite* sprite;
   int layer; /**< Sprite's z-position. Refer to video/drawing_context.hpp for sensible values. */
 
+  /**
+   * set new action for sprite and resize bounding box.
+   * use with care as you can easily get stuck when resizing the bounding box.
+   */
+  void set_action(const std::string& action, int loops);
+
+  /**
+   * set new action for sprite and re-center bounding box.
+   * use with care as you can easily get stuck when resizing the bounding box.
+   */
+  void set_action_centered(const std::string& action, int loops);
 };
 
 #endif