[Super-tux-commit] supertux/src gameobjs.cpp,1.51,1.52 gameobjs.h,1.36,1.37 sector.cpp,1.28,1.29
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-09-20 19:17:39
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13237/src Modified Files: gameobjs.cpp gameobjs.h sector.cpp Log Message: Changed FloatingScore to support text (changed name to FloatingText). I guess this could be usefull for some stuff, saying "Bonus" and whatever. Also made a fading animation when disapearing. Index: gameobjs.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.cpp,v retrieving revision 1.51 retrieving revision 1.52 diff -u -d -r1.51 -r1.52 --- gameobjs.cpp 17 Sep 2004 12:41:50 -0000 1.51 +++ gameobjs.cpp 20 Sep 2004 19:17:29 -0000 1.52 @@ -114,27 +114,48 @@ draw_tile(context, shape.id, position + Vector(0, offset), LAYER_TILES+1); } -FloatingScore::FloatingScore(const Vector& pos, int score) +FloatingText::FloatingText(const Vector& pos, 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.draw_text(gold_text, text, position, LEFT_ALLIGN, LAYER_OBJECTS, NONE_EFFECT, alpha); } /* Trampoline */ Index: gameobjs.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.h,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- gameobjs.h 17 Sep 2004 12:41:52 -0000 1.36 +++ gameobjs.h 20 Sep 2004 19:17:29 -0000 1.37 @@ -91,17 +91,18 @@ TileId& shape; }; -class FloatingScore : public GameObject +class FloatingText : public GameObject { public: - FloatingScore(const Vector& pos, int s); + FloatingText(const Vector& pos, std::string& text_); + FloatingText(const Vector& pos, int s); // use this for score, for instance virtual void action(float elapsed_time); virtual void draw(DrawingContext& context); private: Vector position; - char str[10]; + std::string text; Timer timer; }; Index: sector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- sector.cpp 17 Sep 2004 12:22:40 -0000 1.28 +++ sector.cpp 20 Sep 2004 19:17:29 -0000 1.29 @@ -667,7 +667,7 @@ { global_stats.add_points(SCORE_STAT, s); - add_object(new FloatingScore(pos, s)); + add_object(new FloatingText(pos, s)); } void |