X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fyeti.cpp;h=1c039068e459d39655fe99e5509964d354e5e3dd;hb=013a5ca196545a094f27c1b708facd0084d58d55;hp=adb6344b24ec7a6368511cd5e2f05aa71e2247cc;hpb=1a22fd2f500ae137ec81f83eac2d74aa06be8cb1;p=supertux.git diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index adb6344b2..1c039068e 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -1,5 +1,5 @@ // $Id$ -// +// // SuperTux - Boss "Yeti" // Copyright (C) 2005 Matthias Braun // Copyright (C) 2006 Christoph Sommer @@ -13,7 +13,7 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA @@ -28,36 +28,38 @@ #include "yeti_stalactite.hpp" #include "bouncing_snowball.hpp" #include "game_session.hpp" +#include "level.hpp" namespace { const float JUMP_DOWN_VX = 250; /**< horizontal speed while jumping off the dais */ - const float JUMP_DOWN_VY = 250; /**< vertical speed while jumping off the dais */ + const float JUMP_DOWN_VY = -250; /**< vertical speed while jumping off the dais */ const float RUN_VX = 350; /**< horizontal speed while running */ const float JUMP_UP_VX = 350; /**< horizontal speed while jumping on the dais */ - const float JUMP_UP_VY = 700; /**< vertical speed while jumping on the dais */ + const float JUMP_UP_VY = -800; /**< vertical speed while jumping on the dais */ - const float STOMP_VY = 250; /** vertical speed while stomping on the dais */ + const float STOMP_VY = -250; /** vertical speed while stomping on the dais */ const float LEFT_STAND_X = 16; /**< x-coordinate of left dais' end position */ - const float RIGHT_STAND_X = 800-60-16; /**< x-coordinate of right dais' end position */ - const float LEFT_JUMP_X = LEFT_STAND_X+284; /**< x-coordinate of from where to jump on the left dais */ - const float RIGHT_JUMP_X = RIGHT_STAND_X-284; /**< x-coordinate of from where to jump on the right dais */ + const float RIGHT_STAND_X = 800-60-16; /**< x-coordinate of right dais' end position */ + const float LEFT_JUMP_X = LEFT_STAND_X+224; /**< x-coordinate of from where to jump on the left dais */ + const float RIGHT_JUMP_X = RIGHT_STAND_X-224; /**< x-coordinate of from where to jump on the right dais */ const float STOMP_WAIT = .5; /**< time we stay on the dais before jumping again */ const float SAFE_TIME = .5; /**< the time we are safe when tux just hit us */ const int INITIAL_HITPOINTS = 3; /**< number of hits we can take */ + + const float SQUISH_TIME = 5; } Yeti::Yeti(const lisp::Lisp& reader) + : BadGuy(reader, "images/creatures/yeti/yeti.sprite") { - reader.get("x", start_position.x); - reader.get("y", start_position.y); - bbox.set_size(60, 90); - sprite = sprite_manager->create("images/creatures/yeti/yeti.sprite"); hit_points = INITIAL_HITPOINTS; - reader.get("dead-script", dead_script); countMe = false; + sound_manager->preload("sounds/yeti_gna.wav"); + sound_manager->preload("sounds/yeti_roar.wav"); + hud_head.reset(new Surface("images/creatures/yeti/hudlife.png")); } Yeti::~Yeti() @@ -65,7 +67,7 @@ Yeti::~Yeti() } void -Yeti::activate() +Yeti::initialize() { dir = RIGHT; jump_down(); @@ -78,10 +80,32 @@ Yeti::draw(DrawingContext& context) if(safe_timer.started() && size_t(game_time*40)%2) return; + draw_hit_points(context); + BadGuy::draw(context); } void +Yeti::draw_hit_points(DrawingContext& context) +{ + int i; + + Surface *hh = hud_head.get(); + if (!hh) + return; + + context.push_transform(); + context.set_translation(Vector(0, 0)); + + for (i = 0; i < hit_points; ++i) + { + context.draw_surface(hh, Vector(BORDER_X + (i * hh->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1); + } + + context.pop_transform(); +} + +void Yeti::active_update(float elapsed_time) { switch(state) { @@ -97,12 +121,17 @@ Yeti::active_update(float elapsed_time) if (((dir == RIGHT) && (get_pos().x >= RIGHT_STAND_X)) || ((dir == LEFT) && (get_pos().x <= LEFT_STAND_X))) be_angry(); break; case BE_ANGRY: - if(stomp_timer.check()) { + if(state_timer.check()) { sound_manager->play("sounds/yeti_gna.wav"); physic.set_velocity_y(STOMP_VY); sprite->set_action((dir==RIGHT)?"stomp-right":"stomp-left"); } break; + case SQUISHED: + if (state_timer.check()) { + remove_me(); + } + break; } movement = physic.get_movement(elapsed_time); @@ -144,54 +173,72 @@ Yeti::be_angry() sprite->set_action((dir==RIGHT)?"stand-right":"stand-left"); physic.set_velocity_x(0); physic.set_velocity_y(0); - state = BE_ANGRY; if (hit_points < INITIAL_HITPOINTS) summon_snowball(); stomp_count = 0; - stomp_timer.start(STOMP_WAIT); + state = BE_ANGRY; + state_timer.start(STOMP_WAIT); } void -Yeti::die(Player& player) +Yeti::summon_snowball() { - sprite->set_action("dead", 1); - kill_squished(player); + Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x+(dir == RIGHT ? 64 : -64), get_pos().y), dir)); +} - // start script - if(dead_script != "") { - std::istringstream stream(dead_script); - Sector::current()->run_script(stream, "Yeti - dead-script"); - } +bool +Yeti::collision_squished(GameObject& object) +{ + kill_squished(object); + + return true; } void -Yeti::summon_snowball() +Yeti::kill_squished(GameObject& object) { - Sector::current()->add_object(new BouncingSnowball(get_pos().x+(dir == RIGHT ? 64 : -64), get_pos().y, dir)); + Player* player = dynamic_cast(&object); + if (player) { + player->bounce(*this); + take_hit(*player); + } } -bool -Yeti::collision_squished(Player& player) +void Yeti::take_hit(Player& ) { if(safe_timer.started()) - return true; + return; - player.bounce(*this); sound_manager->play("sounds/yeti_roar.wav"); hit_points--; + if(hit_points <= 0) { - die(player); - } else { + // We're dead + physic.enable_gravity(true); + physic.set_velocity_x(0); + physic.set_velocity_y(0); + + state = SQUISHED; + state_timer.start(SQUISH_TIME); + set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC); + sprite->set_action("dead"); + + if (countMe) Sector::current()->get_level()->stats.badguys++; + + if(dead_script != "") { + std::istringstream stream(dead_script); + Sector::current()->run_script(stream, "Yeti - dead-script"); + } + } + else { safe_timer.start(SAFE_TIME); } - - return true; } void Yeti::kill_fall() { // shooting bullets or being invincible won't work :) - die(*get_nearest_player()); // FIXME: debug only + //take_hit(*get_nearest_player()); // FIXME: debug only(?) } void @@ -202,10 +249,6 @@ Yeti::write(lisp::Writer& writer) writer.write_float("x", start_position.x); writer.write_float("y", start_position.y); - if(dead_script != "") { - writer.write_string("dead-script", dead_script); - } - writer.end_list("yeti"); } @@ -213,7 +256,7 @@ void Yeti::drop_stalactite() { // make a stalactite falling down and shake camera a bit - Sector::current()->camera->shake(.1, 0, 10); + Sector::current()->camera->shake(.1f, 0, 10); YetiStalactite* nearest = 0; float dist = FLT_MAX; @@ -226,7 +269,7 @@ Yeti::drop_stalactite() i != sector->gameobjects.end(); ++i) { YetiStalactite* stalactite = dynamic_cast (*i); if(stalactite && stalactite->is_hanging()) { - float sdist + float sdist = fabsf(stalactite->get_pos().x - player->get_pos().x); if(sdist < dist) { nearest = stalactite; @@ -239,10 +282,10 @@ Yeti::drop_stalactite() nearest->start_shaking(); } -HitResponse -Yeti::collision_solid(GameObject& , const CollisionHit& hit) +void +Yeti::collision_solid(const CollisionHit& hit) { - if(fabsf(hit.normal.y) > .5) { + if(hit.top || hit.bottom) { // hit floor or roof physic.set_velocity_y(0); switch (state) { @@ -255,7 +298,7 @@ Yeti::collision_solid(GameObject& , const CollisionHit& hit) break; case BE_ANGRY: // we just landed - if(!stomp_timer.started()) { + if(!state_timer.started()) { sprite->set_action((dir==RIGHT)?"stand-right":"stand-left"); stomp_count++; drop_stalactite(); @@ -265,18 +308,17 @@ Yeti::collision_solid(GameObject& , const CollisionHit& hit) jump_down(); } else { // jump again - stomp_timer.start(STOMP_WAIT); + state_timer.start(STOMP_WAIT); } } break; + case SQUISHED: + break; } - } else - if(fabsf(hit.normal.x) > .5) { + } else if(hit.left || hit.right) { // hit wall jump_up(); } - - return CONTINUE; } IMPLEMENT_FACTORY(Yeti, "yeti")