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"
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 = 700; /**< 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+284; /**< x-coordinate of from where to jump on the left dais */
46 const float RIGHT_JUMP_X = RIGHT_STAND_X-284; /**< 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 */
52 Yeti::Yeti(const lisp::Lisp& reader)
54 reader.get("x", start_position.x);
55 reader.get("y", start_position.y);
56 bbox.set_size(60, 90);
57 sprite = sprite_manager->create("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(stomp_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");
108 movement = physic.get_movement(elapsed_time);
114 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
115 physic.set_velocity_x((dir==RIGHT)?(+JUMP_DOWN_VX):(-JUMP_DOWN_VX));
116 physic.set_velocity_y(JUMP_DOWN_VY);
123 sprite->set_action((dir==RIGHT)?"run-right":"run-left");
124 physic.set_velocity_x((dir==RIGHT)?(+RUN_VX):(-RUN_VX));
125 physic.set_velocity_y(0);
132 sprite->set_action((dir==RIGHT)?"jump-right":"jump-left");
133 physic.set_velocity_x((dir==RIGHT)?(+JUMP_UP_VX):(-JUMP_UP_VX));
134 physic.set_velocity_y(JUMP_UP_VY);
142 dir = (dir==RIGHT)?LEFT:RIGHT;
144 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
145 physic.set_velocity_x(0);
146 physic.set_velocity_y(0);
148 if (hit_points < INITIAL_HITPOINTS) summon_snowball();
150 stomp_timer.start(STOMP_WAIT);
154 Yeti::die(Player& player)
156 sprite->set_action("dead", 1);
157 kill_squished(player);
160 if(dead_script != "") {
161 std::istringstream stream(dead_script);
162 Sector::current()->run_script(stream, "Yeti - dead-script");
167 Yeti::summon_snowball()
169 Sector::current()->add_object(new BouncingSnowball(get_pos().x+(dir == RIGHT ? 64 : -64), get_pos().y, dir));
173 Yeti::collision_squished(Player& player)
175 if(safe_timer.started())
178 player.bounce(*this);
179 sound_manager->play("sounds/yeti_roar.wav");
181 if(hit_points <= 0) {
184 safe_timer.start(SAFE_TIME);
193 // shooting bullets or being invincible won't work :)
194 die(*get_nearest_player()); // FIXME: debug only
198 Yeti::write(lisp::Writer& writer)
200 writer.start_list("yeti");
202 writer.write_float("x", start_position.x);
203 writer.write_float("y", start_position.y);
205 if(dead_script != "") {
206 writer.write_string("dead-script", dead_script);
209 writer.end_list("yeti");
213 Yeti::drop_stalactite()
215 // make a stalactite falling down and shake camera a bit
216 Sector::current()->camera->shake(.1, 0, 10);
218 YetiStalactite* nearest = 0;
219 float dist = FLT_MAX;
221 Player* player = this->get_nearest_player();
224 Sector* sector = Sector::current();
225 for(Sector::GameObjects::iterator i = sector->gameobjects.begin();
226 i != sector->gameobjects.end(); ++i) {
227 YetiStalactite* stalactite = dynamic_cast<YetiStalactite*> (*i);
228 if(stalactite && stalactite->is_hanging()) {
230 = fabsf(stalactite->get_pos().x - player->get_pos().x);
232 nearest = stalactite;
239 nearest->start_shaking();
243 Yeti::collision_solid(GameObject& , const CollisionHit& hit)
245 if(fabsf(hit.normal.y) > .5) {
247 physic.set_velocity_y(0);
258 if(!stomp_timer.started()) {
259 sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
263 // go to other side after 3 jumps
264 if(stomp_count == 3) {
268 stomp_timer.start(STOMP_WAIT);
274 if(fabsf(hit.normal.x) > .5) {
282 IMPLEMENT_FACTORY(Yeti, "yeti")