// $Id$
//
-// SuperTux - A Jump'n Run
+// SuperTux
// Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
+// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
#include "sprite/sprite_manager.hpp"
#include "math/vector.hpp"
#include "main.hpp"
-#include "msg.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 = 0;
PlayerStatus::PlayerStatus()
- : coins(0),
- lives(START_LIVES),
+ : coins(START_COINS),
bonus(NO_BONUS),
score_multiplier(1),
max_score_multiplier(1)
{
reset();
- key_brass = sprite_manager->create("images/objects/keys/key_brass.sprite");
- key_iron = sprite_manager->create("images/objects/keys/key_iron.sprite");
- key_bronze = sprite_manager->create("images/objects/keys/key_bronze.sprite");
- key_silver = sprite_manager->create("images/objects/keys/key_silver.sprite");
- key_gold = sprite_manager->create("images/objects/keys/key_gold.sprite");
+ key_brass.reset(sprite_manager->create("images/objects/keys/key_brass.sprite"));
+ key_iron.reset(sprite_manager->create("images/objects/keys/key_iron.sprite"));
+ key_bronze.reset(sprite_manager->create("images/objects/keys/key_bronze.sprite"));
+ key_silver.reset(sprite_manager->create("images/objects/keys/key_silver.sprite"));
+ key_gold.reset(sprite_manager->create("images/objects/keys/key_gold.sprite"));
key_brass->set_action("outline");
key_iron->set_action("outline");
key_bronze->set_action("outline");
key_silver->set_action("outline");
key_gold->set_action("outline");
+
+ tux_life.reset(sprite_manager->create("images/creatures/tux_small/tux-life.sprite"));
+
+ Console::instance->registerCommand("coins", this);
}
PlayerStatus::~PlayerStatus()
{
- delete key_brass;
- delete key_iron;
- delete key_bronze;
- delete key_silver;
- delete key_gold;
}
void PlayerStatus::reset()
{
- coins = 0;
+ coins = START_COINS;
keys = 0;
- lives = START_LIVES;
bonus = NO_BONUS;
score_multiplier = 1;
max_score_multiplier = 1;
}
void
-PlayerStatus::incLives()
-{
- if(lives < MAX_LIVES)
- ++lives;
- sound_manager->play("sounds/lifeup.wav");
-}
-
-void
-PlayerStatus::incCoins()
+PlayerStatus::add_coins(int count)
{
- coins++;
- if(coins >= 100) {
- incLives();
- coins = 0;
- }
- sound_manager->play("sounds/coin.wav");
+ coins = std::min(coins + count, MAX_COINS);
+ if(count > 100)
+ sound_manager->play("sounds/lifeup.wav");
+ else
+ sound_manager->play("sounds/coin.wav");
}
void
writer.write_string("bonus", "iceflower");
break;
default:
- msg_warning("Unknown bonus type.");
+ log_warning << "Unknown bonus type." << std::endl;
writer.write_string("bonus", "none");
}
writer.write_bool("key-brass", keys & KEY_BRASS);
writer.write_bool("key-silver", keys & KEY_SILVER);
writer.write_bool("key-gold", keys & KEY_GOLD);
- writer.write_int("lives", lives);
writer.write_int("coins", coins);
writer.write_int("max-score-multiplier", max_score_multiplier);
}
} else if(bonusname == "iceflower") {
bonus = ICE_BONUS;
} else {
- msg_warning("Unknown bonus '" << bonusname << "' in savefile");
+ log_warning << "Unknown bonus '" << bonusname << "' in savefile" << std::endl;
bonus = NO_BONUS;
}
}
if(lisp.get("key-gold", val) && val == true)
set_keys(KEY_GOLD);
- lisp.get("lives", lives);
lisp.get("coins", coins);
lisp.get("max-score-multiplier", max_score_multiplier);
}
context.set_translation(Vector(0, 0));
char str[60];
-
- sprintf(str, " %d", player_status->coins);
+
+ int displayCoins = std::max(player_status->coins, 0);
+ sprintf(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") - BORDER_X, BORDER_Y),
- LEFT_ALLIGN, LAYER_FOREGROUND1);
- context.draw_text(gold_text, str,
- Vector(SCREEN_WIDTH - gold_text->get_text_width(" 99") - BORDER_X, BORDER_Y),
- 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->get_width();
- context.draw_text(gold_text, str, Vector(x - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN,
- LAYER_FOREGROUND1);
- context.draw_surface(tux_life, Vector(SCREEN_WIDTH - 16 - BORDER_X, BORDER_Y + 20),
- LAYER_FOREGROUND1);
- } else {
- for(int i= 0; i < player_status->lives; ++i)
- context.draw_surface(tux_life,
- Vector(SCREEN_WIDTH - tux_life->get_width()*4 +(tux_life->get_width()*i) - BORDER_X,
- BORDER_Y + 20),
- 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);
- 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") - BORDER_X, BORDER_Y + 20),
- LEFT_ALLIGN, LAYER_FOREGROUND1);
-
draw_keys(context);
context.pop_transform();
PlayerStatus::operator= (const PlayerStatus& other)
{
coins = other.coins;
- lives = other.lives;
bonus = other.bonus;
score_multiplier = other.score_multiplier;
max_score_multiplier = other.max_score_multiplier;
keys = other.keys;
}
+bool
+PlayerStatus::consoleCommand(std::string command, std::vector<std::string> arguments)
+{
+ if (command == "coins") {
+ if ((arguments.size() < 1) || (!Console::string_is<int>(arguments[0]))) {
+ log_info << "Usage: coins <number>" << std::endl;
+ } else {
+ coins = Console::string_to<int>(arguments[0]);
+ }
+ return true;
+ }
+ return false;
+}
+