X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fplayer_status.cpp;h=84925da0cc5495b84a89605c4139fbf9939a2ba0;hb=7a0031e8f250c852743709ab06ecafe1896eefbe;hp=1f233bd4bf32a2c784eb9ffe1b2b77705f08bcaf;hpb=a983f6648d43492632c41e2b7519b70458b53cf4;p=supertux.git diff --git a/src/player_status.cpp b/src/player_status.cpp index 1f233bd4b..84925da0c 100644 --- a/src/player_status.cpp +++ b/src/player_status.cpp @@ -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,6 +49,8 @@ PlayerStatus::PlayerStatus() reset(); coin_surface.reset(new Surface("images/engine/hud/coins-0.png")); + sound_manager->preload("sounds/coin.wav"); + sound_manager->preload("sounds/lifeup.wav"); } PlayerStatus::~PlayerStatus() @@ -65,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; + } } } @@ -153,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() - fixed_font->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(fixed_font, coins_text, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), ALIGN_RIGHT, LAYER_HUD, PlayerStatus::text_color); context.pop_transform(); }