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)
41 bbox.set_size(32, 32);
42 sprite = sprite_manager->create("images/objects/coin/coin.sprite");
43 set_group(COLGROUP_TOUCHABLE);
46 Coin::Coin(const lisp::Lisp& reader)
48 reader.get("x", bbox.p1.x);
49 reader.get("y", bbox.p1.y);
50 bbox.set_size(32, 32);
51 sprite = sprite_manager->create("images/objects/coin/coin.sprite");
52 set_group(COLGROUP_TOUCHABLE);
66 Coin::draw(DrawingContext& context)
68 sprite->draw(context, get_pos(), LAYER_TILES);
74 static Timer sound_timer; /**< time since last Coin was collected */
75 static int pitch_one = 128;
76 static float last_pitch = 1;
79 int tile = static_cast<int>(get_pos().y / 32);
81 if (!sound_timer.started()) {
86 else if (sound_timer.get_timegone() < 0.02) {
91 switch ((pitch_one - tile) % 7) {
134 sound_timer.start(1);
136 SoundSource* soundSource = sound_manager->create_sound_source("sounds/coin.wav");
137 soundSource->set_position(get_pos());
138 soundSource->set_pitch(pitch);
139 sound_manager->play_and_delete(soundSource);
141 Sector::current()->player->get_status()->add_coins(1, false);
142 Sector::current()->add_object(new BouncyCoin(get_pos()));
143 Sector::current()->get_level()->stats.coins++;
148 Coin::collision(GameObject& other, const CollisionHit& )
150 Player* player = dynamic_cast<Player*>(&other);
158 IMPLEMENT_FACTORY(Coin, "coin");