X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fcoin.cpp;h=c75312fb9adfb02633fcde87821be07c16202a41;hb=5745d9670262c91e6cd35363fd0d2ec169e7c8a4;hp=c48292b398944d34f6e1abe43b650264d77f7e18;hpb=c0093d25093395cb62fc2526ab42be65a9f015b8;p=supertux.git diff --git a/src/object/coin.cpp b/src/object/coin.cpp index c48292b39..c75312fb9 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,62 +12,117 @@ // 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.h" -#include "resources.h" -#include "video/drawing_context.h" -#include "sprite/sprite_manager.h" -#include "player.h" -#include "sector.h" -#include "player_status.h" -#include "gameobjs.h" -#include "statistics.h" -#include "object_factory.h" +#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" 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("coin"); + 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("coin"); -} - -Coin::~Coin() -{ - delete sprite; + sound_manager->preload("sounds/coin.wav"); } void -Coin::action(float ) +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; -void -Coin::draw(DrawingContext& context) -{ - sprite->draw(context, get_pos(), LAYER_TILES); -} + int tile = static_cast(get_pos().y / 32); -void -Coin::collect() -{ - Sector::current()->player->get_status()->incCoins(); + 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); + soundSource->play(); + sound_manager->manage_source(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(); }