Skip to content
Browse files

added special item sound effect when a heart is acquired

  • Loading branch information...
1 parent 6f839db commit 00d7d03369caf02573cfda5265b470e9e2084dcd davewx7 committed Jul 13, 2008
Showing with 35 additions and 1 deletion.
  1. +5 −0 item.cpp
  2. +1 −0 item_type.cpp
  3. +2 −0 item_type.hpp
  4. +1 −0 items.cfg
  5. 0 {sounds → music}/specialitem.ogg
  6. +25 −1 sound.cpp
  7. +1 −0 sound.hpp
View
5 item.cpp
@@ -4,6 +4,7 @@
#include "formatter.hpp"
#include "item.hpp"
#include "level.hpp"
+#include "sound.hpp"
#include "wml_node.hpp"
#include "wml_utils.hpp"
@@ -44,6 +45,10 @@ void item::process(level& lvl)
time_in_frame_ = 0;
touched_ = true;
+ if(type_->on_touch_music().empty() == false) {
+ sound::play_music_interrupt(type_->on_touch_music());
+ }
+
for(int n = 0; n != type_->num_on_touch_particles(); ++n) {
const_custom_object_type_ptr particle_type = custom_object_type::get(type_->on_touch_particles());
if(!particle_type) {
View
1 item_type.cpp
@@ -31,6 +31,7 @@ item_type::item_type(wml::const_node_ptr node)
frame_(node->get_child("animation")),
destroy_on_touch_(wml::get_bool(node, "destroy_on_touch", false)),
automatic_touch_(wml::get_bool(node, "automatic_touch", true)),
+ on_touch_music_(node->attr("on_touch_music")),
touch_condition_(game_logic::formula::create_optional_formula(node->attr("touch_condition"))),
on_touch_particles_(node->attr("on_touch_particles")),
num_on_touch_particles_(wml::get_int(node, "num_particles"))
View
2 item_type.hpp
@@ -33,13 +33,15 @@ class item_type
const std::string& on_touch_particles() const { return on_touch_particles_; }
int num_on_touch_particles() const { return num_on_touch_particles_; }
+ const std::string& on_touch_music() const { return on_touch_music_; }
private:
std::string id_;
frame frame_;
boost::shared_ptr<frame> touched_frame_;
bool destroy_on_touch_;
bool automatic_touch_;
+ std::string on_touch_music_;
std::map<std::string, game_logic::const_formula_ptr> on_touch_;
game_logic::const_formula_ptr touch_condition_;
std::string on_touch_particles_;
View
1 items.cfg
@@ -94,6 +94,7 @@
destroy_on_touch=yes
on_touch_particles=heart_sparkle
num_particles=12
+ on_touch_music=specialitem.ogg
[ontouch]
hitpoints="hitpoints + 1"
max_hitpoints="max_hitpoints + 1"
View
0 sounds/specialitem.ogg → music/specialitem.ogg
File renamed without changes.
View
26 sound.cpp
@@ -25,6 +25,7 @@ typedef std::map<std::string, Mix_Chunk*> cache_map;
cache_map cache;
Mix_Music* current_music = NULL;
+std::string current_music_name;
std::string next_music;
//function which gets called when music finishes playing. It starts playing
@@ -34,7 +35,9 @@ void on_music_finished()
std::cerr << "music finished...\n";
Mix_FreeMusic(current_music);
current_music = NULL;
- play_music(next_music);
+ if(next_music.empty() == false) {
+ play_music(next_music);
+ }
next_music.clear();
}
@@ -102,6 +105,7 @@ void play_music(const std::string& file)
return;
}
+ current_music_name = file;
current_music = Mix_LoadMUS(("music/" + file).c_str());
if(!current_music) {
std::cerr << "Mix_LaadMUS ERROR loading " << file << ": " << Mix_GetError() << "\n";
@@ -113,4 +117,24 @@ void play_music(const std::string& file)
Mix_FadeInMusic(current_music, -1, 1000);
}
+void play_music_interrupt(const std::string& file)
+{
+ if(next_music.empty() == false) {
+ current_music_name = next_music;
+ next_music.clear();
+ }
+
+ Mix_HaltMusic();
+
+ next_music = current_music_name;
+
+ current_music = Mix_LoadMUS(("music/" + file).c_str());
+ if(!current_music) {
+ std::cerr << "Mix_LaadMUS ERROR loading " << file << ": " << Mix_GetError() << "\n";
+ return;
+ }
+
+ Mix_PlayMusic(current_music, 1);
+}
+
}
View
1 sound.hpp
@@ -14,6 +14,7 @@ bool ok();
void play(const std::string& file);
void play_music(const std::string& file);
+void play_music_interrupt(const std::string& file);
}

0 comments on commit 00d7d03

Please sign in to comment.
Something went wrong with that request. Please try again.