| 1 | // Dart - Your average poison dart |
| 2 | // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de> |
| 3 | // |
| 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. |
| 8 | // |
| 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. |
| 13 | // |
| 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/>. |
| 16 | |
| 17 | #include "badguy/dart.hpp" |
| 18 | |
| 19 | #include "audio/sound_manager.hpp" |
| 20 | #include "audio/sound_source.hpp" |
| 21 | #include "sprite/sprite.hpp" |
| 22 | |
| 23 | namespace { |
| 24 | const float DART_SPEED = 200; |
| 25 | } |
| 26 | |
| 27 | static const std::string DART_SOUND = "sounds/flame.wav" ; |
| 28 | |
| 29 | Dart::Dart(const ReaderMapping& reader) : |
| 30 | BadGuy(reader, "images/creatures/dart/dart.sprite" ), |
| 31 | parent(nullptr), |
| 32 | sound_source() |
| 33 | { |
| 34 | m_physic.enable_gravity(false); |
| 35 | m_countMe = false; |
| 36 | SoundManager::current()->preload(DART_SOUND); |
| 37 | SoundManager::current()->preload("sounds/darthit.wav" ); |
| 38 | SoundManager::current()->preload("sounds/stomp.wav" ); |
| 39 | } |
| 40 | |
| 41 | Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent_ = nullptr) : |
| 42 | BadGuy(pos, d, "images/creatures/dart/dart.sprite" ), |
| 43 | parent(parent_), |
| 44 | sound_source() |
| 45 | { |
| 46 | m_physic.enable_gravity(false); |
| 47 | m_countMe = false; |
| 48 | SoundManager::current()->preload(DART_SOUND); |
| 49 | SoundManager::current()->preload("sounds/darthit.wav" ); |
| 50 | SoundManager::current()->preload("sounds/stomp.wav" ); |
| 51 | } |
| 52 | |
| 53 | bool |
| 54 | Dart::updatePointers(const GameObject* from_object, GameObject* to_object) |
| 55 | { |
| 56 | if (from_object == parent) { |
| 57 | parent = dynamic_cast<Dart*>(to_object); |
| 58 | return true; |
| 59 | } |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | void |
| 64 | Dart::initialize() |
| 65 | { |
| 66 | m_physic.set_velocity_x(m_dir == Direction::LEFT ? -::DART_SPEED : ::DART_SPEED); |
| 67 | m_sprite->set_action(m_dir == Direction::LEFT ? "flying-left" : "flying-right" ); |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | Dart::activate() |
| 72 | { |
| 73 | sound_source = SoundManager::current()->create_sound_source(DART_SOUND); |
| 74 | sound_source->set_position(get_pos()); |
| 75 | sound_source->set_looping(true); |
| 76 | sound_source->set_gain(0.5f); |
| 77 | sound_source->set_reference_distance(32); |
| 78 | sound_source->play(); |
| 79 | } |
| 80 | |
| 81 | void |
| 82 | Dart::deactivate() |
| 83 | { |
| 84 | sound_source.reset(); |
| 85 | remove_me(); |
| 86 | } |
| 87 | |
| 88 | void |
| 89 | Dart::active_update(float dt_sec) |
| 90 | { |
| 91 | BadGuy::active_update(dt_sec); |
| 92 | sound_source->set_position(get_pos()); |
| 93 | } |
| 94 | |
| 95 | void |
| 96 | Dart::collision_solid(const CollisionHit& ) |
| 97 | { |
| 98 | SoundManager::current()->play("sounds/darthit.wav" , get_pos()); |
| 99 | remove_me(); |
| 100 | } |
| 101 | |
| 102 | HitResponse |
| 103 | Dart::collision_badguy(BadGuy& badguy, const CollisionHit& ) |
| 104 | { |
| 105 | // ignore collisions with parent |
| 106 | if (&badguy == parent) { |
| 107 | return FORCE_MOVE; |
| 108 | } |
| 109 | SoundManager::current()->play("sounds/stomp.wav" , get_pos()); |
| 110 | remove_me(); |
| 111 | badguy.kill_fall(); |
| 112 | return ABORT_MOVE; |
| 113 | } |
| 114 | |
| 115 | HitResponse |
| 116 | Dart::collision_player(Player& player, const CollisionHit& hit) |
| 117 | { |
| 118 | SoundManager::current()->play("sounds/stomp.wav" , get_pos()); |
| 119 | remove_me(); |
| 120 | return BadGuy::collision_player(player, hit); |
| 121 | } |
| 122 | |
| 123 | bool |
| 124 | Dart::is_flammable() const |
| 125 | { |
| 126 | return false; |
| 127 | } |
| 128 | |
| 129 | void Dart::stop_looping_sounds() |
| 130 | { |
| 131 | if (sound_source) { |
| 132 | sound_source->stop(); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | void Dart::play_looping_sounds() |
| 137 | { |
| 138 | if (sound_source) { |
| 139 | sound_source->play(); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /* EOF */ |
| 144 | |