blind commit, please test: use squirrel datatypes
[supertux.git] / src / object / coin.cpp
index 7fbebc7..7e263aa 100644 (file)
 #include "gameobjs.hpp"
 #include "statistics.hpp"
 #include "object_factory.hpp"
+#include "level.hpp"
+#include "random_generator.hpp"
+#include "audio/sound_source.hpp"
+#include "audio/sound_manager.hpp"
+#include "timer.hpp"
 
 Coin::Coin(const Vector& pos)
 {
@@ -66,9 +71,78 @@ Coin::draw(DrawingContext& context)
 void
 Coin::collect()
 {
+  // TODO: commented out musical code. Maybe fork this for a special "MusicalCoin" object?
+  /*
+  static Timer sound_timer; 
+  static int pitch_one = 128;
+  static float last_pitch = 1;
+  float pitch = 1;
+
+  int tile = static_cast<int>(get_pos().y / 32);
+
+  if (!sound_timer.started()) {
+    pitch_one = tile;
+    pitch = 1;
+    last_pitch = 1;
+  } 
+  else if (sound_timer.get_timegone() < 0.02) {
+    pitch = last_pitch;
+  } 
+  else 
+  {
+    switch ((pitch_one - tile) % 7) {
+      case -6:
+       pitch = 1.0/2;
+       break;
+      case -5:
+       pitch = 5.0/8;
+       break;
+      case -4:
+       pitch = 4.0/6;
+       break;
+      case -3:
+       pitch = 3.0/4;
+       break;
+      case -2:
+       pitch = 5.0/6;
+       break;
+      case -1:
+       pitch = 9.0/10;
+       break;
+      case 0:
+       pitch = 1.0;
+       break;
+      case 1:
+       pitch = 9.0/8;
+       break;
+      case 2:
+       pitch = 5.0/4;
+       break;
+      case 3:
+       pitch = 4.0/3;
+       break;
+      case 4:
+       pitch = 3.0/2;
+       break;
+      case 5:
+       pitch = 5.0/3;
+       break;
+      case 6:
+       pitch = 9.0/5;
+       break;
+    }
+    last_pitch = pitch;
+  }
+  sound_timer.start(1);
+
+  SoundSource* soundSource = sound_manager->create_sound_source("sounds/coin.wav");
+  soundSource->set_position(get_pos());
+  soundSource->set_pitch(pitch);
+  sound_manager->play_and_delete(soundSource);
+*/
   Sector::current()->player->get_status()->add_coins(1);
   Sector::current()->add_object(new BouncyCoin(get_pos()));
-  Sector::current()->get_level()->stats.add_points(COINS_COLLECTED_STAT, 1);
+  Sector::current()->get_level()->stats.coins++;
   remove_me();
 }