X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgameobjs.cpp;h=5340bfb57b31712ce8c70592b46490391501aa3e;hb=e4db6eb50cd6bcba607858b5e6c4c5d53531ed1f;hp=efaf5431401202b02fe7931c5fce4f69cb41520e;hpb=e85dd457fc30c6adf68ce2ad63cf58e109225a3c;p=supertux.git diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index efaf54314..5340bfb57 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -114,27 +114,53 @@ BouncyBrick::draw(DrawingContext& context) draw_tile(context, shape.id, position + Vector(0, offset), LAYER_TILES+1); } -FloatingScore::FloatingScore(const Vector& pos, int score) +FloatingText::FloatingText(const Vector& pos, const std::string& text_) + : position(pos), text(text_) +{ + timer.start(1000); + position.x -= text.size() * 8; +} + +FloatingText::FloatingText(const Vector& pos, int score) : position(pos) { timer.start(1000); + + // turn int into a string + char str[10]; snprintf(str, 10, "%d", score); - position.x -= strlen(str) * 8; + text = str; + + position.x -= text.size() * 8; } void -FloatingScore::action(float elapsed_time) +FloatingText::action(float elapsed_time) { - position.y -= 2 * elapsed_time; + position.y -= 1.4 * elapsed_time; if(!timer.check()) remove_me(); } +#define FADING_TIME 350 + void -FloatingScore::draw(DrawingContext& context) +FloatingText::draw(DrawingContext& context) { - context.draw_text(gold_text, str, position, LEFT_ALLIGN, LAYER_OBJECTS); + // make an alpha animation when disapearing + int alpha; + if(timer.get_left() < FADING_TIME) + alpha = timer.get_left() * 255 / FADING_TIME; + else + alpha = 255; + + context.push_transform(); + context.set_alpha(alpha); + + context.draw_text(gold_text, text, position, LEFT_ALLIGN, LAYER_OBJECTS+1); + + context.pop_transform(); } /* Trampoline */