3 // Dart - Your average poison dart
4 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
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
25 #include "lisp/writer.hpp"
26 #include "object_factory.hpp"
27 #include "audio/sound_manager.hpp"
28 #include "audio/sound_source.hpp"
29 #include "sprite/sprite.hpp"
32 const float SPEED = 200;
35 static const std::string SOUNDFILE = "sounds/flame.wav";
37 Dart::Dart(const lisp::Lisp& reader)
38 : BadGuy(reader, "images/creatures/dart/dart.sprite"), parent(0)
40 physic.enable_gravity(false);
42 sound_manager->preload(SOUNDFILE);
43 sound_manager->preload("sounds/darthit.wav");
44 sound_manager->preload("sounds/stomp.wav");
47 Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0)
48 : BadGuy(pos, d, "images/creatures/dart/dart.sprite"), parent(parent)
50 physic.enable_gravity(false);
52 sound_manager->preload(SOUNDFILE);
53 sound_manager->preload("sounds/darthit.wav");
54 sound_manager->preload("sounds/stomp.wav");
57 Dart::Dart(const Dart& other)
58 : BadGuy(other), parent(other.parent)
60 sound_manager->preload(SOUNDFILE);
61 sound_manager->preload("sounds/darthit.wav");
62 sound_manager->preload("sounds/stomp.wav");
70 Dart::updatePointers(const GameObject* from_object, GameObject* to_object)
72 if (from_object == parent) {
73 parent = dynamic_cast<Dart*>(to_object);
80 Dart::write(lisp::Writer& writer)
82 writer.start_list("dart");
83 writer.write("x", start_position.x);
84 writer.write("y", start_position.y);
85 writer.end_list("dart");
91 physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED);
92 sprite->set_action(dir == LEFT ? "flying-left" : "flying-right");
98 sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
99 sound_source->set_position(get_pos());
100 sound_source->set_looping(true);
101 sound_source->set_gain(1.0);
102 sound_source->set_reference_distance(32);
103 sound_source->play();
109 sound_source.reset();
114 Dart::active_update(float elapsed_time)
116 BadGuy::active_update(elapsed_time);
117 sound_source->set_position(get_pos());
121 Dart::collision_solid(const CollisionHit& )
123 sound_manager->play("sounds/darthit.wav", get_pos());
128 Dart::collision_badguy(BadGuy& badguy, const CollisionHit& )
130 // ignore collisions with parent
131 if (&badguy == parent) {
134 sound_manager->play("sounds/stomp.wav", get_pos());
141 Dart::collision_player(Player& player, const CollisionHit& hit)
143 sound_manager->play("sounds/stomp.wav", get_pos());
145 return BadGuy::collision_player(player, hit);
148 IMPLEMENT_FACTORY(Dart, "dart")