X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbadguy%2Fwillowisp.cpp;h=6480c1675f9e3715c63393aac95486296534cb30;hb=6e7c8fafae2311b22c78b1ea597a408396873560;hp=00f0c748c535abe68a789b77856abb76a7627b58;hpb=37f90b08b22c730ef1cd699ceb603595b7b7a716;p=supertux.git diff --git a/src/badguy/willowisp.cpp b/src/badguy/willowisp.cpp index 00f0c748c..6480c1675 100644 --- a/src/badguy/willowisp.cpp +++ b/src/badguy/willowisp.cpp @@ -1,4 +1,4 @@ -// $Id: willowisp.cpp 3117 2006-03-25 17:19:54Z sommer $ +// $Id$ // // SuperTux - "Will-O-Wisp" Badguy // Copyright (C) 2006 Christoph Sommer @@ -20,29 +20,22 @@ #include #include "willowisp.hpp" -#include "msg.hpp" +#include "log.hpp" #include "game_session.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 */ static const float VANISH_RANGE = 512; /**< at what distance to stop tracking and vanish */ +static const std::string SOUNDFILE = "sounds/willowisp.wav"; WillOWisp::WillOWisp(const lisp::Lisp& reader) - : mystate(STATE_IDLE), target_sector("main"), target_spawnpoint("main"), soundSource(0) + : BadGuy(reader, "images/creatures/willowisp/willowisp.sprite", LAYER_FLOATINGOBJECTS), mystate(STATE_IDLE), target_sector("main"), target_spawnpoint("main") { - reader.get("x", start_position.x); - reader.get("y", start_position.y); reader.get("sector", target_sector); reader.get("spawnpoint", target_spawnpoint); - bbox.set_size(32, 32); - sprite = sprite_manager->create("images/creatures/willowisp/willowisp.sprite"); countMe = false; -} - -WillOWisp::~WillOWisp() -{ - delete soundSource; + sound_manager->preload(SOUNDFILE); } void @@ -59,6 +52,19 @@ WillOWisp::write(lisp::Writer& writer) } void +WillOWisp::draw(DrawingContext& context) +{ + sprite->draw(context, get_pos(), layer); + + context.push_target(); + context.set_target(DrawingContext::LIGHTMAP); + + sprite->draw(context, get_pos(), layer); + + context.pop_target(); +} + +void WillOWisp::active_update(float elapsed_time) { Player* player = get_nearest_player(); @@ -81,7 +87,7 @@ WillOWisp::active_update(float elapsed_time) mystate = STATE_VANISHING; sprite->set_action("vanishing", 1); } - soundSource->set_position(get_pos()); + sound_source->set_position(get_pos()); } if (mystate == STATE_WARPING) { @@ -103,24 +109,30 @@ WillOWisp::activate() { sprite->set_action("idle"); - delete soundSource; - soundSource = sound_manager->create_sound_source("sounds/rain.wav"); - if(!soundSource) { - msg_warning("Couldn't start WillOWisp sound"); - return; - } - soundSource->set_position(get_pos()); - soundSource->set_looping(true); - soundSource->set_gain(2.0); - soundSource->set_reference_distance(32); - soundSource->play(); + sound_source.reset(sound_manager->create_sound_source(SOUNDFILE)); + sound_source->set_position(get_pos()); + sound_source->set_looping(true); + sound_source->set_gain(2.0); + sound_source->set_reference_distance(32); + sound_source->play(); } void WillOWisp::deactivate() { - delete soundSource; - soundSource = 0; + sound_source.reset(NULL); + + switch (mystate) { + case STATE_IDLE: + break; + case STATE_TRACKING: + mystate = STATE_IDLE; + break; + case STATE_WARPING: + case STATE_VANISHING: + remove_me(); + break; + } } void