X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fcoin.cpp;h=c75312fb9adfb02633fcde87821be07c16202a41;hb=5745d9670262c91e6cd35363fd0d2ec169e7c8a4;hp=36b035abb93cd3910b48a3029994ee3da1f9495f;hpb=d99e2443318865c0f379170b4ef2aa30f515b235;p=supertux.git diff --git a/src/object/coin.cpp b/src/object/coin.cpp index 36b035abb..c75312fb9 100644 --- a/src/object/coin.cpp +++ b/src/object/coin.cpp @@ -36,42 +36,23 @@ #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,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: @@ -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();