4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "sprite/sprite_manager.hpp"
26 static const float WALKSPEED = 80;
28 MrBomb::MrBomb(const lisp::Lisp& reader)
29 : BadGuy(reader, "images/creatures/mr_cherry/mr_cherry.sprite")
31 //Check if we need another sprite
32 if( !reader.get( "sprite", sprite_name ) ){
35 if( sprite_name == "" ){
36 sprite_name = "images/creatures/mr_cherry/mr_cherry.sprite";
40 sprite = sprite_manager->create( sprite_name );
43 /* MrBomb created by a despencer always gets default sprite atm.*/
44 MrBomb::MrBomb(const Vector& pos, Direction d)
45 : BadGuy(pos, d, "images/creatures/mr_cherry/mr_cherry.sprite")
50 MrBomb::write(lisp::Writer& writer)
52 writer.start_list("mrbomb");
54 writer.write_float("x", start_position.x);
55 writer.write_float("y", start_position.y);
57 writer.end_list("mrbomb");
63 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
64 sprite->set_action(dir == LEFT ? "left" : "right");
65 bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
69 MrBomb::active_update(float elapsed_time)
73 dir = (dir == LEFT ? RIGHT : LEFT);
74 sprite->set_action(dir == LEFT ? "left" : "right");
75 physic.set_velocity_x(-physic.get_velocity_x());
78 BadGuy::active_update(elapsed_time);
82 MrBomb::collision_squished(Player& player)
85 Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name ));
86 kill_squished(player);
91 MrBomb::collision_solid(GameObject& , const CollisionHit& hit)
93 if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
94 physic.set_velocity_y(0);
95 } else { // hit right or left
96 dir = dir == LEFT ? RIGHT : LEFT;
97 sprite->set_action(dir == LEFT ? "left" : "right");
98 physic.set_velocity_x(-physic.get_velocity_x());
105 MrBomb::collision_badguy(BadGuy& , const CollisionHit& hit)
107 if(fabsf(hit.normal.x) > .8) { // left or right
108 dir = dir == LEFT ? RIGHT : LEFT;
109 sprite->set_action(dir == LEFT ? "left" : "right");
110 physic.set_velocity_x(-physic.get_velocity_x());
120 Bomb* bomb = new Bomb(get_pos(), dir, sprite_name );
121 Sector::current()->add_object(bomb);
125 IMPLEMENT_FACTORY(MrBomb, "mrbomb")