src/badguy/dart.cpp

Go to the documentation of this file.
00001 //  Dart - Your average poison dart
00002 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.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/dart.hpp"
00018 
00019 #include "audio/sound_manager.hpp"
00020 #include "audio/sound_source.hpp"
00021 #include "sprite/sprite.hpp"
00022 #include "supertux/object_factory.hpp"
00023 
00024 namespace {
00025 const float DART_SPEED = 200;
00026 }
00027 
00028 static const std::string DART_SOUND = "sounds/flame.wav";
00029 
00030 Dart::Dart(const Reader& reader) :
00031   BadGuy(reader, "images/creatures/dart/dart.sprite"), 
00032   parent(0),
00033   sound_source()
00034 {
00035   physic.enable_gravity(false);
00036   countMe = false;
00037   sound_manager->preload(DART_SOUND);
00038   sound_manager->preload("sounds/darthit.wav");
00039   sound_manager->preload("sounds/stomp.wav");
00040 }
00041 
00042 Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0) :
00043   BadGuy(pos, d, "images/creatures/dart/dart.sprite"), 
00044   parent(parent),
00045   sound_source()
00046 {
00047   physic.enable_gravity(false);
00048   countMe = false;
00049   sound_manager->preload(DART_SOUND);
00050   sound_manager->preload("sounds/darthit.wav");
00051   sound_manager->preload("sounds/stomp.wav");
00052 }
00053 
00054 Dart::~Dart()
00055 {
00056 }
00057 
00058 bool
00059 Dart::updatePointers(const GameObject* from_object, GameObject* to_object)
00060 {
00061   if (from_object == parent) {
00062     parent = dynamic_cast<Dart*>(to_object);
00063     return true;
00064   }
00065   return false;
00066 }
00067 
00068 void
00069 Dart::initialize()
00070 {
00071   physic.set_velocity_x(dir == LEFT ? -::DART_SPEED : ::DART_SPEED);
00072   sprite->set_action(dir == LEFT ? "flying-left" : "flying-right");
00073 }
00074 
00075 void
00076 Dart::activate()
00077 {
00078   sound_source.reset(sound_manager->create_sound_source(DART_SOUND));
00079   sound_source->set_position(get_pos());
00080   sound_source->set_looping(true);
00081   sound_source->set_gain(1.0);
00082   sound_source->set_reference_distance(32);
00083   sound_source->play();
00084 }
00085 
00086 void
00087 Dart::deactivate()
00088 {
00089   sound_source.reset();
00090   remove_me();
00091 }
00092 
00093 void
00094 Dart::active_update(float elapsed_time)
00095 {
00096   BadGuy::active_update(elapsed_time);
00097   sound_source->set_position(get_pos());
00098 }
00099 
00100 void
00101 Dart::collision_solid(const CollisionHit& )
00102 {
00103   sound_manager->play("sounds/darthit.wav", get_pos());
00104   remove_me();
00105 }
00106 
00107 HitResponse
00108 Dart::collision_badguy(BadGuy& badguy, const CollisionHit& )
00109 {
00110   // ignore collisions with parent
00111   if (&badguy == parent) {
00112     return FORCE_MOVE;
00113   }
00114   sound_manager->play("sounds/stomp.wav", get_pos());
00115   remove_me();
00116   badguy.kill_fall();
00117   return ABORT_MOVE;
00118 }
00119 
00120 HitResponse
00121 Dart::collision_player(Player& player, const CollisionHit& hit)
00122 {
00123   sound_manager->play("sounds/stomp.wav", get_pos());
00124   remove_me();
00125   return BadGuy::collision_player(player, hit);
00126 }
00127 
00128 /* EOF */

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