2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "object/coin.hpp"
19 #include "audio/sound_manager.hpp"
20 #include "object/bouncy_coin.hpp"
21 #include "object/player.hpp"
22 #include "supertux/level.hpp"
23 #include "supertux/object_factory.hpp"
24 #include "supertux/sector.hpp"
26 Coin::Coin(const Vector& pos)
27 : MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE)
29 sound_manager->preload("sounds/coin.wav");
32 Coin::Coin(const Reader& reader)
33 : MovingSprite(reader, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE)
35 sound_manager->preload("sounds/coin.wav");
41 // TODO: commented out musical code. Maybe fork this for a special "MusicalCoin" object?
43 static Timer sound_timer;
44 static int pitch_one = 128;
45 static float last_pitch = 1;
48 int tile = static_cast<int>(get_pos().y / 32);
50 if (!sound_timer.started()) {
55 else if (sound_timer.get_timegone() < 0.02) {
60 switch ((pitch_one - tile) % 7) {
103 sound_timer.start(1);
105 SoundSource* soundSource = sound_manager->create_sound_source("sounds/coin.wav");
106 soundSource->set_position(get_pos());
107 soundSource->set_pitch(pitch);
109 sound_manager->manage_source(soundSource);
111 Sector::current()->player->get_status()->add_coins(1);
112 Sector::current()->add_object(new BouncyCoin(get_pos()));
113 Sector::current()->get_level()->stats.coins++;
118 Coin::collision(GameObject& other, const CollisionHit& )
120 Player* player = dynamic_cast<Player*>(&other);