src/badguy/flame.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "badguy/flame.hpp"
00018 
00019 #include <math.h>
00020 
00021 #include "audio/sound_manager.hpp"
00022 #include "supertux/object_factory.hpp"
00023 #include "util/reader.hpp"
00024 
00025 static const std::string FLAME_SOUND = "sounds/flame.wav";
00026 
00027 Flame::Flame(const Reader& reader) :
00028   BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS), 
00029   angle(0), 
00030   radius(100), 
00031   speed(2),
00032   sound_source()
00033 {
00034   reader.get("radius", radius);
00035   reader.get("speed", speed);
00036   bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
00037                       start_position.y + sin(angle) * radius));
00038   countMe = false;
00039   sound_manager->preload(FLAME_SOUND);
00040 
00041   set_colgroup_active(COLGROUP_TOUCHABLE);
00042 }
00043 
00044 void
00045 Flame::active_update(float elapsed_time)
00046 {
00047   angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
00048   Vector newpos(start_position.x + cos(angle) * radius,
00049                 start_position.y + sin(angle) * radius);
00050   movement = newpos - get_pos();
00051 
00052   sound_source->set_position(get_pos());
00053 }
00054 
00055 void
00056 Flame::activate()
00057 {
00058   sound_source.reset(sound_manager->create_sound_source(FLAME_SOUND));
00059   sound_source->set_position(get_pos());
00060   sound_source->set_looping(true);
00061   sound_source->set_gain(2.0);
00062   sound_source->set_reference_distance(32);
00063   sound_source->play();
00064 }
00065 
00066 void
00067 Flame::deactivate()
00068 {
00069   sound_source.reset();
00070 }
00071 
00072 void
00073 Flame::kill_fall()
00074 {
00075 }
00076 
00077 /* EOF */

Generated on Mon Jun 9 03:38:17 2014 for SuperTux by  doxygen 1.5.1