X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fplayer_status.cpp;h=95f994e71451c6869e19a71f8a99fd31627b6e21;hb=4a486d92343d1824b311c234e9321e08f280fe68;hp=ba8b633c7776136cfb014df766773c00a81902f1;hpb=9599042661b468aae7bd34dca05441c0ebc93ad7;p=supertux.git diff --git a/src/player_status.cpp b/src/player_status.cpp index ba8b633c7..95f994e71 100644 --- a/src/player_status.cpp +++ b/src/player_status.cpp @@ -1,7 +1,8 @@ // $Id$ // -// SuperTux - A Jump'n Run +// SuperTux // Copyright (C) 2003 Tobias Glaesser +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -18,73 +19,86 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include -#include "lisp/writer.h" -#include "lisp/lisp.h" -#include "player_status.h" -#include "resources.h" +#include "lisp/writer.hpp" +#include "lisp/lisp.hpp" +#include "player_status.hpp" +#include "resources.hpp" +#include "gettext.hpp" +#include "video/drawing_context.hpp" +#include "audio/sound_manager.hpp" +#include "sprite/sprite_manager.hpp" +#include "math/vector.hpp" +#include "main.hpp" +#include "log.hpp" -static const int START_LIVES = 4; -static const int MAX_LIVES = 99; +static const int START_COINS = 100; +static const int MAX_COINS = 99999; -PlayerStatus player_status; +PlayerStatus* player_status = 0; PlayerStatus::PlayerStatus() - : distros(0), - lives(START_LIVES), + : coins(START_COINS), bonus(NO_BONUS), + max_fire_bullets(0), + max_ice_bullets(0), score_multiplier(1), max_score_multiplier(1) { + reset(); + + coin_surface.reset(new Surface("images/engine/hud/coins-0.png")); + + Console::instance->registerCommand("coins", this); +} + +PlayerStatus::~PlayerStatus() +{ } void PlayerStatus::reset() { - distros = 0; - lives = START_LIVES; + coins = START_COINS; bonus = NO_BONUS; score_multiplier = 1; max_score_multiplier = 1; } void -PlayerStatus::incLives() -{ - if(lives < MAX_LIVES) - ++lives; - SoundManager::get()->play_sound(IDToSound(SND_LIFEUP)); -} - -void -PlayerStatus::incCoins() +PlayerStatus::add_coins(int count, bool play_sound) { - distros++; - if(distros >= 100) { - incLives(); - distros = 0; + coins = std::min(coins + count, MAX_COINS); + if(play_sound) { + if(count >= 100) + sound_manager->play("sounds/lifeup.wav"); + else + sound_manager->play("sounds/coin.wav"); } - SoundManager::get()->play_sound(IDToSound(SND_DISTRO)); } void PlayerStatus::write(lisp::Writer& writer) { switch(bonus) { - case PlayerStatus::NO_BONUS: + case NO_BONUS: writer.write_string("bonus", "none"); break; - case PlayerStatus::GROWUP_BONUS: + case GROWUP_BONUS: writer.write_string("bonus", "growup"); break; - case PlayerStatus::FLOWER_BONUS: + case FIRE_BONUS: writer.write_string("bonus", "fireflower"); break; + case ICE_BONUS: + writer.write_string("bonus", "iceflower"); + break; default: - std::cerr << "Unknown bonus type.\n"; + log_warning << "Unknown bonus type." << std::endl; writer.write_string("bonus", "none"); } + writer.write_int("fireflowers", max_fire_bullets); + writer.write_int("iceflowers", max_ice_bullets); - writer.write_int("lives", lives); - writer.write_int("distros", distros); + writer.write_int("coins", coins); writer.write_int("max-score-multiplier", max_score_multiplier); } @@ -92,7 +106,7 @@ void PlayerStatus::read(const lisp::Lisp& lisp) { reset(); - + std::string bonusname; if(lisp.get("bonus", bonusname)) { if(bonusname == "none") { @@ -100,15 +114,70 @@ PlayerStatus::read(const lisp::Lisp& lisp) } else if(bonusname == "growup") { bonus = GROWUP_BONUS; } else if(bonusname == "fireflower") { - bonus = FLOWER_BONUS; + bonus = FIRE_BONUS; + } else if(bonusname == "iceflower") { + bonus = ICE_BONUS; } else { - std::cerr << "Unknown bonus '" << bonusname << "' in savefile.\n"; + log_warning << "Unknown bonus '" << bonusname << "' in savefile" << std::endl; bonus = NO_BONUS; } } + lisp.get("fireflowers", max_fire_bullets); + lisp.get("iceflowers", max_ice_bullets); - lisp.get("lives", lives); - lisp.get("distros", distros); + lisp.get("coins", coins); lisp.get("max-score-multiplier", max_score_multiplier); } +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)); + + 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(); +} + +void +PlayerStatus::operator= (const PlayerStatus& other) +{ + coins = other.coins; + bonus = other.bonus; + score_multiplier = other.score_multiplier; + max_score_multiplier = other.max_score_multiplier; +} + +bool +PlayerStatus::consoleCommand(std::string command, std::vector arguments) +{ + if (command == "coins") { + if ((arguments.size() < 1) || (!Console::string_is(arguments[0]))) { + log_info << "Usage: coins " << std::endl; + } else { + coins = Console::string_to(arguments[0]); + } + return true; + } + return false; +}