X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fyeti.cpp;h=10a33e0768bd02dfd8b6eff7f0752e7c4c8e567c;hb=5c14f6f384eff76491d494b4c157abf2ff776d49;hp=327927544579b511427206a9130d630b1c314db0;hpb=c0093d25093395cb62fc2526ab42be65a9f015b8;p=supertux.git diff --git a/src/badguy/yeti.cpp b/src/badguy/yeti.cpp index 327927544..10a33e076 100644 --- a/src/badguy/yeti.cpp +++ b/src/badguy/yeti.cpp @@ -17,44 +17,61 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA // 02111-1307, USA. - #include #include -#include "yeti.h" -#include "object/camera.h" -#include "yeti_stalactite.h" -#include "bouncing_snowball.h" +#include +#include +#include "yeti.hpp" +#include "object/camera.hpp" +#include "yeti_stalactite.hpp" +#include "bouncing_snowball.hpp" +#include "game_session.hpp" +#include "scripting/script_interpreter.hpp" static const float JUMP_VEL1 = 250; static const float JUMP_VEL2 = 700; static const float RUN_SPEED = 350; static const float JUMP_TIME = 1.6; static const float ANGRY_JUMP_WAIT = .5; +/// the time we are safe when tux just hit us +static const float SAFE_TIME = .5; static const int INITIAL_HITPOINTS = 3; -static const int INITIAL_BULLET_HP = 10; Yeti::Yeti(const lisp::Lisp& reader) { reader.get("x", start_position.x); reader.get("y", start_position.y); bbox.set_size(80, 120); - sprite = sprite_manager->create("yeti"); + sprite = sprite_manager->create("images/creatures/yeti/yeti.sprite"); + sprite->set_action("right"); state = INIT; side = LEFT; - hitpoints = INITIAL_HITPOINTS; - bullet_hitpoints = INITIAL_BULLET_HP; +#if 0 sound_manager->preload_sound("yeti_gna"); - sound_manager->preload_sound("yeti_roar"); + sound_manager->preload_sound("yeti_roar"); +#endif + hit_points = INITIAL_HITPOINTS; + reader.get("dead-script", dead_script); + countMe = false; } Yeti::~Yeti() { - Mix_FreeChunk(sound_gna); } void -Yeti::active_action(float elapsed_time) +Yeti::draw(DrawingContext& context) +{ + // we blink when we are safe + if(safe_timer.started() && size_t(game_time*40)%2) + return; + + BadGuy::draw(context); +} + +void +Yeti::active_update(float elapsed_time) { switch(state) { case INIT: @@ -72,8 +89,12 @@ Yeti::active_action(float elapsed_time) case ANGRY_JUMPING: if(timer.check()) { // jump - sound_manager->play_sound("yeti_gna"); + sound_manager->play("sounds/yeti_gna.wav"); physic.set_velocity_y(JUMP_VEL1); + if (side == LEFT) // on the left, facing Tux who is on the right + sprite->set_action("jump-right"); + else + sprite->set_action("jump-left"); } break; default: @@ -87,6 +108,7 @@ void Yeti::go_right() { // jump and move right + sprite->set_action("right"); physic.set_velocity_y(JUMP_VEL1); physic.set_velocity_x(RUN_SPEED); state = GO_RIGHT; @@ -96,6 +118,7 @@ Yeti::go_right() void Yeti::go_left() { + sprite->set_action("left"); physic.set_velocity_y(JUMP_VEL1); physic.set_velocity_x(-RUN_SPEED); state = GO_LEFT; @@ -117,46 +140,50 @@ Yeti::summon_snowball() Sector::current()->add_object(new BouncingSnowball(get_pos().x+(side == LEFT ? 64 : -64), get_pos().y, (side == LEFT ? RIGHT : LEFT))); } -HitResponse -Yeti::collision_player(Player& player, const CollisionHit& hit) -{ - if(player.is_invincible()) { - kill_fall(); - return ABORT_MOVE; - } - if(hit.normal.y > .9) { - hitpoints--; - bullet_hitpoints--; - sound_manager->play_sound("yeti_roar"); - if(collision_squished(player)) - return ABORT_MOVE; - else if (hitpoints <= 0) { - bullet_hitpoints = 0; - player.kill(Player::SHRINK); - return FORCE_MOVE; - } - } - player.kill(Player::SHRINK); - return FORCE_MOVE; -} - bool Yeti::collision_squished(Player& player) { - bool result = false; + if(safe_timer.started()) + return true; + player.bounce(*this); - if (hitpoints <= 0) { - bullet_hitpoints = 0; - //sprite->set_action("dead"); + sound_manager->play("sounds/yeti_roar.wav"); + hit_points--; + if(hit_points <= 0) { + sprite->set_action("dead"); kill_squished(player); - result = true; + + // start script + if(dead_script != "") { + ScriptInterpreter::add_script_object(Sector::current(), + "Yeti - dead-script", dead_script); + } + } else { + safe_timer.start(SAFE_TIME); } - return result; + + return true; } void -Yeti::write(lisp::Writer& ) +Yeti::kill_fall() +{ + // shooting bullets or being invincible won't work :) +} + +void +Yeti::write(lisp::Writer& writer) { + writer.start_list("yeti"); + + 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"); } void @@ -193,14 +220,20 @@ Yeti::collision_solid(GameObject& , const CollisionHit& hit) } else if(state == GO_LEFT && !timer.started()) { side = LEFT; summon_snowball(); + sprite->set_action("stand-right"); angry_jumping(); } else if(state == GO_RIGHT && !timer.started()) { side = RIGHT; summon_snowball(); + sprite->set_action("stand-left"); angry_jumping(); } else if(state == ANGRY_JUMPING) { if(!timer.started()) { // we just landed + if (side == LEFT) // standing on the left, facing Tux who is on the right + sprite->set_action("stand-right"); + else + sprite->set_action("stand-left"); jumpcount++; // make a stalactite falling down and shake camera a bit Sector::current()->camera->shake(.1, 0, 10); @@ -223,19 +256,4 @@ Yeti::collision_solid(GameObject& , const CollisionHit& hit) return CONTINUE; } -void -Yeti::kill_fall() -{ - sound_manager->play_sound("yeti_roar"); - bullet_hitpoints--; - if (bullet_hitpoints <= 0) { - sound_manager->play_sound("fall", this, - Sector::current()->player->get_pos()); - physic.set_velocity_y(0); - physic.enable_gravity(true); - set_state(STATE_FALLING); - } - std::cout << "KILL_FALL - HITPOINTS: " << hitpoints << ", BULLET HP: " << bullet_hitpoints << std::endl; -} - IMPLEMENT_FACTORY(Yeti, "yeti")