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/floating_text.hpp"
21 #include "supertux/resources.hpp"
22 #include "video/drawing_context.hpp"
24 FloatingText::FloatingText(const Vector& pos, const std::string& text_)
25 : position(pos), text(text_)
28 position.x -= text.size() * 8;
31 FloatingText::FloatingText(const Vector& pos, int score)
36 // turn int into a string
38 snprintf(str, 10, "%d", score);
41 position.x -= text.size() * 8;
45 FloatingText::update(float elapsed_time)
47 position.y -= 1.4 * elapsed_time;
53 #define FADING_TIME .350
56 FloatingText::draw(DrawingContext& context)
58 // make an alpha animation when disappearing
60 if(timer.get_timeleft() < FADING_TIME)
61 alpha = int(timer.get_timeleft() * 255 / FADING_TIME);
65 context.push_transform();
66 context.set_alpha(alpha);
68 context.draw_text(normal_font, text, position, ALIGN_LEFT, LAYER_OBJECTS+1, FloatingText::text_color);
70 context.pop_transform();