4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "resources.hpp"
24 #include "video/drawing_context.hpp"
25 #include "sprite/sprite_manager.hpp"
28 #include "player_status.hpp"
29 #include "gameobjs.hpp"
30 #include "statistics.hpp"
31 #include "object_factory.hpp"
33 #include "random_generator.hpp"
34 #include "audio/sound_source.hpp"
35 #include "audio/sound_manager.hpp"
38 Coin::Coin(const Vector& pos)
39 : MovingSprite(pos, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE)
43 Coin::Coin(const lisp::Lisp& reader)
44 : MovingSprite(reader, "images/objects/coin/coin.sprite", LAYER_TILES, COLGROUP_TOUCHABLE)
51 // TODO: commented out musical code. Maybe fork this for a special "MusicalCoin" object?
53 static Timer sound_timer;
54 static int pitch_one = 128;
55 static float last_pitch = 1;
58 int tile = static_cast<int>(get_pos().y / 32);
60 if (!sound_timer.started()) {
65 else if (sound_timer.get_timegone() < 0.02) {
70 switch ((pitch_one - tile) % 7) {
113 sound_timer.start(1);
115 SoundSource* soundSource = sound_manager->create_sound_source("sounds/coin.wav");
116 soundSource->set_position(get_pos());
117 soundSource->set_pitch(pitch);
119 sound_manager->manage_source(soundSource);
121 Sector::current()->player->get_status()->add_coins(1);
122 Sector::current()->add_object(new BouncyCoin(get_pos()));
123 Sector::current()->get_level()->stats.coins++;
128 Coin::collision(GameObject& other, const CollisionHit& )
130 Player* player = dynamic_cast<Player*>(&other);
138 IMPLEMENT_FACTORY(Coin, "coin");