1 // SuperTux - Boss "Yeti"
2 // Copyright (C) 2005 Matthias Braun <matze@braunis.de>
3 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "badguy/yeti.hpp"
20 #include "audio/sound_manager.hpp"
21 #include "badguy/bouncing_snowball.hpp"
22 #include "badguy/yeti_stalactite.hpp"
23 #include "object/camera.hpp"
24 #include "object/player.hpp"
25 #include "sprite/sprite.hpp"
26 #include "supertux/object_factory.hpp"
27 #include "supertux/sector.hpp"
33 const float JUMP_DOWN_VX = 250; /**< horizontal speed while jumping off the dais */
34 const float JUMP_DOWN_VY = -250; /**< vertical speed while jumping off the dais */
36 const float RUN_VX = 350; /**< horizontal speed while running */
38 const float JUMP_UP_VX = 350; /**< horizontal speed while jumping on the dais */
39 const float JUMP_UP_VY = -800; /**< vertical speed while jumping on the dais */
41 const float STOMP_VY = -250; /** vertical speed while stomping on the dais */
43 const float LEFT_STAND_X = 16; /**< x-coordinate of left dais' end position */
44 const float RIGHT_STAND_X = 800-60-16; /**< x-coordinate of right dais' end position */
45 const float LEFT_JUMP_X = LEFT_STAND_X+224; /**< x-coordinate of from where to jump on the left dais */
46 const float RIGHT_JUMP_X = RIGHT_STAND_X-224; /**< x-coordinate of from where to jump on the right dais */
47 const float STOMP_WAIT = .5; /**< time we stay on the dais before jumping again */
48 const float SAFE_TIME = .5; /**< the time we are safe when tux just hit us */
49 const int INITIAL_HITPOINTS = 3; /**< number of hits we can take */
51 const float SQUISH_TIME = 5;
54 Yeti::Yeti(const Reader& reader) :
55 BadGuy(reader, "images/creatures/yeti/yeti.sprite"),
63 hit_points = INITIAL_HITPOINTS;
65 sound_manager->preload("sounds/yeti_gna.wav");
66 sound_manager->preload("sounds/yeti_roar.wav");
67 hud_head = Surface::create("images/creatures/yeti/hudlife.png");
82 Yeti::draw(DrawingContext& context)
84 // we blink when we are safe
85 if(safe_timer.started() && size_t(game_time*40)%2)
88 draw_hit_points(context);
90 BadGuy::draw(context);
94 Yeti::draw_hit_points(DrawingContext& context)
100 context.push_transform();
101 context.set_translation(Vector(0, 0));
103 for (i = 0; i < hit_points; ++i)
105 context.draw_surface(hud_head, Vector(BORDER_X + (i * hud_head->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1);
108 context.pop_transform();
113 Yeti::active_update(float elapsed_time)
117 physic.set_velocity_x((dir==RIGHT)?+JUMP_DOWN_VX:-JUMP_DOWN_VX);
120 physic.set_velocity_x((dir==RIGHT)?+RUN_VX:-RUN_VX);
121 if (((dir == RIGHT) && (get_pos().x >= RIGHT_JUMP_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_JUMP_X))) jump_up();
124 physic.set_velocity_x((dir==RIGHT)?+JUMP_UP_VX:-JUMP_UP_VX);
125 if (((dir == RIGHT) && (get_pos().x >= RIGHT_STAND_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_STAND_X))) be_angry();
128 if(state_timer.check()) {
129 sound_manager->play("sounds/yeti_gna.wav");
130 physic.set_velocity_y(STOMP_VY);
131 sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left");
135 if (state_timer.check()) {
141 movement = physic.get_movement(elapsed_time);
147 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
148 physic.set_velocity_x((dir==RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX));
149 physic.set_velocity_y(JUMP_DOWN_VY);
156 sprite->set_action((dir==RIGHT)?"run-right":"run-left");
157 physic.set_velocity_x((dir==RIGHT)?(+RUN_VX):(-RUN_VX));
158 physic.set_velocity_y(0);
165 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
166 physic.set_velocity_x((dir==RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX));
167 physic.set_velocity_y(JUMP_UP_VY);
175 dir = (dir==RIGHT)?LEFT:RIGHT;
177 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
178 physic.set_velocity_x(0);
179 physic.set_velocity_y(0);
180 if (hit_points < INITIAL_HITPOINTS) summon_snowball();
183 state_timer.start(STOMP_WAIT);
187 Yeti::summon_snowball()
189 Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x+(dir == RIGHT ? 64 : -64), get_pos().y), dir));
193 Yeti::collision_squished(GameObject& object)
195 kill_squished(object);
201 Yeti::kill_squished(GameObject& object)
203 Player* player = dynamic_cast<Player*>(&object);
205 player->bounce(*this);
210 void Yeti::take_hit(Player& )
212 if(safe_timer.started())
215 sound_manager->play("sounds/yeti_roar.wav");
218 if(hit_points <= 0) {
220 physic.enable_gravity(true);
221 physic.set_velocity_x(0);
222 physic.set_velocity_y(0);
225 state_timer.start(SQUISH_TIME);
226 set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC);
227 sprite->set_action("dead");
232 safe_timer.start(SAFE_TIME);
239 // shooting bullets or being invincible won't work :)
240 //take_hit(*get_nearest_player()); // FIXME: debug only(?)
244 Yeti::drop_stalactite()
246 // make a stalactite falling down and shake camera a bit
247 Sector::current()->camera->shake(.1f, 0, 10);
249 YetiStalactite* nearest = 0;
250 float dist = FLT_MAX;
252 Player* player = this->get_nearest_player();
255 Sector* sector = Sector::current();
256 for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
257 i != sector->gameobjects.end(); ++i) {
258 YetiStalactite* stalactite = dynamic_cast<YetiStalactite*> (*i);
259 if(stalactite && stalactite->is_hanging()) {
261 = fabsf(stalactite->get_pos().x - player->get_pos().x);
263 nearest = stalactite;
270 nearest->start_shaking();
274 Yeti::collision_solid(const CollisionHit& hit)
276 if(hit.top || hit.bottom) {
278 physic.set_velocity_y(0);
289 if(!state_timer.started()) {
290 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
294 // go to other side after 3 jumps
295 if(stomp_count == 3) {
299 state_timer.start(STOMP_WAIT);
306 } else if(hit.left || hit.right) {