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 draw_dead_script_hint = false;
77 Yeti::draw(DrawingContext& context)
79 // we blink when we are safe
80 if(safe_timer.started() && size_t(game_time*40)%2)
83 BadGuy::draw(context);
87 Yeti::active_update(float elapsed_time)
91 physic.set_velocity_x((dir==RIGHT)?+JUMP_DOWN_VX:-JUMP_DOWN_VX);
94 physic.set_velocity_x((dir==RIGHT)?+RUN_VX:-RUN_VX);
95 if (((dir == RIGHT) && (get_pos().x >= RIGHT_JUMP_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_JUMP_X))) jump_up();
98 physic.set_velocity_x((dir==RIGHT)?+JUMP_UP_VX:-JUMP_UP_VX);
99 if (((dir == RIGHT) && (get_pos().x >= RIGHT_STAND_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_STAND_X))) be_angry();
102 if(state_timer.check()) {
103 sound_manager->play("sounds/yeti_gna.wav");
104 physic.set_velocity_y(STOMP_VY);
105 sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left");
109 if (state_timer.check()) {
115 movement = physic.get_movement(elapsed_time);
121 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
122 physic.set_velocity_x((dir==RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX));
123 physic.set_velocity_y(JUMP_DOWN_VY);
130 sprite->set_action((dir==RIGHT)?"run-right":"run-left");
131 physic.set_velocity_x((dir==RIGHT)?(+RUN_VX):(-RUN_VX));
132 physic.set_velocity_y(0);
139 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
140 physic.set_velocity_x((dir==RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX));
141 physic.set_velocity_y(JUMP_UP_VY);
149 dir = (dir==RIGHT)?LEFT:RIGHT;
151 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
152 physic.set_velocity_x(0);
153 physic.set_velocity_y(0);
154 if (hit_points < INITIAL_HITPOINTS) summon_snowball();
157 state_timer.start(STOMP_WAIT);
161 Yeti::summon_snowball()
163 Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x+(dir == RIGHT ? 64 : -64), get_pos().y), dir));
167 Yeti::collision_squished(GameObject& object)
169 kill_squished(object);
175 Yeti::kill_squished(GameObject& object)
177 Player* player = dynamic_cast<Player*>(&object);
179 player->bounce(*this);
184 void Yeti::take_hit(Player& )
186 if(safe_timer.started())
189 sound_manager->play("sounds/yeti_roar.wav");
192 if(hit_points <= 0) {
194 physic.enable_gravity(true);
195 physic.set_velocity_x(0);
196 physic.set_velocity_y(0);
199 state_timer.start(SQUISH_TIME);
200 set_group(COLGROUP_MOVING_ONLY_STATIC);
201 sprite->set_action("dead");
203 if (countMe) Sector::current()->get_level()->stats.badguys++;
205 if(dead_script != "") {
206 std::istringstream stream(dead_script);
207 Sector::current()->run_script(stream, "Yeti - dead-script");
211 safe_timer.start(SAFE_TIME);
218 // shooting bullets or being invincible won't work :)
219 take_hit(*get_nearest_player()); // FIXME: debug only(?)
223 Yeti::write(lisp::Writer& writer)
225 writer.start_list("yeti");
227 writer.write_float("x", start_position.x);
228 writer.write_float("y", start_position.y);
230 writer.end_list("yeti");
234 Yeti::drop_stalactite()
236 // make a stalactite falling down and shake camera a bit
237 Sector::current()->camera->shake(.1, 0, 10);
239 YetiStalactite* nearest = 0;
240 float dist = FLT_MAX;
242 Player* player = this->get_nearest_player();
245 Sector* sector = Sector::current();
246 for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
247 i != sector->gameobjects.end(); ++i) {
248 YetiStalactite* stalactite = dynamic_cast<YetiStalactite*> (*i);
249 if(stalactite && stalactite->is_hanging()) {
251 = fabsf(stalactite->get_pos().x - player->get_pos().x);
253 nearest = stalactite;
260 nearest->start_shaking();
264 Yeti::collision_solid(const CollisionHit& hit)
266 if(hit.top || hit.bottom) {
268 physic.set_velocity_y(0);
279 if(!state_timer.started()) {
280 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
284 // go to other side after 3 jumps
285 if(stomp_count == 3) {
289 state_timer.start(STOMP_WAIT);
296 } else if(hit.left || hit.right) {
302 IMPLEMENT_FACTORY(Yeti, "yeti")