X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fmrbomb.cpp;h=2e8a4531e746bed2b453f5fcaa68079f27ae9bd0;hb=12a28b64dcce9c7ff706451b4f3aecd201cc8a5f;hp=78cb5b7261f7b54fca6029a3f0dd901c85ffcc72;hpb=34c5787d09b5d56664c13173dbafb6242a3d4e65;p=supertux.git diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index 78cb5b726..2e8a4531e 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux // Copyright (C) 2006 Matthias Braun // -// 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 2 -// of the License, or (at your option) any later version. +// 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 @@ -14,112 +12,136 @@ // 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, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include +// along with this program. If not, see . -#include "mrbomb.hpp" -#include "bomb.hpp" +#include "audio/sound_manager.hpp" +#include "badguy/bomb.hpp" +#include "badguy/mrbomb.hpp" +#include "object/explosion.hpp" +#include "sprite/sprite.hpp" #include "sprite/sprite_manager.hpp" +#include "supertux/object_factory.hpp" +#include "supertux/sector.hpp" -static const float WALKSPEED = 80; - -MrBomb::MrBomb(const lisp::Lisp& reader) - : BadGuy(reader, "images/creatures/mr_cherry/mr_cherry.sprite") +MrBomb::MrBomb(const Reader& reader) : + WalkingBadguy(reader, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right"), + grabbed() { + walk_speed = 80; + max_drop_height = 16; + grabbed = false; + + //Prevent stutter when Tux jumps on Mr Bomb + sound_manager->preload("sounds/explosion.wav"); + //Check if we need another sprite if( !reader.get( "sprite", sprite_name ) ){ return; } if( sprite_name == "" ){ - sprite_name = "images/creatures/mr_cherry/mr_cherry.sprite"; + sprite_name = "images/creatures/mr_bomb/mr_bomb.sprite"; return; } - //Replace sprite + //Replace sprite sprite = sprite_manager->create( sprite_name ); } -/* MrBomb created by a despencer always gets default sprite atm.*/ -MrBomb::MrBomb(const Vector& pos, Direction d) - : BadGuy(pos, d, "images/creatures/mr_cherry/mr_cherry.sprite") +/* MrBomb created by a dispenser always gets default sprite atm.*/ +MrBomb::MrBomb(const Vector& pos, Direction d) : + WalkingBadguy(pos, d, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right"), + grabbed() { + walk_speed = 80; + max_drop_height = 16; + grabbed = false; + sound_manager->preload("sounds/explosion.wav"); } -void -MrBomb::write(lisp::Writer& writer) +HitResponse +MrBomb::collision(GameObject& object, const CollisionHit& hit) { - writer.start_list("mrbomb"); + if(grabbed) + return FORCE_MOVE; + return WalkingBadguy::collision(object, hit); +} - writer.write_float("x", start_position.x); - writer.write_float("y", start_position.y); +HitResponse +MrBomb::collision_player(Player& player, const CollisionHit& hit) +{ + if(grabbed) + return FORCE_MOVE; + return WalkingBadguy::collision_player(player, hit); +} - writer.end_list("mrbomb"); +bool +MrBomb::collision_squished(GameObject& object) +{ + if(is_valid()) { + remove_me(); + Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name )); + } + kill_squished(object); + return true; } void -MrBomb::activate() +MrBomb::active_update(float elapsed_time) { - physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); - sprite->set_action(dir == LEFT ? "left" : "right"); - bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); + if(grabbed) + return; + WalkingBadguy::active_update(elapsed_time); } void -MrBomb::active_update(float elapsed_time) +MrBomb::kill_fall() { - if (on_ground() && might_fall()) - { - dir = (dir == LEFT ? RIGHT : LEFT); - sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(-physic.get_velocity_x()); + if(is_valid()) { + remove_me(); + Explosion* explosion = new Explosion(get_bbox().get_middle()); + Sector::current()->add_object(explosion); } - BadGuy::active_update(elapsed_time); + run_dead_script(); } -bool -MrBomb::collision_squished(Player& player) +void +MrBomb::grab(MovingObject&, const Vector& pos, Direction dir) { - remove_me(); - Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name )); - kill_squished(player); - return true; + assert(frozen); + movement = pos - get_pos(); + this->dir = dir; + sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); + set_colgroup_active(COLGROUP_DISABLED); + grabbed = true; } void -MrBomb::collision_solid(const CollisionHit& hit) +MrBomb::ungrab(MovingObject& , Direction dir) { - update_on_ground_flag(hit); - - if(hit.bottom || hit.top) { - physic.set_velocity_y(0); - } - if(hit.left || hit.right) { - dir = dir == LEFT ? RIGHT : LEFT; - sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(-physic.get_velocity_x()); - } + this->dir = dir; + set_colgroup_active(COLGROUP_MOVING); + grabbed = false; } -HitResponse -MrBomb::collision_badguy(BadGuy&, const CollisionHit& hit ) +void +MrBomb::freeze() { - if(hit.left || hit.right) { - dir = (dir == LEFT) ? RIGHT : LEFT; - sprite->set_action(dir == LEFT ? "left" : "right"); - physic.set_velocity_x(-physic.get_velocity_x()); - } - return CONTINUE; + WalkingBadguy::freeze(); + sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); } -void -MrBomb::kill_fall() +bool +MrBomb::is_freezable() const { - remove_me(); - Bomb* bomb = new Bomb(get_pos(), dir, sprite_name ); - Sector::current()->add_object(bomb); - bomb->explode(); + return true; } -IMPLEMENT_FACTORY(MrBomb, "mrbomb") +bool +MrBomb::is_portable() const +{ + return frozen; +} + +IMPLEMENT_FACTORY(MrBomb, "mrbomb"); + +/* EOF */