2 // Copyright (C) 2010 Florian Forster <supertux at octo.it>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "badguy/bombfish.hpp"
19 #include "supertux/constants.hpp"
20 #include "supertux/sector.hpp"
21 #include "object/player.hpp"
22 #include "object/explosion.hpp"
24 BombFish::BombFish(const Reader& reader) :
25 BadGuy(reader, "images/creatures/bombfish/bombfish.sprite"),
30 BombFish::BombFish(const Vector& pos, Direction d) :
31 BadGuy(pos, d, "images/creatures/bombfish/bombfish.sprite"),
37 BombFish::collision_solid(const CollisionHit& hit)
44 if (hit.left || hit.right)
45 physic.set_velocity_x (0.0);
46 } /* void collision_solid */
49 BombFish::collision_badguy(BadGuy&, const CollisionHit& hit)
57 } /* HitResponse collision_badguy */
60 BombFish::grab (MovingObject&, const Vector& pos, Direction dir)
62 movement = pos - get_pos();
67 physic.set_velocity_x (movement.x * LOGICAL_FPS);
68 physic.set_velocity_y (0.0);
69 physic.set_acceleration_y (0.0);
70 physic.enable_gravity (false);
71 set_colgroup_active (COLGROUP_DISABLED);
75 BombFish::ungrab (MovingObject& , Direction)
79 physic.set_velocity_y (0);
80 physic.set_acceleration_y (0);
81 physic.enable_gravity (true);
82 set_colgroup_active (COLGROUP_MOVING);
86 BombFish::collision_player(Player&, const CollisionHit& hit)
94 } /* HitResponse collision_player */
97 BombFish::collision_squished (GameObject& obj)
99 Player *player = dynamic_cast<Player *> (&obj);
101 player->bounce (*this);
107 } /* bool collision_squished */
110 BombFish::active_update (float elapsed_time)
113 movement = physic.get_movement(elapsed_time);
114 } /* void active_update */
117 BombFish::explode (void)
122 Explosion *explosion = new Explosion (get_bbox ().get_middle ());
124 explosion->hurts (true);
125 explosion->pushes (false);
126 Sector::current()->add_object (explosion);
131 /* vim: set sw=2 sts=2 et fdm=marker : */