00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 }
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 }
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 }
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 }
00109
00110 void
00111 SkyDive::active_update (float elapsed_time)
00112 {
00113 if (!is_grabbed)
00114 movement = physic.get_movement(elapsed_time);
00115 }
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 }
00131
00132
00133