3 // Dart - Your average poison dart
4 // Copyright (C) 2006 Christoph Sommer <supertux@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
26 const float SPEED = 200;
29 static const std::string SOUNDFILE = "sounds/flame.wav";
31 Dart::Dart(const lisp::Lisp& reader)
32 : BadGuy(reader, "images/creatures/dart/dart.sprite"), parent(0)
34 physic.enable_gravity(false);
36 sound_manager->preload("sounds/darthit.wav");
37 sound_manager->preload("sounds/stomp.wav");
40 Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0)
41 : BadGuy(pos, d, "images/creatures/dart/dart.sprite"), parent(parent)
43 physic.enable_gravity(false);
45 sound_manager->preload("sounds/darthit.wav");
46 sound_manager->preload("sounds/stomp.wav");
49 Dart::Dart(const Dart& other)
50 : BadGuy(other), parent(other.parent)
52 sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
53 sound_manager->preload("sounds/darthit.wav");
54 sound_manager->preload("sounds/stomp.wav");
62 Dart::updatePointers(const GameObject* from_object, GameObject* to_object)
64 if (from_object == parent) {
65 parent = dynamic_cast<Dart*>(to_object);
72 Dart::write(lisp::Writer& writer)
74 writer.start_list("dart");
75 writer.write_float("x", start_position.x);
76 writer.write_float("y", start_position.y);
77 writer.end_list("dart");
83 physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED);
84 sprite->set_action(dir == LEFT ? "flying-left" : "flying-right");
86 sound_source.reset(sound_manager->create_sound_source(SOUNDFILE));
87 sound_source->set_position(get_pos());
88 sound_source->set_looping(true);
89 sound_source->set_gain(1.0);
90 sound_source->set_reference_distance(32);
102 Dart::active_update(float elapsed_time)
104 BadGuy::active_update(elapsed_time);
105 sound_source->set_position(get_pos());
109 Dart::collision_solid(const CollisionHit& )
111 sound_manager->play("sounds/darthit.wav", get_pos());
116 Dart::collision_badguy(BadGuy& badguy, const CollisionHit& )
118 // ignore collisions with parent
119 if (&badguy == parent) {
122 sound_manager->play("sounds/stomp.wav", get_pos());
129 Dart::collision_player(Player& player, const CollisionHit& hit)
131 sound_manager->play("sounds/stomp.wav", get_pos());
133 return BadGuy::collision_player(player, hit);
136 IMPLEMENT_FACTORY(Dart, "dart")