1 // Dart - Your average poison dart
2 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "badguy/dart.hpp"
19 #include "audio/sound_manager.hpp"
20 #include "audio/sound_source.hpp"
21 #include "sprite/sprite.hpp"
22 #include "supertux/object_factory.hpp"
25 const float SPEED = 200;
28 static const std::string SOUNDFILE = "sounds/flame.wav";
30 Dart::Dart(const Reader& reader) :
31 BadGuy(reader, "images/creatures/dart/dart.sprite"),
35 physic.enable_gravity(false);
37 sound_manager->preload(SOUNDFILE);
38 sound_manager->preload("sounds/darthit.wav");
39 sound_manager->preload("sounds/stomp.wav");
42 Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0) :
43 BadGuy(pos, d, "images/creatures/dart/dart.sprite"),
47 physic.enable_gravity(false);
49 sound_manager->preload(SOUNDFILE);
50 sound_manager->preload("sounds/darthit.wav");
51 sound_manager->preload("sounds/stomp.wav");
59 Dart::updatePointers(const GameObject* from_object, GameObject* to_object)
61 if (from_object == parent) {
62 parent = dynamic_cast<Dart*>(to_object);
71 physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED);
72 sprite->set_action(dir == LEFT ? "flying-left" : "flying-right");
78 sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
79 sound_source->set_position(get_pos());
80 sound_source->set_looping(true);
81 sound_source->set_gain(1.0);
82 sound_source->set_reference_distance(32);
94 Dart::active_update(float elapsed_time)
96 BadGuy::active_update(elapsed_time);
97 sound_source->set_position(get_pos());
101 Dart::collision_solid(const CollisionHit& )
103 sound_manager->play("sounds/darthit.wav", get_pos());
108 Dart::collision_badguy(BadGuy& badguy, const CollisionHit& )
110 // ignore collisions with parent
111 if (&badguy == parent) {
114 sound_manager->play("sounds/stomp.wav", get_pos());
121 Dart::collision_player(Player& player, const CollisionHit& hit)
123 sound_manager->play("sounds/stomp.wav", get_pos());
125 return BadGuy::collision_player(player, hit);
128 IMPLEMENT_FACTORY(Dart, "dart");