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"
29 static const int START_LIVES = 4;
30 static const int MAX_LIVES = 99;
32 PlayerStatus player_status;
34 PlayerStatus::PlayerStatus()
39 max_score_multiplier(1)
43 void PlayerStatus::reset()
49 max_score_multiplier = 1;
53 PlayerStatus::incLives()
57 sound_manager->play_sound("lifeup");
61 PlayerStatus::incCoins()
68 sound_manager->play_sound("coin");
72 PlayerStatus::write(lisp::Writer& writer)
76 writer.write_string("bonus", "none");
79 writer.write_string("bonus", "growup");
82 writer.write_string("bonus", "fireflower");
85 writer.write_string("bonus", "iceflower");
88 std::cerr << "Unknown bonus type.\n";
89 writer.write_string("bonus", "none");
92 writer.write_int("lives", lives);
93 writer.write_int("coins", coins);
94 writer.write_int("max-score-multiplier", max_score_multiplier);
98 PlayerStatus::read(const lisp::Lisp& lisp)
102 std::string bonusname;
103 if(lisp.get("bonus", bonusname)) {
104 if(bonusname == "none") {
106 } else if(bonusname == "growup") {
107 bonus = GROWUP_BONUS;
108 } else if(bonusname == "fireflower") {
110 } else if(bonusname == "iceflower") {
113 std::cerr << "Unknown bonus '" << bonusname << "' in savefile.\n";
118 lisp.get("lives", lives);
119 lisp.get("coins", coins);
120 lisp.get("max-score-multiplier", max_score_multiplier);
124 PlayerStatus::draw(DrawingContext& context)
126 context.push_transform();
127 context.set_translation(Vector(0, 0));
131 sprintf(str, " %d", player_status.coins);
132 const char* coinstext = _("COINS");
133 context.draw_text(white_text, coinstext,
134 Vector(SCREEN_WIDTH - white_text->get_text_width(coinstext)
135 - white_text->get_text_width(" 99"), 0),
136 LEFT_ALLIGN, LAYER_FOREGROUND1);
137 context.draw_text(gold_text, str,
138 Vector(SCREEN_WIDTH - gold_text->get_text_width(" 99"), 0),
139 LEFT_ALLIGN, LAYER_FOREGROUND1);
141 if (player_status.lives >= 5) {
142 sprintf(str, "%dx", player_status.lives);
143 float x = SCREEN_WIDTH - gold_text->get_text_width(str) - tux_life->w;
144 context.draw_text(gold_text, str, Vector(x, 20), LEFT_ALLIGN,
146 context.draw_surface(tux_life, Vector(SCREEN_WIDTH - 16, 20),
149 for(int i= 0; i < player_status.lives; ++i)
150 context.draw_surface(tux_life,
151 Vector(SCREEN_WIDTH - tux_life->w*4 +(tux_life->w*i), 20),
155 const char* livestext = _("LIVES");
156 context.draw_text(white_text, livestext,
157 Vector(SCREEN_WIDTH - white_text->get_text_width(livestext)
158 - white_text->get_text_width(" 99"), 20),
159 LEFT_ALLIGN, LAYER_FOREGROUND1);
161 context.pop_transform();