Patch by mathnerd314 <man.is.allan@gmail.com> resolves issue 0000302: Mr. Ice Block...
[supertux.git] / src / object / coin.cpp
index 7e263aa..c75312f 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
@@ -73,7 +52,7 @@ Coin::collect()
 {
   // TODO: commented out musical code. Maybe fork this for a special "MusicalCoin" object?
   /*
-  static Timer sound_timer; 
+  static Timer sound_timer;
   static int pitch_one = 128;
   static float last_pitch = 1;
   float pitch = 1;
@@ -84,11 +63,11 @@ 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:
@@ -138,7 +117,8 @@ 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);
+  soundSource->play();
+  sound_manager->manage_source(soundSource);
 */
   Sector::current()->player->get_status()->add_coins(1);
   Sector::current()->add_object(new BouncyCoin(get_pos()));