From: Christoph Sommer Date: Sat, 15 Apr 2006 23:54:57 +0000 (+0000) Subject: Added some audio / Minor fixes / Nicer test level X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9108829688029885d32ae0be51999c9666d806e6;p=supertux.git Added some audio / Minor fixes / Nicer test level SVN-Revision: 3349 --- diff --git a/data/levels/test/darttrap.stl b/data/levels/test/darttrap.stl index f189b89e8..82a8f18dc 100644 --- a/data/levels/test/darttrap.stl +++ b/data/levels/test/darttrap.stl @@ -75,11 +75,11 @@ 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 - 61 61 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 - 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 - 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 - 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 - 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 + 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 61 61 61 61 61 + 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 0 0 0 0 0 61 + 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 61 61 61 61 61 61 0 0 0 0 0 61 + 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 0 0 0 0 0 0 0 0 0 0 0 61 + 61 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 0 0 0 0 0 0 0 0 0 0 0 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 61 )) (tilemap @@ -129,7 +129,8 @@ (speed 0.500000) ) - (darttrap (x 800) (y 850)) + (darttrap (x 725) (y 770) (fire-delay 1.3)) + (darttrap (x 533) (y 850) (initial-delay 2) (ammo 3)) (powerup (x 100) (y 700) (sprite "images/powerups/egg/egg.sprite")) (spawnpoint (name "main") (x 40) (y 700)) ) diff --git a/src/badguy/dart.cpp b/src/badguy/dart.cpp index 99d5bb774..e266c2036 100644 --- a/src/badguy/dart.cpp +++ b/src/badguy/dart.cpp @@ -26,7 +26,7 @@ namespace { const float SPEED = 200; } -Dart::Dart(const lisp::Lisp& reader) : set_direction(false), parent(0) +Dart::Dart(const lisp::Lisp& reader) : set_direction(false), parent(0), soundSource(0) { reader.get("x", start_position.x); reader.get("y", start_position.y); @@ -36,7 +36,7 @@ Dart::Dart(const lisp::Lisp& reader) : set_direction(false), parent(0) countMe = false; } -Dart::Dart(float pos_x, float pos_y, Direction d, const BadGuy* parent = 0) : set_direction(true), initial_direction(d), parent(parent) +Dart::Dart(float pos_x, float pos_y, Direction d, const BadGuy* parent = 0) : set_direction(true), initial_direction(d), parent(parent), soundSource(0) { start_position.x = pos_x; start_position.y = pos_y; @@ -46,6 +46,11 @@ Dart::Dart(float pos_x, float pos_y, Direction d, const BadGuy* parent = 0) : se countMe = false; } +Dart::~Dart() +{ + delete soundSource; +} + void Dart::write(lisp::Writer& writer) { @@ -61,17 +66,40 @@ Dart::activate() if (set_direction) dir = initial_direction; physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED); sprite->set_action(dir == LEFT ? "flying-left" : "flying-right"); + + delete soundSource; + soundSource = sound_manager->create_sound_source("sounds/flame.wav"); + if(soundSource) { + soundSource->set_position(get_pos()); + soundSource->set_looping(true); + soundSource->set_gain(1.0); + soundSource->set_reference_distance(32); + soundSource->play(); + } else { + log_warning << "Couldn't start Dart ambient sound" << std::endl; + } } void Dart::deactivate() { + delete soundSource; + soundSource = 0; remove_me(); } +void +Dart::active_update(float elapsed_time) +{ + BadGuy::active_update(elapsed_time); + if (soundSource) soundSource->set_position(get_pos()); +} + + HitResponse Dart::collision_solid(GameObject& , const CollisionHit& ) { + sound_manager->play("sounds/stomp.wav", get_pos()); remove_me(); return ABORT_MOVE; } @@ -83,6 +111,7 @@ Dart::collision_badguy(BadGuy& badguy, const CollisionHit& ) if (&badguy == parent) { return FORCE_MOVE; } + sound_manager->play("sounds/stomp.wav", get_pos()); remove_me(); badguy.kill_fall(); return ABORT_MOVE; @@ -91,11 +120,10 @@ Dart::collision_badguy(BadGuy& badguy, const CollisionHit& ) HitResponse Dart::collision_player(Player& player, const CollisionHit& hit) { + sound_manager->play("sounds/stomp.wav", get_pos()); remove_me(); return BadGuy::collision_player(player, hit); } - - IMPLEMENT_FACTORY(Dart, "dart") diff --git a/src/badguy/dart.hpp b/src/badguy/dart.hpp index 36f858f9f..46bc30173 100644 --- a/src/badguy/dart.hpp +++ b/src/badguy/dart.hpp @@ -31,11 +31,14 @@ class Dart : public BadGuy public: Dart(const lisp::Lisp& reader); Dart(float pos_x, float pos_y, Direction d, const BadGuy* parent); + ~Dart(); void activate(); void deactivate(); void write(lisp::Writer& writer); + void active_update(float elapsed_time); + HitResponse collision_solid(GameObject& object, const CollisionHit& hit); HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); HitResponse collision_player(Player& player, const CollisionHit& hit); @@ -44,6 +47,7 @@ protected: bool set_direction; Direction initial_direction; const BadGuy* parent; /**< collisions with this BadGuy will be ignored */ + SoundSource* soundSource; /**< SoundSource for ambient sound */ }; #endif diff --git a/src/badguy/darttrap.cpp b/src/badguy/darttrap.cpp index 112837a22..f04d5cc96 100644 --- a/src/badguy/darttrap.cpp +++ b/src/badguy/darttrap.cpp @@ -26,7 +26,7 @@ namespace { const float MUZZLE_Y = 28; /**< [px] muzzle y-offset from top */ } -DartTrap::DartTrap(const lisp::Lisp& reader) : initial_delay(0), fire_delay(2), ammo(-1), state(IDLE) +DartTrap::DartTrap(const lisp::Lisp& reader) : set_direction(true), initial_direction(LEFT), initial_delay(0), fire_delay(2), ammo(-1), state(IDLE) { reader.get("x", start_position.x); reader.get("y", start_position.y); @@ -99,6 +99,7 @@ DartTrap::fire() float py = get_pos().y; py += MUZZLE_Y; + sound_manager->play("sounds/squish.wav", get_pos()); Sector::current()->add_object(new Dart(px, py, dir, this)); state = IDLE; sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");