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;
59 reader.get("dead-script", dead_script);
75 Yeti::draw(DrawingContext& context)
77 // we blink when we are safe
78 if(safe_timer.started() && size_t(game_time*40)%2)
81 BadGuy::draw(context);
85 Yeti::active_update(float elapsed_time)
89 physic.set_velocity_x((dir==RIGHT)?+JUMP_DOWN_VX:-JUMP_DOWN_VX);
92 physic.set_velocity_x((dir==RIGHT)?+RUN_VX:-RUN_VX);
93 if (((dir == RIGHT) && (get_pos().x >= RIGHT_JUMP_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_JUMP_X))) jump_up();
96 physic.set_velocity_x((dir==RIGHT)?+JUMP_UP_VX:-JUMP_UP_VX);
97 if (((dir == RIGHT) && (get_pos().x >= RIGHT_STAND_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_STAND_X))) be_angry();
100 if(state_timer.check()) {
101 sound_manager->play("sounds/yeti_gna.wav");
102 physic.set_velocity_y(STOMP_VY);
103 sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left");
107 if (state_timer.check()) {
113 movement = physic.get_movement(elapsed_time);
119 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
120 physic.set_velocity_x((dir==RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX));
121 physic.set_velocity_y(JUMP_DOWN_VY);
128 sprite->set_action((dir==RIGHT)?"run-right":"run-left");
129 physic.set_velocity_x((dir==RIGHT)?(+RUN_VX):(-RUN_VX));
130 physic.set_velocity_y(0);
137 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
138 physic.set_velocity_x((dir==RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX));
139 physic.set_velocity_y(JUMP_UP_VY);
147 dir = (dir==RIGHT)?LEFT:RIGHT;
149 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
150 physic.set_velocity_x(0);
151 physic.set_velocity_y(0);
152 if (hit_points < INITIAL_HITPOINTS) summon_snowball();
155 state_timer.start(STOMP_WAIT);
159 Yeti::summon_snowball()
161 Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x+(dir == RIGHT ? 64 : -64), get_pos().y), dir));
165 Yeti::collision_squished(Player& player)
167 kill_squished(player);
173 Yeti::kill_squished(Player& player)
175 player.bounce(*this);
179 void Yeti::take_hit(Player& )
181 if(safe_timer.started())
184 sound_manager->play("sounds/yeti_roar.wav");
187 if(hit_points <= 0) {
189 physic.enable_gravity(true);
190 physic.set_velocity_x(0);
191 physic.set_velocity_y(0);
194 state_timer.start(SQUISH_TIME);
195 set_group(COLGROUP_MOVING_ONLY_STATIC);
196 sprite->set_action("dead");
198 if (countMe) Sector::current()->get_level()->stats.badguys++;
201 if(dead_script != "") {
202 std::istringstream stream(dead_script);
203 Sector::current()->run_script(stream, "Yeti - dead-script");
207 safe_timer.start(SAFE_TIME);
214 // shooting bullets or being invincible won't work :)
215 take_hit(*get_nearest_player()); // FIXME: debug only(?)
219 Yeti::write(lisp::Writer& writer)
221 writer.start_list("yeti");
223 writer.write_float("x", start_position.x);
224 writer.write_float("y", start_position.y);
226 if(dead_script != "") {
227 writer.write_string("dead-script", dead_script);
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(GameObject& , const CollisionHit& hit)
266 if(fabsf(hit.normal.y) > .5) {
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);
297 if(fabsf(hit.normal.x) > .5) {
305 IMPLEMENT_FACTORY(Yeti, "yeti")