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/bouncy_coin.hpp"
19 #include "sprite/sprite.hpp"
20 #include "sprite/sprite_manager.hpp"
22 /** this controls the time over which a bouncy coin fades */
23 static const float FADE_TIME = .2f;
24 /** this is the total life time of a bouncy coin */
25 static const float LIFE_TIME = .5f;
27 BouncyCoin::BouncyCoin(const Vector& pos, bool emerge) :
31 timer.start(LIFE_TIME);
32 sprite = sprite_manager->create("images/objects/coin/coin.sprite");
35 emerge_distance = sprite->get_height();
39 BouncyCoin::~BouncyCoin()
44 BouncyCoin::update(float elapsed_time)
46 float dist = -200 * elapsed_time;
48 emerge_distance += dist;
55 BouncyCoin::draw(DrawingContext& context)
57 float time_left = timer.get_timeleft();
58 bool fading = time_left < FADE_TIME;
60 float alpha = time_left/FADE_TIME;
61 context.push_transform();
62 context.set_alpha(alpha);
66 if(emerge_distance > 0) {
67 layer = LAYER_OBJECTS - 5;
69 layer = LAYER_OBJECTS + 5;
71 sprite->draw(context, position, layer);
74 context.pop_transform();