X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fcoin.cpp;h=7e263aa04f554d0f38efe0181ad8e1ed6869b5b9;hb=fe138b9ec292ca9679b43cf5c4555f0193bab25d;hp=d3e5a56896a8a2a3fd59ef3bed3269c53a096cb1;hpb=5d1290054358cb4560f54bcd6840121a69360bf9;p=supertux.git diff --git a/src/object/coin.cpp b/src/object/coin.cpp index d3e5a5689..7e263aa04 100644 --- a/src/object/coin.cpp +++ b/src/object/coin.cpp @@ -1,7 +1,7 @@ // $Id$ -// +// // SuperTux -// Copyright (C) 2005 Matthias Braun +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,11 +12,11 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 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. +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include #include "coin.hpp" @@ -29,6 +29,11 @@ #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(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())); - global_stats.add_points(COINS_COLLECTED_STAT, 1); + Sector::current()->get_level()->stats.coins++; remove_me(); }