X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fplayer_status.cpp;h=f39ded0e8ca31f756b911f2b57f15b2c82365480;hb=d84d73b701cc7fa2bd74f3490b9be1bf8b6f705a;hp=c953d920dc653e47b077643e47335f1da8b9ba0b;hpb=795f0b283fcb1c8777723dc1cc850826d39c6806;p=supertux.git diff --git a/src/player_status.cpp b/src/player_status.cpp index c953d920d..f39ded0e8 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,55 +19,60 @@ // 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 "gettext.h" -#include "video/drawing_context.h" -#include "audio/sound_manager.h" -#include "main.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() - : coins(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(); + + tux_life.reset(sprite_manager->create("images/creatures/tux_small/tux-life.sprite")); + + Console::instance->registerCommand("coins", this); +} + +PlayerStatus::~PlayerStatus() +{ } void PlayerStatus::reset() { - coins = 0; - lives = START_LIVES; + coins = START_COINS; bonus = NO_BONUS; score_multiplier = 1; max_score_multiplier = 1; } void -PlayerStatus::incLives() +PlayerStatus::add_coins(int count, bool play_sound) { - if(lives < MAX_LIVES) - ++lives; - sound_manager->play("lifeup"); -} - -void -PlayerStatus::incCoins() -{ - coins++; - if(coins >= 100) { - incLives(); - coins = 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"); } - sound_manager->play("coin"); } void @@ -86,11 +92,12 @@ PlayerStatus::write(lisp::Writer& writer) 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("lives", lives); + writer.write_int("fireflowers", max_fire_bullets); + writer.write_int("iceflowers", max_ice_bullets); + writer.write_int("coins", coins); writer.write_int("max-score-multiplier", max_score_multiplier); } @@ -111,12 +118,13 @@ PlayerStatus::read(const lisp::Lisp& lisp) } 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("coins", coins); lisp.get("max-score-multiplier", max_score_multiplier); } @@ -128,36 +136,36 @@ PlayerStatus::draw(DrawingContext& context) context.set_translation(Vector(0, 0)); char str[60]; - - sprintf(str, " %d", player_status.coins); + + 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) - - white_text->get_text_width(" 99"), 0), - LEFT_ALLIGN, LAYER_FOREGROUND1); - context.draw_text(gold_text, str, - Vector(SCREEN_WIDTH - gold_text->get_text_width(" 99"), 0), - LEFT_ALLIGN, LAYER_FOREGROUND1); - - if (player_status.lives >= 5) { - sprintf(str, "%dx", player_status.lives); - float x = SCREEN_WIDTH - gold_text->get_text_width(str) - tux_life->w; - context.draw_text(gold_text, str, Vector(x, 20), LEFT_ALLIGN, - LAYER_FOREGROUND1); - context.draw_surface(tux_life, Vector(SCREEN_WIDTH - 16, 20), - LAYER_FOREGROUND1); - } else { - for(int i= 0; i < player_status.lives; ++i) - context.draw_surface(tux_life, - Vector(SCREEN_WIDTH - tux_life->w*4 +(tux_life->w*i), 20), - LAYER_FOREGROUND1); - } - - const char* livestext = _("LIVES"); - context.draw_text(white_text, livestext, - Vector(SCREEN_WIDTH - white_text->get_text_width(livestext) - - white_text->get_text_width(" 99"), 20), - LEFT_ALLIGN, LAYER_FOREGROUND1); + 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); 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; +} +