4 // Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
5 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "lisp/writer.hpp"
23 #include "lisp/lisp.hpp"
24 #include "player_status.hpp"
25 #include "resources.hpp"
26 #include "gettext.hpp"
27 #include "video/drawing_context.hpp"
28 #include "audio/sound_manager.hpp"
29 #include "sprite/sprite_manager.hpp"
30 #include "math/vector.hpp"
34 static const int START_COINS = 100;
35 static const int MAX_COINS = 99999;
37 PlayerStatus* player_status = 0;
39 PlayerStatus::PlayerStatus()
45 max_score_multiplier(1)
49 tux_life.reset(sprite_manager->create("images/creatures/tux_small/tux-life.sprite"));
51 Console::instance->registerCommand("coins", this);
54 PlayerStatus::~PlayerStatus()
58 void PlayerStatus::reset()
63 max_score_multiplier = 1;
67 PlayerStatus::add_coins(int count, bool play_sound)
69 coins = std::min(coins + count, MAX_COINS);
72 sound_manager->play("sounds/lifeup.wav");
74 sound_manager->play("sounds/coin.wav");
79 PlayerStatus::write(lisp::Writer& writer)
83 writer.write_string("bonus", "none");
86 writer.write_string("bonus", "growup");
89 writer.write_string("bonus", "fireflower");
92 writer.write_string("bonus", "iceflower");
95 log_warning << "Unknown bonus type." << std::endl;
96 writer.write_string("bonus", "none");
98 writer.write_int("fireflowers", max_fire_bullets);
99 writer.write_int("iceflowers", max_ice_bullets);
101 writer.write_int("coins", coins);
102 writer.write_int("max-score-multiplier", max_score_multiplier);
106 PlayerStatus::read(const lisp::Lisp& lisp)
110 std::string bonusname;
111 if(lisp.get("bonus", bonusname)) {
112 if(bonusname == "none") {
114 } else if(bonusname == "growup") {
115 bonus = GROWUP_BONUS;
116 } else if(bonusname == "fireflower") {
118 } else if(bonusname == "iceflower") {
121 log_warning << "Unknown bonus '" << bonusname << "' in savefile" << std::endl;
125 lisp.get("fireflowers", max_fire_bullets);
126 lisp.get("iceflowers", max_ice_bullets);
128 lisp.get("coins", coins);
129 lisp.get("max-score-multiplier", max_score_multiplier);
133 PlayerStatus::draw(DrawingContext& context)
135 context.push_transform();
136 context.set_translation(Vector(0, 0));
140 int displayCoins = std::max(player_status->coins, 0);
141 snprintf(str, sizeof(str), "%d", displayCoins);
142 const char* coinstext = _("COINS");
143 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);
144 context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y), RIGHT_ALLIGN, LAYER_FOREGROUND1);
146 context.pop_transform();
150 PlayerStatus::operator= (const PlayerStatus& other)
154 score_multiplier = other.score_multiplier;
155 max_score_multiplier = other.max_score_multiplier;
159 PlayerStatus::consoleCommand(std::string command, std::vector<std::string> arguments)
161 if (command == "coins") {
162 if ((arguments.size() < 1) || (!Console::string_is<int>(arguments[0]))) {
163 log_info << "Usage: coins <number>" << std::endl;
165 coins = Console::string_to<int>(arguments[0]);