From 99ffd1de8f666bffa646064a587238803acec131 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Mon, 20 Sep 2004 19:17:29 +0000 Subject: [PATCH] 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. SVN-Revision: 1952 --- src/gameobjs.cpp | 33 +++++++++++++++++++++++++++------ src/gameobjs.h | 7 ++++--- src/sector.cpp | 2 +- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index efaf54314..b440b5cc1 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -114,27 +114,48 @@ 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, 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 */ diff --git a/src/gameobjs.h b/src/gameobjs.h index 41de71a85..88a8d7aab 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -91,17 +91,18 @@ private: 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; }; diff --git a/src/sector.cpp b/src/sector.cpp index b980e8ed5..0cd48d879 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -667,7 +667,7 @@ Sector::add_score(const Vector& pos, int s) { global_stats.add_points(SCORE_STAT, s); - add_object(new FloatingScore(pos, s)); + add_object(new FloatingText(pos, s)); } void -- 2.11.0