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 "object/lantern.hpp"
25 static const std::string SOUNDFILE = "sounds/willowisp.wav";
27 TreeWillOWisp::TreeWillOWisp(const Vector& pos, float radius, float speed)
28 : BadGuy(pos, "images/creatures/willowisp/willowisp.sprite",
29 LAYER_OBJECTS - 20), mystate(STATE_DEFAULT)
31 sound_manager->preload(SOUNDFILE);
33 this->radius = radius;
38 TreeWillOWisp::~TreeWillOWisp()
43 TreeWillOWisp::activate()
45 sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
46 sound_source->set_position(get_pos());
47 sound_source->set_looping(true);
48 sound_source->set_gain(2.0);
49 sound_source->set_reference_distance(32);
52 set_group(COLGROUP_MOVING);
56 TreeWillOWisp::vanish()
58 mystate = STATE_VANISHING;
59 sprite->set_action("vanishing", 1);
60 set_group(COLGROUP_DISABLED);
64 TreeWillOWisp::collision_player(Player& player, const CollisionHit& hit)
66 //TODO: basically a no-op. Remove if this doesn't change.
67 return BadGuy::collision_player(player, hit);
71 TreeWillOWisp::collides(GameObject& other, const CollisionHit& ) {
72 Lantern* lantern = dynamic_cast<Lantern*>(&other);
73 if (lantern && lantern->is_open()) return true;
74 if (dynamic_cast<Player*>(&other)) return true;
79 TreeWillOWisp::active_update(float elapsed_time)
82 // remove TreeWillOWisp if it has completely vanished
83 if (mystate == STATE_VANISHING) {
84 if(sprite->animation_done()) {
90 angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
91 Vector newpos(start_position.x + sin(angle) * radius, start_position.y);
92 movement = newpos - get_pos();
93 float sizemod = cos(angle) * 0.8f;
94 /* TODO: modify sprite size */
96 sound_source->set_position(get_pos());
99 layer = LAYER_OBJECTS + 5;
101 layer = LAYER_OBJECTS - 20;
106 TreeWillOWisp::set_color(const Color& color)
109 sprite->set_color(color);
113 TreeWillOWisp::get_color() const