Changed jump behaviour: Tux will now jump even if the button was pressed (up to)...
[supertux.git] / src / object / coin.cpp
index 36b035a..dd9c0bf 100644 (file)
 #include "timer.hpp"
 
 Coin::Coin(const Vector& pos)
+        : MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE)
 {
-  bbox.set_pos(pos);
-  bbox.set_size(32, 32);
-  sprite = sprite_manager->create("images/objects/coin/coin.sprite");
-  set_group(COLGROUP_TOUCHABLE);
+  sound_manager->preload("sounds/coin.wav");
 }
 
 Coin::Coin(const lisp::Lisp& reader)
+        : MovingSprite(reader, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE)
 {
-  reader.get("x", bbox.p1.x);
-  reader.get("y", bbox.p1.y);
-  bbox.set_size(32, 32);
-  sprite = sprite_manager->create("images/objects/coin/coin.sprite");
-  set_group(COLGROUP_TOUCHABLE);
-}
-
-Coin::~Coin()
-{
-  delete sprite;
-}
-
-void
-Coin::update(float )
-{
-}
-
-void
-Coin::draw(DrawingContext& context)
-{
-  sprite->draw(context, get_pos(), LAYER_TILES);
+  sound_manager->preload("sounds/coin.wav");
 }
 
 void
 Coin::collect()
 {
-  static Timer sound_timer; /**< time since last Coin was collected */
+  // 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;
@@ -82,52 +63,52 @@ Coin::collect()
     pitch_one = tile;
     pitch = 1;
     last_pitch = 1;
-  } 
+  }
   else if (sound_timer.get_timegone() < 0.02) {
     pitch = last_pitch;
-  } 
-  else 
+  }
+  else
   {
     switch ((pitch_one - tile) % 7) {
       case -6:
-       pitch = 1.0/2;
-       break;
+        pitch = 1.0/2;
+        break;
       case -5:
-       pitch = 5.0/8;
-       break;
+        pitch = 5.0/8;
+        break;
       case -4:
-       pitch = 4.0/6;
-       break;
+        pitch = 4.0/6;
+        break;
       case -3:
-       pitch = 3.0/4;
-       break;
+        pitch = 3.0/4;
+        break;
       case -2:
-       pitch = 5.0/6;
-       break;
+        pitch = 5.0/6;
+        break;
       case -1:
-       pitch = 9.0/10;
-       break;
+        pitch = 9.0/10;
+        break;
       case 0:
-       pitch = 1.0;
-       break;
+        pitch = 1.0;
+        break;
       case 1:
-       pitch = 9.0/8;
-       break;
+        pitch = 9.0/8;
+        break;
       case 2:
-       pitch = 5.0/4;
-       break;
+        pitch = 5.0/4;
+        break;
       case 3:
-       pitch = 4.0/3;
-       break;
+        pitch = 4.0/3;
+        break;
       case 4:
-       pitch = 3.0/2;
-       break;
+        pitch = 3.0/2;
+        break;
       case 5:
-       pitch = 5.0/3;
-       break;
+        pitch = 5.0/3;
+        break;
       case 6:
-       pitch = 9.0/5;
-       break;
+        pitch = 9.0/5;
+        break;
     }
     last_pitch = pitch;
   }
@@ -136,9 +117,10 @@ Coin::collect()
   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, false);
+  soundSource->play();
+  sound_manager->manage_source(soundSource);
+*/
+  Sector::current()->player->get_status()->add_coins(1);
   Sector::current()->add_object(new BouncyCoin(get_pos()));
   Sector::current()->get_level()->stats.coins++;
   remove_me();