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_) :
30 position.x -= text.size() * 8;
33 FloatingText::FloatingText(const Vector& pos, int score) :
40 // turn int into a string
42 snprintf(str, 10, "%d", score);
45 position.x -= text.size() * 8;
49 FloatingText::update(float elapsed_time)
51 position.y -= 1.4 * elapsed_time;
57 #define FADING_TIME .350
60 FloatingText::draw(DrawingContext& context)
62 // make an alpha animation when disappearing
64 if(timer.get_timeleft() < FADING_TIME)
65 alpha = int(timer.get_timeleft() * 255 / FADING_TIME);
69 context.push_transform();
70 context.set_alpha(alpha);
72 context.draw_text(Resources::normal_font, text, position, ALIGN_LEFT, LAYER_OBJECTS+1, FloatingText::text_color);
74 context.pop_transform();