Some animation/hitbox fixes
[supertux.git] / src / player_status.cpp
index 44512a1..4bed7df 100644 (file)
@@ -31,6 +31,7 @@
 #include "math/vector.hpp"
 #include "main.hpp"
 #include "log.hpp"
+#include "timer.hpp"
 
 static const int START_COINS = 100;
 static const int MAX_COINS = 99999;
@@ -48,8 +49,8 @@ PlayerStatus::PlayerStatus()
   reset();
 
   coin_surface.reset(new Surface("images/engine/hud/coins-0.png"));
-
-  Console::instance->registerCommand("coins", this);
+  sound_manager->preload("sounds/coin.wav");
+  sound_manager->preload("sounds/lifeup.wav");
 }
 
 PlayerStatus::~PlayerStatus()
@@ -67,12 +68,15 @@ void PlayerStatus::reset()
 void
 PlayerStatus::add_coins(int count, bool play_sound)
 {
+  static float sound_played_time = 0;
   coins = std::min(coins + count, MAX_COINS);
   if(play_sound) {
     if(count >= 100)
       sound_manager->play("sounds/lifeup.wav");
-    else
+    else if (real_time > sound_played_time + 0.010) {
       sound_manager->play("sounds/coin.wav");
+      sound_played_time = real_time;
+    }
   }
 }
 
@@ -155,9 +159,9 @@ PlayerStatus::draw(DrawingContext& context)
 
   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_HUD);
+    context.draw_surface(coin_surf, Vector(SCREEN_WIDTH - BORDER_X - coin_surf->get_width() - gold_fixed_text->get_text_width(coins_text), BORDER_Y + 1), LAYER_HUD);
   }
-  context.draw_text(gold_text, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), RIGHT_ALLIGN, LAYER_HUD);
+  context.draw_text(gold_fixed_text, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), ALIGN_RIGHT, LAYER_HUD);
 
   context.pop_transform();
 }
@@ -170,17 +174,3 @@ PlayerStatus::operator= (const PlayerStatus& other)
   score_multiplier = other.score_multiplier;
   max_score_multiplier = other.max_score_multiplier;
 }
-
-bool
-PlayerStatus::consoleCommand(std::string command, std::vector<std::string> arguments)
-{
-  if (command == "coins") {
-    if ((arguments.size() < 1) || (!Console::string_is<int>(arguments[0]))) {
-      log_info << "Usage: coins <number>" << std::endl;
-    } else {
-      coins = Console::string_to<int>(arguments[0]);
-    }
-    return true;
-  }
-  return false;
-}