X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fwillowisp.cpp;h=db467e7f922d17c1c625b91a92376a5c00dfbbba;hb=788a9153f60fb3d25a52fd184387ebbde7636719;hp=cc50d6bcd796a8b3a0f1932e8e216947dce09e45;hpb=fea3446f05e1e7673607b835c269d3e8d1929ab3;p=supertux.git diff --git a/src/badguy/willowisp.cpp b/src/badguy/willowisp.cpp index cc50d6bcd..db467e7f9 100644 --- a/src/badguy/willowisp.cpp +++ b/src/badguy/willowisp.cpp @@ -20,11 +20,20 @@ #include #include "willowisp.hpp" + #include "log.hpp" #include "game_session.hpp" #include "object/lantern.hpp" #include "object/player.hpp" #include "scripting/squirrel_util.hpp" +#include "object/path.hpp" +#include "object/path_walker.hpp" +#include "audio/sound_source.hpp" +#include "lisp/writer.hpp" +#include "object_factory.hpp" +#include "audio/sound_manager.hpp" +#include "sector.hpp" +#include "sprite/sprite.hpp" static const float FLYSPEED = 64; /**< speed in px per second */ static const float TRACK_RANGE = 384; /**< at what distance to start tracking the player */ @@ -59,6 +68,9 @@ WillOWisp::WillOWisp(const lisp::Lisp& reader) countMe = false; sound_manager->preload(SOUNDFILE); + sound_manager->preload("sounds/warp.wav"); + + sprite->set_action("idle"); } void @@ -94,11 +106,14 @@ WillOWisp::active_update(float elapsed_time) break; case STATE_TRACKING: - if (dist.norm() <= vanish_range) { + if (dist.norm() > vanish_range) { + vanish(); + } else if (dist.norm() >= 1) { Vector dir = dist.unit(); movement = dir * elapsed_time * flyspeed; } else { - vanish(); + /* We somehow landed right on top of the player without colliding. + * Sit tight and avoid a division by zero. */ } sound_source->set_position(get_pos()); break; @@ -135,8 +150,6 @@ WillOWisp::active_update(float elapsed_time) void WillOWisp::activate() { - sprite->set_action("idle"); - sound_source.reset(sound_manager->create_sound_source(SOUNDFILE)); sound_source->set_position(get_pos()); sound_source->set_looping(true); @@ -171,7 +184,7 @@ WillOWisp::vanish() { mystate = STATE_VANISHING; sprite->set_action("vanishing", 1); - set_group(COLGROUP_DISABLED); + set_colgroup_active(COLGROUP_DISABLED); } bool @@ -250,7 +263,7 @@ WillOWisp::set_state(const std::string& new_state) } else { std::ostringstream msg; msg << "Can't set unknown willowisp state '" << new_state << "', should " - "be stopped, move_path, move_path_track or normal"; + "be stopped, move_path, move_path_track or normal"; throw new std::runtime_error(msg.str()); } }