In-game HUD now uses icons instead of text /
authorChristoph Sommer <mail@christoph-sommer.de>
Tue, 25 Jul 2006 00:30:30 +0000 (00:30 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Tue, 25 Jul 2006 00:30:30 +0000 (00:30 +0000)
Number of coins smoothly "counts" up- and downward

SVN-Revision: 4085

data/images/engine/hud/coins-0.png [new file with mode: 0644]
data/images/engine/hud/time-0.png [new file with mode: 0644]
src/object/level_time.cpp
src/object/level_time.hpp
src/player_status.cpp
src/player_status.hpp

diff --git a/data/images/engine/hud/coins-0.png b/data/images/engine/hud/coins-0.png
new file mode 100644 (file)
index 0000000..9ab0b4a
Binary files /dev/null and b/data/images/engine/hud/coins-0.png differ
diff --git a/data/images/engine/hud/time-0.png b/data/images/engine/hud/time-0.png
new file mode 100644 (file)
index 0000000..69ef34d
Binary files /dev/null and b/data/images/engine/hud/time-0.png differ
index 2941929..5911763 100644 (file)
@@ -42,6 +42,7 @@ LevelTime::LevelTime(const lisp::Lisp& reader)
 {
   reader.get("time", time_left);
   if(time_left <= 0) throw std::runtime_error("No or invalid leveltime specified");
+  time_surface.reset(new Surface("images/engine/hud/time-0.png"));
 }
 
 void
@@ -65,13 +66,14 @@ LevelTime::draw(DrawingContext& context)
   if ((time_left > TIME_WARNING) || (int(game_time * 2.5) % 2)) {
     std::stringstream ss;
     ss << int(time_left);
-    std::string time = ss.str();
+    std::string time_text = ss.str();
 
-    float caption_width = white_text->get_text_width(_("TIME")) + white_text->get_text_width(" ");
-    float all_width = caption_width + white_text->get_text_width(time);
-
-    context.draw_text(white_text, _("TIME"), Vector((SCREEN_WIDTH - all_width)/2, BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1);
-    context.draw_text(gold_text, time, Vector((SCREEN_WIDTH - all_width)/2 + caption_width, BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1);
+    Surface* time_surf = time_surface.get();
+    if (time_surf) {
+      float all_width = time_surf->get_width() + white_text->get_text_width(time_text);
+      context.draw_surface(time_surf, Vector((SCREEN_WIDTH - all_width)/2, BORDER_Y + 1), LAYER_FOREGROUND1); 
+      context.draw_text(gold_text, time_text, Vector((SCREEN_WIDTH - all_width)/2 + time_surf->get_width(), BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1);
+    }
   }
 
   context.pop_transform();
index 335f878..b96709a 100644 (file)
 #ifndef __LEVELTIME_H__
 #define __LEVELTIME_H__
 
+#include <memory>
 #include "game_object.hpp"
 #include "timer.hpp"
 #include "lisp/lisp.hpp"
+#include "video/surface.hpp"
 
 class LevelTime : public GameObject
 {
@@ -34,6 +36,7 @@ public:
     void stop();
 
 private:
+    std::auto_ptr<Surface> time_surface;
     bool running;
     float time_left;
 };
index ee86477..f638bca 100644 (file)
@@ -46,7 +46,7 @@ PlayerStatus::PlayerStatus()
 {
   reset();
 
-  tux_life.reset(sprite_manager->create("images/creatures/tux_small/tux-life.sprite"));
+  coin_surface.reset(new Surface("images/engine/hud/coins-0.png"));
 
   Console::instance->registerCommand("coins", this);
 }
@@ -132,16 +132,29 @@ PlayerStatus::read(const lisp::Lisp& lisp)
 void
 PlayerStatus::draw(DrawingContext& context)
 {
+  static int displayed_coins = -1;
+  static int next_count = 0;
+
+  if (displayed_coins == -1) displayed_coins = coins;
+  if (++next_count > 2) {
+    next_count = 0;
+    if (displayed_coins < coins) displayed_coins++;
+    if (displayed_coins > coins) displayed_coins--;
+  }
+  displayed_coins = std::min(std::max(displayed_coins, 0), 9999);
+
+  std::stringstream ss;
+  ss << displayed_coins;
+  std::string coins_text = ss.str();
+
   context.push_transform();
   context.set_translation(Vector(0, 0));
 
-  char str[60];
-
-  int displayCoins = std::max(player_status->coins, 0);
-  snprintf(str, sizeof(str), "%d", displayCoins);
-  const char* coinstext = _("COINS");
-  context.draw_text(white_text, coinstext, Vector(SCREEN_WIDTH - white_text->get_text_width(coinstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y), LEFT_ALLIGN, LAYER_FOREGROUND1);
-  context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), RIGHT_ALLIGN, LAYER_FOREGROUND1);
+  Surface* coin_surf = coin_surface.get();
+  if (coin_surf) {
+    context.draw_surface(coin_surf, Vector(SCREEN_WIDTH - BORDER_X - coin_surf->get_width() - gold_text->get_text_width(coins_text), BORDER_Y + 1), LAYER_FOREGROUND1); 
+  }
+  context.draw_text(gold_text, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), RIGHT_ALLIGN, LAYER_FOREGROUND1);
 
   context.pop_transform();
 }
index 1559725..bf5cc27 100644 (file)
@@ -27,6 +27,7 @@
 #include "serializable.hpp"
 #include "sprite/sprite.hpp"
 #include "console.hpp"
+#include "video/surface.hpp"
 
 static const float BORDER_X = 10;
 static const float BORDER_Y = 10;
@@ -69,7 +70,7 @@ private:
   // don't use this
   PlayerStatus(const PlayerStatus& other);
 
-  std::auto_ptr<Sprite> tux_life;
+  std::auto_ptr<Surface> coin_surface;
 };
 
 // global player state