{
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
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();
{
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);
}
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();
}
#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;
// don't use this
PlayerStatus(const PlayerStatus& other);
- std::auto_ptr<Sprite> tux_life;
+ std::auto_ptr<Surface> coin_surface;
};
// global player state