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) :
33 timer.start(LIFE_TIME);
34 sprite = sprite_manager->create("images/objects/coin/coin.sprite");
37 emerge_distance = sprite->get_height();
41 BouncyCoin::~BouncyCoin()
46 BouncyCoin::update(float elapsed_time)
48 float dist = -200 * elapsed_time;
50 emerge_distance += dist;
57 BouncyCoin::draw(DrawingContext& context)
59 float time_left = timer.get_timeleft();
60 bool fading = time_left < FADE_TIME;
62 float alpha = time_left/FADE_TIME;
63 context.push_transform();
64 context.set_alpha(alpha);
68 if(emerge_distance > 0) {
69 layer = LAYER_OBJECTS - 5;
71 layer = LAYER_OBJECTS + 5;
73 sprite->draw(context, position, layer);
76 context.pop_transform();