src/badguy/skydive.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2010 Florian Forster <supertux at octo.it>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "badguy/skydive.hpp"
00018 
00019 #include "supertux/constants.hpp"
00020 #include "supertux/sector.hpp"
00021 #include "object/anchor_point.hpp"
00022 #include "object/player.hpp"
00023 #include "object/explosion.hpp"
00024 
00025 SkyDive::SkyDive(const Reader& reader) :
00026   BadGuy(reader, "images/creatures/skydive/skydive.sprite"),
00027   is_grabbed(false)
00028 {
00029 }
00030 
00031 SkyDive::SkyDive(const Vector& pos, Direction d) :
00032   BadGuy(pos, d, "images/creatures/skydive/skydive.sprite"),
00033   is_grabbed(false)
00034 {
00035 }
00036 
00037 void
00038 SkyDive::collision_solid(const CollisionHit& hit)
00039 {
00040   if (hit.bottom) {
00041     explode ();
00042     return;
00043   }
00044 
00045   if (hit.left || hit.right)
00046     physic.set_velocity_x (0.0);
00047 } /* void collision_solid */
00048 
00049 HitResponse
00050 SkyDive::collision_badguy(BadGuy&, const CollisionHit& hit)
00051 {
00052   if (hit.bottom) {
00053     explode ();
00054     return (ABORT_MOVE);
00055   }
00056 
00057   return (FORCE_MOVE);
00058 } /* HitResponse collision_badguy */
00059 
00060 void
00061 SkyDive::grab (MovingObject&, const Vector& pos, Direction dir)
00062 {
00063   movement = pos - get_pos();
00064   this->dir = dir;
00065 
00066   is_grabbed = true;
00067 
00068   physic.set_velocity_x (movement.x * LOGICAL_FPS);
00069   physic.set_velocity_y (0.0);
00070   physic.set_acceleration_y (0.0);
00071   physic.enable_gravity (false);
00072   set_colgroup_active (COLGROUP_DISABLED);
00073 }
00074 
00075 void
00076 SkyDive::ungrab (MovingObject& , Direction)
00077 {
00078   is_grabbed = false;
00079 
00080   physic.set_velocity_y (0);
00081   physic.set_acceleration_y (0);
00082   physic.enable_gravity (true);
00083   set_colgroup_active (COLGROUP_MOVING);
00084 }
00085 
00086 HitResponse
00087 SkyDive::collision_player(Player&, const CollisionHit& hit)
00088 {
00089   if (hit.bottom) {
00090     explode ();
00091     return (ABORT_MOVE);
00092   }
00093 
00094   return FORCE_MOVE;
00095 } /* HitResponse collision_player */
00096 
00097 bool
00098 SkyDive::collision_squished (GameObject& obj)
00099 {
00100   Player *player = dynamic_cast<Player *> (&obj);
00101   if (player) {
00102     player->bounce (*this);
00103     return (false);
00104   }
00105 
00106   explode ();
00107   return (false);
00108 } /* bool collision_squished */
00109 
00110 void
00111 SkyDive::active_update (float elapsed_time)
00112 {
00113   if (!is_grabbed)
00114     movement = physic.get_movement(elapsed_time);
00115 } /* void active_update */
00116 
00117 void
00118 SkyDive::explode (void)
00119 {
00120   if (!is_valid ())
00121     return;
00122 
00123   Explosion *explosion = new Explosion (get_anchor_pos (bbox, ANCHOR_BOTTOM));
00124 
00125   explosion->hurts (true);
00126   explosion->pushes (false);
00127   Sector::current()->add_object (explosion);
00128 
00129   remove_me ();
00130 } /* void explode */
00131 
00132 /* vim: set sw=2 sts=2 et fdm=marker : */
00133 /* EOF */

Generated on Mon Jun 9 03:38:17 2014 for SuperTux by  doxygen 1.5.1