3 // SuperTux - "Will-O-Wisp" Badguy
4 // Copyright (C) 2007 Matthias Braun
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #include "treewillowisp.hpp"
23 #include "ghosttree.hpp"
24 #include "object/lantern.hpp"
26 static const std::string SOUNDFILE = "sounds/willowisp.wav";
27 static const float SUCKSPEED = 25;
29 TreeWillOWisp::TreeWillOWisp(GhostTree* tree, const Vector& pos,
30 float radius, float speed)
31 : BadGuy(Vector(0, 0), "images/creatures/willowisp/willowisp.sprite",
32 LAYER_OBJECTS - 20), mystate(STATE_DEFAULT), tree(tree)
35 sound_manager->preload(SOUNDFILE);
37 this->radius = radius;
40 start_position = tree->get_pos() + treepos_delta;
43 TreeWillOWisp::~TreeWillOWisp()
48 TreeWillOWisp::activate()
50 sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
51 sound_source->set_position(get_pos());
52 sound_source->set_looping(true);
53 sound_source->set_gain(2.0);
54 sound_source->set_reference_distance(32);
57 set_group(COLGROUP_MOVING);
61 TreeWillOWisp::vanish()
63 mystate = STATE_VANISHING;
64 sprite->set_action("vanishing", 1);
65 set_group(COLGROUP_DISABLED);
69 TreeWillOWisp::start_sucking()
71 mystate = STATE_SUCKED;
75 TreeWillOWisp::collision_player(Player& player, const CollisionHit& hit)
77 //TODO: basically a no-op. Remove if this doesn't change.
78 return BadGuy::collision_player(player, hit);
82 TreeWillOWisp::collides(GameObject& other, const CollisionHit& ) {
83 Lantern* lantern = dynamic_cast<Lantern*>(&other);
84 if (lantern && lantern->is_open())
86 if (dynamic_cast<Player*>(&other))
93 TreeWillOWisp::active_update(float elapsed_time)
95 // remove TreeWillOWisp if it has completely vanished
96 if (mystate == STATE_VANISHING) {
97 if(sprite->animation_done()) {
99 tree->willowisp_died(this);
104 if (mystate == STATE_SUCKED) {
105 Vector dir = tree->get_bbox().get_middle() - get_pos();
110 Vector newpos = get_pos() + dir * elapsed_time;
111 movement = newpos - get_pos();
115 angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
116 Vector newpos(tree->get_pos() + treepos_delta + Vector(sin(angle) * radius, 0));
117 movement = newpos - get_pos();
118 float sizemod = cos(angle) * 0.8f;
119 /* TODO: modify sprite size */
121 sound_source->set_position(get_pos());
124 layer = LAYER_OBJECTS + 5;
126 layer = LAYER_OBJECTS - 20;
131 TreeWillOWisp::set_color(const Color& color)
134 sprite->set_color(color);
138 TreeWillOWisp::get_color() const