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 Dart::Dart(const lisp::Lisp& reader)
30 : BadGuy(reader, "images/creatures/dart/dart.sprite"), set_direction(false), parent(0), soundSource(0)
32 physic.enable_gravity(false);
36 Dart::Dart(const Vector& pos, Direction d, const BadGuy* parent = 0)
37 : BadGuy(pos, "images/creatures/dart/dart.sprite"), set_direction(true), initial_direction(d), parent(parent), soundSource(0)
39 physic.enable_gravity(false);
43 Dart::Dart(const Dart& other)
44 : BadGuy(other), set_direction(other.set_direction), initial_direction(other.initial_direction), parent(other.parent)
46 soundSource = sound_manager->create_sound_source("sounds/flame.wav");
55 Dart::updatePointers(const GameObject* from_object, GameObject* to_object)
57 if (from_object == parent) {
58 parent = dynamic_cast<Dart*>(to_object);
65 Dart::write(lisp::Writer& writer)
67 writer.start_list("dart");
68 writer.write_float("x", start_position.x);
69 writer.write_float("y", start_position.y);
70 writer.end_list("dart");
76 if (set_direction) dir = initial_direction;
77 physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED);
78 sprite->set_action(dir == LEFT ? "flying-left" : "flying-right");
81 soundSource = sound_manager->create_sound_source("sounds/flame.wav");
83 soundSource->set_position(get_pos());
84 soundSource->set_looping(true);
85 soundSource->set_gain(1.0);
86 soundSource->set_reference_distance(32);
89 log_warning << "Couldn't start Dart ambient sound" << std::endl;
102 Dart::active_update(float elapsed_time)
104 BadGuy::active_update(elapsed_time);
105 if (soundSource) soundSource->set_position(get_pos());
110 Dart::collision_solid(GameObject& , const CollisionHit& )
112 sound_manager->play("sounds/stomp.wav", get_pos());
118 Dart::collision_badguy(BadGuy& badguy, const CollisionHit& )
120 // ignore collisions with parent
121 if (&badguy == parent) {
124 sound_manager->play("sounds/stomp.wav", get_pos());
131 Dart::collision_player(Player& player, const CollisionHit& hit)
133 sound_manager->play("sounds/stomp.wav", get_pos());
135 return BadGuy::collision_player(player, hit);
138 IMPLEMENT_FACTORY(Dart, "dart")