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/skydive.hpp"
19 #include "supertux/constants.hpp"
20 #include "supertux/sector.hpp"
21 #include "object/anchor_point.hpp"
22 #include "object/player.hpp"
23 #include "object/explosion.hpp"
25 SkyDive::SkyDive(const Reader& reader) :
26 BadGuy(reader, "images/creatures/skydive/skydive.sprite"),
31 SkyDive::SkyDive(const Vector& pos, Direction d) :
32 BadGuy(pos, d, "images/creatures/skydive/skydive.sprite"),
38 SkyDive::collision_solid(const CollisionHit& hit)
45 if (hit.left || hit.right)
46 physic.set_velocity_x (0.0);
47 } /* void collision_solid */
50 SkyDive::collision_badguy(BadGuy&, const CollisionHit& hit)
58 } /* HitResponse collision_badguy */
61 SkyDive::grab (MovingObject&, const Vector& pos, Direction dir_)
63 movement = pos - get_pos();
68 physic.set_velocity_x (movement.x * LOGICAL_FPS);
69 physic.set_velocity_y (0.0);
70 physic.set_acceleration_y (0.0);
71 physic.enable_gravity (false);
72 set_colgroup_active (COLGROUP_DISABLED);
76 SkyDive::ungrab (MovingObject& , Direction)
80 physic.set_velocity_y (0);
81 physic.set_acceleration_y (0);
82 physic.enable_gravity (true);
83 set_colgroup_active (COLGROUP_MOVING);
87 SkyDive::collision_player(Player&, const CollisionHit& hit)
95 } /* HitResponse collision_player */
98 SkyDive::collision_squished (GameObject& obj)
100 Player *player = dynamic_cast<Player *> (&obj);
102 player->bounce (*this);
108 } /* bool collision_squished */
111 SkyDive::active_update (float elapsed_time)
114 movement = physic.get_movement(elapsed_time);
115 } /* void active_update */
118 SkyDive::explode (void)
123 Explosion *explosion = new Explosion (get_anchor_pos (bbox, ANCHOR_BOTTOM));
125 explosion->hurts (true);
126 explosion->pushes (false);
127 Sector::current()->add_object (explosion);
132 /* vim: set sw=2 sts=2 et fdm=marker : */