1 // SuperTux - Mole Badguy
2 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
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 "audio/sound_manager.hpp"
18 #include "badguy/mole.hpp"
19 #include "badguy/mole_rock.hpp"
20 #include "math/random_generator.hpp"
21 #include "sprite/sprite.hpp"
22 #include "supertux/object_factory.hpp"
23 #include "supertux/sector.hpp"
27 static const float IDLE_TIME = 0.2f; /**< time to wait before and after throwing */
28 static const float THROW_TIME = 4.6f; /**< time to spend throwing */
29 static const float THROW_INTERVAL = 1; /**< time between two thrown rocks */
30 static const float THROW_VELOCITY = 400; /**< initial velocity of thrown rocks */
32 Mole::Mole(const Reader& reader) :
33 BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1),
38 physic.enable_gravity(false);
39 sound_manager->preload("sounds/fall.wav");
40 sound_manager->preload("sounds/squish.wav");
41 sound_manager->preload("sounds/dartfire.wav");
44 Mole::Mole(const Vector& pos) :
45 BadGuy(pos, "images/creatures/mole/mole.sprite", LAYER_TILES-1),
50 physic.enable_gravity(false);
51 sound_manager->preload("sounds/fall.wav");
52 sound_manager->preload("sounds/squish.wav");
53 sound_manager->preload("sounds/dartfire.wav");
59 if (state != DEAD) set_state(PRE_THROWING);
66 sound_manager->play("sounds/fall.wav", get_pos());
71 Mole::collision_badguy(BadGuy& , const CollisionHit& )
77 Mole::collision_squished(GameObject& )
80 sound_manager->play("sounds/squish.wav", get_pos());
88 float px = get_bbox().get_middle().x;
89 float py = get_bbox().get_middle().y;
91 float angle = systemRandom.rand(90 - 15, 90 + 15) * (M_PI / 180);
92 float vx = cos(angle) * THROW_VELOCITY;
93 float vy = -sin(angle) * THROW_VELOCITY;
95 sound_manager->play("sounds/dartfire.wav", get_pos());
96 Sector::current()->add_object(new MoleRock(Vector(px, py), Vector(vx, vy), this));
100 Mole::active_update(float elapsed_time)
102 BadGuy::active_update(elapsed_time);
111 if (throw_timer.check()) {
113 throw_timer.start(THROW_INTERVAL);
116 set_state(POST_THROWING);
125 if (sprite->animation_done()) {
126 set_state(PRE_THROWING);
136 Mole::set_state(MoleState new_state)
140 sprite->set_action("idle");
141 set_colgroup_active(COLGROUP_DISABLED);
142 timer.start(IDLE_TIME);
145 sprite->set_action("idle");
146 set_colgroup_active(COLGROUP_DISABLED);
147 timer.start(THROW_TIME);
148 throw_timer.start(THROW_INTERVAL);
151 sprite->set_action("idle");
152 set_colgroup_active(COLGROUP_DISABLED);
153 timer.start(IDLE_TIME);
156 sprite->set_action("peeking", 1);
157 set_colgroup_active(COLGROUP_STATIC);
160 sprite->set_action("idle");
161 set_colgroup_active(COLGROUP_DISABLED);
168 IMPLEMENT_FACTORY(Mole, "mole");