3 // SuperTux - Boss "Yeti"
4 // Copyright (C) 2005 Matthias Braun <matze@braunis.de>
5 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
27 #include "object/camera.hpp"
28 #include "yeti_stalactite.hpp"
29 #include "bouncing_snowball.hpp"
30 #include "game_session.hpp"
34 const float JUMP_DOWN_VX = 250; /**< horizontal speed while jumping off the dais */
35 const float JUMP_DOWN_VY = -250; /**< vertical speed while jumping off the dais */
37 const float RUN_VX = 350; /**< horizontal speed while running */
39 const float JUMP_UP_VX = 350; /**< horizontal speed while jumping on the dais */
40 const float JUMP_UP_VY = -800; /**< vertical speed while jumping on the dais */
42 const float STOMP_VY = -250; /** vertical speed while stomping on the dais */
44 const float LEFT_STAND_X = 16; /**< x-coordinate of left dais' end position */
45 const float RIGHT_STAND_X = 800-60-16; /**< x-coordinate of right dais' end position */
46 const float LEFT_JUMP_X = LEFT_STAND_X+224; /**< x-coordinate of from where to jump on the left dais */
47 const float RIGHT_JUMP_X = RIGHT_STAND_X-224; /**< x-coordinate of from where to jump on the right dais */
48 const float STOMP_WAIT = .5; /**< time we stay on the dais before jumping again */
49 const float SAFE_TIME = .5; /**< the time we are safe when tux just hit us */
50 const int INITIAL_HITPOINTS = 3; /**< number of hits we can take */
52 const float SQUISH_TIME = 5;
55 Yeti::Yeti(const lisp::Lisp& reader)
56 : BadGuy(reader, "images/creatures/yeti/yeti.sprite")
58 hit_points = INITIAL_HITPOINTS;
60 sound_manager->preload("sounds/yeti_gna.wav");
61 sound_manager->preload("sounds/yeti_roar.wav");
62 hud_head.reset(new Surface("images/creatures/yeti/hudlife.png"));
63 draw_dead_script_hint = false;
78 Yeti::draw(DrawingContext& context)
80 // we blink when we are safe
81 if(safe_timer.started() && size_t(game_time*40)%2)
84 draw_hit_points(context);
86 BadGuy::draw(context);
90 Yeti::draw_hit_points(DrawingContext& context)
94 Surface *hh = hud_head.get();
98 context.push_transform();
99 context.set_translation(Vector(0, 0));
101 for (i = 0; i < hit_points; ++i)
103 context.draw_surface(hh, Vector(BORDER_X + (i * hh->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1);
106 context.pop_transform();
110 Yeti::active_update(float elapsed_time)
114 physic.set_velocity_x((dir==RIGHT)?+JUMP_DOWN_VX:-JUMP_DOWN_VX);
117 physic.set_velocity_x((dir==RIGHT)?+RUN_VX:-RUN_VX);
118 if (((dir == RIGHT) && (get_pos().x >= RIGHT_JUMP_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_JUMP_X))) jump_up();
121 physic.set_velocity_x((dir==RIGHT)?+JUMP_UP_VX:-JUMP_UP_VX);
122 if (((dir == RIGHT) && (get_pos().x >= RIGHT_STAND_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_STAND_X))) be_angry();
125 if(state_timer.check()) {
126 sound_manager->play("sounds/yeti_gna.wav");
127 physic.set_velocity_y(STOMP_VY);
128 sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left");
132 if (state_timer.check()) {
138 movement = physic.get_movement(elapsed_time);
144 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
145 physic.set_velocity_x((dir==RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX));
146 physic.set_velocity_y(JUMP_DOWN_VY);
153 sprite->set_action((dir==RIGHT)?"run-right":"run-left");
154 physic.set_velocity_x((dir==RIGHT)?(+RUN_VX):(-RUN_VX));
155 physic.set_velocity_y(0);
162 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
163 physic.set_velocity_x((dir==RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX));
164 physic.set_velocity_y(JUMP_UP_VY);
172 dir = (dir==RIGHT)?LEFT:RIGHT;
174 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
175 physic.set_velocity_x(0);
176 physic.set_velocity_y(0);
177 if (hit_points < INITIAL_HITPOINTS) summon_snowball();
180 state_timer.start(STOMP_WAIT);
184 Yeti::summon_snowball()
186 Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x+(dir == RIGHT ? 64 : -64), get_pos().y), dir));
190 Yeti::collision_squished(GameObject& object)
192 kill_squished(object);
198 Yeti::kill_squished(GameObject& object)
200 Player* player = dynamic_cast<Player*>(&object);
202 player->bounce(*this);
207 void Yeti::take_hit(Player& )
209 if(safe_timer.started())
212 sound_manager->play("sounds/yeti_roar.wav");
215 if(hit_points <= 0) {
217 physic.enable_gravity(true);
218 physic.set_velocity_x(0);
219 physic.set_velocity_y(0);
222 state_timer.start(SQUISH_TIME);
223 set_group(COLGROUP_MOVING_ONLY_STATIC);
224 sprite->set_action("dead");
226 if (countMe) Sector::current()->get_level()->stats.badguys++;
228 if(dead_script != "") {
229 std::istringstream stream(dead_script);
230 Sector::current()->run_script(stream, "Yeti - dead-script");
234 safe_timer.start(SAFE_TIME);
241 // shooting bullets or being invincible won't work :)
242 take_hit(*get_nearest_player()); // FIXME: debug only(?)
246 Yeti::write(lisp::Writer& writer)
248 writer.start_list("yeti");
250 writer.write_float("x", start_position.x);
251 writer.write_float("y", start_position.y);
253 writer.end_list("yeti");
257 Yeti::drop_stalactite()
259 // make a stalactite falling down and shake camera a bit
260 Sector::current()->camera->shake(.1f, 0, 10);
262 YetiStalactite* nearest = 0;
263 float dist = FLT_MAX;
265 Player* player = this->get_nearest_player();
268 Sector* sector = Sector::current();
269 for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
270 i != sector->gameobjects.end(); ++i) {
271 YetiStalactite* stalactite = dynamic_cast<YetiStalactite*> (*i);
272 if(stalactite && stalactite->is_hanging()) {
274 = fabsf(stalactite->get_pos().x - player->get_pos().x);
276 nearest = stalactite;
283 nearest->start_shaking();
287 Yeti::collision_solid(const CollisionHit& hit)
289 if(hit.top || hit.bottom) {
291 physic.set_velocity_y(0);
302 if(!state_timer.started()) {
303 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
307 // go to other side after 3 jumps
308 if(stomp_count == 3) {
312 state_timer.start(STOMP_WAIT);
319 } else if(hit.left || hit.right) {
325 IMPLEMENT_FACTORY(Yeti, "yeti")