Owl: Drop "Bombfishes" by default.
[supertux.git] / src / badguy / bombfish.cpp
1 //  SuperTux
2 //  Copyright (C) 2010 Florian Forster <supertux at octo.it>
3 //
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.
8 //
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.
13 //
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/>.
16
17 #include "badguy/bombfish.hpp"
18
19 #include "supertux/constants.hpp"
20 #include "supertux/sector.hpp"
21 #include "object/player.hpp"
22 #include "object/explosion.hpp"
23
24 BombFish::BombFish(const Reader& reader) :
25   BadGuy(reader, "images/creatures/bombfish/bombfish.sprite"),
26   is_grabbed(false)
27 {
28 }
29
30 BombFish::BombFish(const Vector& pos, Direction d) :
31   BadGuy(pos, d, "images/creatures/bombfish/bombfish.sprite"),
32   is_grabbed(false)
33 {
34 }
35
36 void
37 BombFish::collision_solid(const CollisionHit& hit)
38 {
39   if (hit.bottom) {
40     explode ();
41     return;
42   }
43
44   if (hit.left || hit.right)
45     physic.set_velocity_x (0.0);
46 } /* void collision_solid */
47
48 HitResponse
49 BombFish::collision_badguy(BadGuy&, const CollisionHit& hit)
50 {
51   if (hit.bottom) {
52     explode ();
53     return (ABORT_MOVE);
54   }
55
56   return (FORCE_MOVE);
57 } /* HitResponse collision_badguy */
58
59 void
60 BombFish::grab (MovingObject&, const Vector& pos, Direction dir)
61 {
62   movement = pos - get_pos();
63   this->dir = dir;
64
65   is_grabbed = true;
66
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);
72 }
73
74 void
75 BombFish::ungrab (MovingObject& , Direction)
76 {
77   is_grabbed = false;
78
79   physic.set_velocity_y (0);
80   physic.set_acceleration_y (0);
81   physic.enable_gravity (true);
82   set_colgroup_active (COLGROUP_MOVING);
83 }
84
85 HitResponse
86 BombFish::collision_player(Player&, const CollisionHit& hit)
87 {
88   if (hit.bottom) {
89     explode ();
90     return (ABORT_MOVE);
91   }
92
93   return FORCE_MOVE;
94 } /* HitResponse collision_player */
95
96 bool
97 BombFish::collision_squished (GameObject& obj)
98 {
99   Player *player = dynamic_cast<Player *> (&obj);
100   if (player) {
101     player->bounce (*this);
102     return (false);
103   }
104
105   explode ();
106   return (false);
107 } /* bool collision_squished */
108
109 void
110 BombFish::active_update (float elapsed_time)
111 {
112   if (!is_grabbed)
113     movement = physic.get_movement(elapsed_time);
114 } /* void active_update */
115
116 void
117 BombFish::explode (void)
118 {
119   if (!is_valid ())
120     return;
121
122   Explosion *explosion = new Explosion (get_bbox ().get_middle ());
123
124   explosion->hurts (true);
125   explosion->pushes (false);
126   Sector::current()->add_object (explosion);
127
128   remove_me ();
129 } /* void explode */
130
131 /* vim: set sw=2 sts=2 et fdm=marker : */
132 /* EOF */