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 = 3;
55 Yeti::Yeti(const lisp::Lisp& reader)
57 reader.get("x", start_position.x);
58 reader.get("y", start_position.y);
59 bbox.set_size(60, 90);
60 sprite = sprite_manager->create("images/creatures/yeti/yeti.sprite");
61 hit_points = INITIAL_HITPOINTS;
62 reader.get("dead-script", dead_script);
78 Yeti::draw(DrawingContext& context)
80 // we blink when we are safe
81 if(safe_timer.started() && size_t(game_time*40)%2)
84 BadGuy::draw(context);
88 Yeti::active_update(float elapsed_time)
92 physic.set_velocity_x((dir==RIGHT)?+JUMP_DOWN_VX:-JUMP_DOWN_VX);
95 physic.set_velocity_x((dir==RIGHT)?+RUN_VX:-RUN_VX);
96 if (((dir == RIGHT) && (get_pos().x >= RIGHT_JUMP_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_JUMP_X))) jump_up();
99 physic.set_velocity_x((dir==RIGHT)?+JUMP_UP_VX:-JUMP_UP_VX);
100 if (((dir == RIGHT) && (get_pos().x >= RIGHT_STAND_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_STAND_X))) be_angry();
103 if(state_timer.check()) {
104 sound_manager->play("sounds/yeti_gna.wav");
105 physic.set_velocity_y(STOMP_VY);
106 sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left");
110 if (state_timer.check()) {
116 movement = physic.get_movement(elapsed_time);
122 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
123 physic.set_velocity_x((dir==RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX));
124 physic.set_velocity_y(JUMP_DOWN_VY);
131 sprite->set_action((dir==RIGHT)?"run-right":"run-left");
132 physic.set_velocity_x((dir==RIGHT)?(+RUN_VX):(-RUN_VX));
133 physic.set_velocity_y(0);
140 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
141 physic.set_velocity_x((dir==RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX));
142 physic.set_velocity_y(JUMP_UP_VY);
150 dir = (dir==RIGHT)?LEFT:RIGHT;
152 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
153 physic.set_velocity_x(0);
154 physic.set_velocity_y(0);
155 if (hit_points < INITIAL_HITPOINTS) summon_snowball();
158 state_timer.start(STOMP_WAIT);
162 Yeti::summon_snowball()
164 Sector::current()->add_object(new BouncingSnowball(get_pos().x+(dir == RIGHT ? 64 : -64), get_pos().y, dir));
168 Yeti::collision_squished(Player& player)
170 kill_squished(player);
176 Yeti::kill_squished(Player& player)
178 player.bounce(*this);
182 void Yeti::take_hit(Player& player)
184 player.bounce(*this);
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++;
206 if(dead_script != "") {
207 std::istringstream stream(dead_script);
208 Sector::current()->run_script(stream, "Yeti - dead-script");
212 safe_timer.start(SAFE_TIME);
219 // shooting bullets or being invincible won't work :)
220 take_hit(*get_nearest_player()); // FIXME: debug only(?)
224 Yeti::write(lisp::Writer& writer)
226 writer.start_list("yeti");
228 writer.write_float("x", start_position.x);
229 writer.write_float("y", start_position.y);
231 if(dead_script != "") {
232 writer.write_string("dead-script", dead_script);
235 writer.end_list("yeti");
239 Yeti::drop_stalactite()
241 // make a stalactite falling down and shake camera a bit
242 Sector::current()->camera->shake(.1, 0, 10);
244 YetiStalactite* nearest = 0;
245 float dist = FLT_MAX;
247 Player* player = this->get_nearest_player();
250 Sector* sector = Sector::current();
251 for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
252 i != sector->gameobjects.end(); ++i) {
253 YetiStalactite* stalactite = dynamic_cast<YetiStalactite*> (*i);
254 if(stalactite && stalactite->is_hanging()) {
256 = fabsf(stalactite->get_pos().x - player->get_pos().x);
258 nearest = stalactite;
265 nearest->start_shaking();
269 Yeti::collision_solid(GameObject& , const CollisionHit& hit)
271 if(fabsf(hit.normal.y) > .5) {
273 physic.set_velocity_y(0);
284 if(!state_timer.started()) {
285 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
289 // go to other side after 3 jumps
290 if(stomp_count == 3) {
294 state_timer.start(STOMP_WAIT);
302 if(fabsf(hit.normal.x) > .5) {
310 IMPLEMENT_FACTORY(Yeti, "yeti")