-// $Id$
-//
// SuperTux - "Will-O-Wisp" Badguy
// Copyright (C) 2007 Matthias Braun
//
-// This program is free software; you can redistribute it and/or
-// modify it under the terms of the GNU General Public License
-// as published by the Free Software Foundation; either version 2
-// of the License, or (at your option) any later version.
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// 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
-// 02111-1307, USA.
-#include <config.h>
-
-#include "treewillowisp.hpp"
-#include "object/lantern.hpp"
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
-static const std::string SOUNDFILE = "sounds/willowisp.wav";
+#include "badguy/treewillowisp.hpp"
-TreeWillOWisp::TreeWillOWisp(const Vector& pos, float radius, float speed)
- : BadGuy(pos, "images/creatures/willowisp/willowisp.sprite",
- LAYER_OBJECTS - 20), mystate(STATE_DEFAULT)
+#include "audio/sound_manager.hpp"
+#include "audio/sound_source.hpp"
+#include "badguy/ghosttree.hpp"
+#include "object/lantern.hpp"
+#include "object/player.hpp"
+#include "sprite/sprite.hpp"
+
+#include <math.h>
+
+static const std::string TREEWILLOSOUND = "sounds/willowisp.wav";
+
+TreeWillOWisp::TreeWillOWisp(GhostTree* tree_, const Vector& pos,
+ float radius_, float speed_) :
+ BadGuy(tree_->get_pos() + pos, "images/creatures/willowisp/willowisp.sprite",
+ LAYER_OBJECTS - 20),
+ was_sucked(false),
+ mystate(STATE_DEFAULT),
+ color(),
+ angle(),
+ radius(),
+ speed(),
+ sound_source(),
+ tree(tree_),
+ suck_target()
{
- sound_manager->preload(SOUNDFILE);
+ SoundManager::current()->preload(TREEWILLOSOUND);
- this->radius = radius;
+ this->radius = radius_;
this->angle = 0;
- this->speed = speed;
+ this->speed = speed_;
+
+ set_colgroup_active(COLGROUP_MOVING);
}
TreeWillOWisp::~TreeWillOWisp()
void
TreeWillOWisp::activate()
{
- sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
+ sound_source = SoundManager::current()->create_sound_source(TREEWILLOSOUND);
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();
-
- set_group(COLGROUP_MOVING);
}
void
{
mystate = STATE_VANISHING;
sprite->set_action("vanishing", 1);
- set_group(COLGROUP_DISABLED);
+ set_colgroup_active(COLGROUP_DISABLED);
+}
+
+void
+TreeWillOWisp::start_sucking(Vector suck_target_)
+{
+ mystate = STATE_SUCKED;
+ this->suck_target = suck_target_;
+ was_sucked = true;
}
HitResponse
TreeWillOWisp::collision_player(Player& player, const CollisionHit& hit)
{
- (void) player;
- (void) hit;
-
- return FORCE_MOVE;
+ //TODO: basically a no-op. Remove if this doesn't change.
+ return BadGuy::collision_player(player, hit);
}
bool
TreeWillOWisp::collides(GameObject& other, const CollisionHit& ) {
- if (dynamic_cast<Lantern*>(&other)) return true;
+ Lantern* lantern = dynamic_cast<Lantern*>(&other);
+ if (lantern && lantern->is_open())
+ return true;
+ if (dynamic_cast<Player*>(&other))
+ return true;
+
return false;
}
void
-TreeWillOWisp::active_update(float elapsed_time)
+TreeWillOWisp::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
+TreeWillOWisp::active_update(float elapsed_time)
+{
// remove TreeWillOWisp if it has completely vanished
if (mystate == STATE_VANISHING) {
if(sprite->animation_done()) {
remove_me();
+ tree->willowisp_died(this);
+ }
+ return;
+ }
+
+ if (mystate == STATE_SUCKED) {
+ Vector dir_ = suck_target - get_pos();
+ if(dir_.norm() < 5) {
+ vanish();
return;
}
+ Vector newpos = get_pos() + dir_ * elapsed_time;
+ movement = newpos - get_pos();
+ return;
}
angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
- Vector newpos(start_position.x + sin(angle) * radius, start_position.y);
+ Vector newpos(start_position + Vector(sin(angle) * radius, 0));
movement = newpos - get_pos();
float sizemod = cos(angle) * 0.8f;
/* TODO: modify sprite size */
}
void
-TreeWillOWisp::set_color(const Color& color)
+TreeWillOWisp::set_color(const Color& color_)
{
- this->color = color;
- sprite->set_color(color);
+ this->color = color_;
+ sprite->set_color(color_);
}
Color
return color;
}
+/* EOF */