Bug 456: Avoid hurting Tux in a ravine.
[supertux.git] / src / object / coin.cpp
index c75312f..9977ff8 100644 (file)
@@ -1,12 +1,10 @@
-//  $Id$
-//
 //  SuperTux
 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
 //
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
 //
 //  This program is distributed in the hope that it will be useful,
 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
 //  GNU General Public License for more details.
 //
 //  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <config.h>
+#include "object/coin.hpp"
 
-#include "coin.hpp"
-#include "resources.hpp"
-#include "video/drawing_context.hpp"
-#include "sprite/sprite_manager.hpp"
-#include "player.hpp"
-#include "sector.hpp"
-#include "player_status.hpp"
-#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"
+#include "object/bouncy_coin.hpp"
+#include "object/player.hpp"
+#include "supertux/level.hpp"
+#include "supertux/object_factory.hpp"
+#include "supertux/sector.hpp"
 
 Coin::Coin(const Vector& pos)
-       : MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE)
+  : MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_TILES, 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)
+Coin::Coin(const Reader& reader)
+  : MovingSprite(reader, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE)
 {
   sound_manager->preload("sounds/coin.wav");
 }
@@ -52,74 +40,74 @@ 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;
+    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);
+    int tile = static_cast<int>(get_pos().y / 32);
 
-  if (!sound_timer.started()) {
+    if (!sound_timer.started()) {
     pitch_one = tile;
     pitch = 1;
     last_pitch = 1;
-  }
-  else if (sound_timer.get_timegone() < 0.02) {
+    }
+    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;
-      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;
+    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);
+    }
+    sound_timer.start(1);
 
-  SoundSource* soundSource = sound_manager->create_sound_source("sounds/coin.wav");
-  soundSource->set_position(get_pos());
-  soundSource->set_pitch(pitch);
-  soundSource->play();
-  sound_manager->manage_source(soundSource);
-*/
+    SoundSource* soundSource = sound_manager->create_sound_source("sounds/coin.wav");
+    soundSource->set_position(get_pos());
+    soundSource->set_pitch(pitch);
+    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++;
@@ -137,4 +125,4 @@ Coin::collision(GameObject& other, const CollisionHit& )
   return ABORT_MOVE;
 }
 
-IMPLEMENT_FACTORY(Coin, "coin");
+/* EOF */