projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
More -Weffc++ cleanup
[supertux.git]
/
src
/
badguy
/
mrbomb.cpp
diff --git
a/src/badguy/mrbomb.cpp
b/src/badguy/mrbomb.cpp
index
15ab8f5
..
2e8a453
100644
(file)
--- a/
src/badguy/mrbomb.cpp
+++ b/
src/badguy/mrbomb.cpp
@@
-1,12
+1,10
@@
-// $Id$
-//
// SuperTux
// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// SuperTux
// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
-// 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
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
@@
-14,113
+12,136
@@
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// 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 <config.h>
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#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 "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 == "" ){
//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;
}
return;
}
- //Replace sprite
+ //Replace sprite
sprite = sprite_manager->create( sprite_name );
}
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
}
void
-MrBomb::activ
ate(
)
+MrBomb::activ
e_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
}
void
-MrBomb::
active_update(float elapsed_time
)
+MrBomb::
kill_fall(
)
{
{
- if (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& playe
r)
+void
+MrBomb::
grab(MovingObject&, const Vector& pos, Direction di
r)
{
{
- 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
}
void
-MrBomb::
collision_solid(const CollisionHit& hit
)
+MrBomb::
ungrab(MovingObject& , Direction dir
)
{
{
- 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&
)
+void
+MrBomb::
freeze(
)
{
{
-#if 0
- if(fabsf(hit.normal.x) > .8) { // left or right
- dir = dir == LEFT ? RIGHT : LEFT;
- sprite->set_action(dir == LEFT ? "left" : "right");
- physic.set_velocity_x(-physic.get_velocity_x());
- }
-#endif
+ WalkingBadguy::freeze();
+ sprite->set_action(dir == LEFT ? "iced-left" : "iced-right");
+}
- return CONTINUE;
+bool
+MrBomb::is_freezable() const
+{
+ return true;
}
}
-void
-MrBomb::
kill_fall()
+bool
+MrBomb::
is_portable() const
{
{
- remove_me();
- Bomb* bomb = new Bomb(get_pos(), dir, sprite_name );
- Sector::current()->add_object(bomb);
- bomb->explode();
+ return frozen;
}
}
-IMPLEMENT_FACTORY(MrBomb, "mrbomb")
+IMPLEMENT_FACTORY(MrBomb, "mrbomb");
+
+/* EOF */