From: Christoph Sommer Date: Wed, 5 Jul 2006 13:52:13 +0000 (+0000) Subject: Shrunk cherry bomb a little, fixed bounding boxes. / X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=6e7c8fafae2311b22c78b1ea597a408396873560;p=supertux.git Shrunk cherry bomb a little, fixed bounding boxes. / Bomb explosion is now bigger than the bomb SVN-Revision: 3893 --- diff --git a/data/images/creatures/mr_cherry/cherry.sprite b/data/images/creatures/mr_cherry/cherry.sprite index 950e0f92a..d6590aca7 100644 --- a/data/images/creatures/mr_cherry/cherry.sprite +++ b/data/images/creatures/mr_cherry/cherry.sprite @@ -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 diff --git a/data/images/creatures/mr_cherry/cherrybomb1.png b/data/images/creatures/mr_cherry/cherrybomb1.png index 062ea5f58..e0913f47d 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb1.png and b/data/images/creatures/mr_cherry/cherrybomb1.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb2.png b/data/images/creatures/mr_cherry/cherrybomb2.png index c9403c993..c572a3516 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb2.png and b/data/images/creatures/mr_cherry/cherrybomb2.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb3.png b/data/images/creatures/mr_cherry/cherrybomb3.png index 082f2c56e..a98992e51 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb3.png and b/data/images/creatures/mr_cherry/cherrybomb3.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb4.png b/data/images/creatures/mr_cherry/cherrybomb4.png index f8bad0974..58b23fc4f 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb4.png and b/data/images/creatures/mr_cherry/cherrybomb4.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb5.png b/data/images/creatures/mr_cherry/cherrybomb5.png index 9b3e349d9..99c34accd 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb5.png and b/data/images/creatures/mr_cherry/cherrybomb5.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb6.png b/data/images/creatures/mr_cherry/cherrybomb6.png index 1818d4451..c5e7666dd 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb6.png and b/data/images/creatures/mr_cherry/cherrybomb6.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb_hit_1.png b/data/images/creatures/mr_cherry/cherrybomb_hit_1.png index dd9927dec..cfac58cc1 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_1.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_1.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb_hit_2.png b/data/images/creatures/mr_cherry/cherrybomb_hit_2.png index a1241183d..f133862b1 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_2.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_2.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb_hit_3.png b/data/images/creatures/mr_cherry/cherrybomb_hit_3.png index c30b86a48..9a5204431 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_3.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_3.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb_hit_4.png b/data/images/creatures/mr_cherry/cherrybomb_hit_4.png index 5fcfd492f..341cdcdfa 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_4.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_4.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb_hit_5.png b/data/images/creatures/mr_cherry/cherrybomb_hit_5.png index 609524bc9..99a7af9d0 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_5.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_5.png differ diff --git a/data/images/creatures/mr_cherry/cherrybomb_hit_6.png b/data/images/creatures/mr_cherry/cherrybomb_hit_6.png index 39fb01f91..061f9a912 100644 Binary files a/data/images/creatures/mr_cherry/cherrybomb_hit_6.png and b/data/images/creatures/mr_cherry/cherrybomb_hit_6.png differ diff --git a/data/images/creatures/mr_cherry/mr_cherry.sprite b/data/images/creatures/mr_cherry/mr_cherry.sprite index 2e9e265df..b5ed16b3a 100644 --- a/data/images/creatures/mr_cherry/mr_cherry.sprite +++ b/data/images/creatures/mr_cherry/mr_cherry.sprite @@ -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")) ) diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index 4b70b2135..d7e4caa26 100644 --- a/src/badguy/bomb.cpp +++ b/src/badguy/bomb.cpp @@ -23,16 +23,12 @@ #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)); + } } diff --git a/src/badguy/bomb.hpp b/src/badguy/bomb.hpp index 0bbe1c4f9..1bc4cb0d2 100644 --- a/src/badguy/bomb.hpp +++ b/src/badguy/bomb.hpp @@ -45,7 +45,6 @@ private: }; State state; - Timer timer; std::auto_ptr ticking; diff --git a/src/math/rect.hpp b/src/math/rect.hpp index 0f8e6c259..2a50dd955 100644 --- a/src/math/rect.hpp +++ b/src/math/rect.hpp @@ -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) { diff --git a/src/object/moving_sprite.cpp b/src/object/moving_sprite.cpp index 193d856b4..853de73ff 100644 --- a/src/object/moving_sprite.cpp +++ b/src/object/moving_sprite.cpp @@ -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); +} diff --git a/src/object/moving_sprite.hpp b/src/object/moving_sprite.hpp index df1743dbc..503f9491c 100644 --- a/src/object/moving_sprite.hpp +++ b/src/object/moving_sprite.hpp @@ -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