3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include "lisp/writer.h"
22 #include "lisp/lisp.h"
23 #include "player_status.h"
24 #include "resources.h"
26 #include "video/drawing_context.h"
27 #include "audio/sound_manager.h"
30 static const int START_LIVES = 4;
31 static const int MAX_LIVES = 99;
33 PlayerStatus player_status;
35 PlayerStatus::PlayerStatus()
40 max_score_multiplier(1)
44 void PlayerStatus::reset()
50 max_score_multiplier = 1;
54 PlayerStatus::incLives()
58 sound_manager->play("lifeup");
62 PlayerStatus::incCoins()
69 sound_manager->play("coin");
73 PlayerStatus::write(lisp::Writer& writer)
77 writer.write_string("bonus", "none");
80 writer.write_string("bonus", "growup");
83 writer.write_string("bonus", "fireflower");
86 writer.write_string("bonus", "iceflower");
89 std::cerr << "Unknown bonus type.\n";
90 writer.write_string("bonus", "none");
93 writer.write_int("lives", lives);
94 writer.write_int("coins", coins);
95 writer.write_int("max-score-multiplier", max_score_multiplier);
99 PlayerStatus::read(const lisp::Lisp& lisp)
103 std::string bonusname;
104 if(lisp.get("bonus", bonusname)) {
105 if(bonusname == "none") {
107 } else if(bonusname == "growup") {
108 bonus = GROWUP_BONUS;
109 } else if(bonusname == "fireflower") {
111 } else if(bonusname == "iceflower") {
114 std::cerr << "Unknown bonus '" << bonusname << "' in savefile.\n";
119 lisp.get("lives", lives);
120 lisp.get("coins", coins);
121 lisp.get("max-score-multiplier", max_score_multiplier);
125 PlayerStatus::draw(DrawingContext& context)
127 context.push_transform();
128 context.set_translation(Vector(0, 0));
132 sprintf(str, " %d", player_status.coins);
133 const char* coinstext = _("COINS");
134 context.draw_text(white_text, coinstext,
135 Vector(SCREEN_WIDTH - white_text->get_text_width(coinstext)
136 - white_text->get_text_width(" 99"), 0),
137 LEFT_ALLIGN, LAYER_FOREGROUND1);
138 context.draw_text(gold_text, str,
139 Vector(SCREEN_WIDTH - gold_text->get_text_width(" 99"), 0),
140 LEFT_ALLIGN, LAYER_FOREGROUND1);
142 if (player_status.lives >= 5) {
143 sprintf(str, "%dx", player_status.lives);
144 float x = SCREEN_WIDTH - gold_text->get_text_width(str) - tux_life->w;
145 context.draw_text(gold_text, str, Vector(x, 20), LEFT_ALLIGN,
147 context.draw_surface(tux_life, Vector(SCREEN_WIDTH - 16, 20),
150 for(int i= 0; i < player_status.lives; ++i)
151 context.draw_surface(tux_life,
152 Vector(SCREEN_WIDTH - tux_life->w*4 +(tux_life->w*i), 20),
156 const char* livestext = _("LIVES");
157 context.draw_text(white_text, livestext,
158 Vector(SCREEN_WIDTH - white_text->get_text_width(livestext)
159 - white_text->get_text_width(" 99"), 20),
160 LEFT_ALLIGN, LAYER_FOREGROUND1);
162 context.pop_transform();