console = new Console(context);
Console::registerCommandReceiver(this);
- restart_level();
+ restart_level(true);
}
void
-GameSession::restart_level()
+GameSession::restart_level(bool fromBeginning)
{
game_pause = false;
exit_status = ES_NONE;
}
global_stats.set_total_points(TIME_NEEDED_STAT, (time == 0) ? -1 : time);
+ if (fromBeginning) reset_sector="";
if(reset_sector != "") {
currentsector = level->get_sector(reset_sector);
if(!currentsector) {
context.draw_center_text(gold_text, level->get_name(), Vector(0, 160),
LAYER_FOREGROUND1);
- sprintf(str, "TUX x %d", player_status->lives);
+ sprintf(str, "Coins: %d", player_status->coins);
context.draw_text(white_text, str, Vector(SCREEN_WIDTH/2, 210),
CENTER_ALLIGN, LAYER_FOREGROUND1);
}
//TODO: remove (or at least hide) this before release
if (command == "cheats") {
- msg_info("grow, fire, ice, lifeup, numberofthebeast, lifedown, grease,\ninvincible, mortal, shrink, kill, gotoend, flip, finish");
+ msg_info("grow, fire, ice, lifeup, numberofthebeast, lifedown, grease, invincible, mortal, shrink, kill, gotoend, flip, finish");
return true;
- }
+ }
if (currentsector == 0) return false;
Player& tux = *currentsector->player;
return true;
}
if (command == "lifeup") {
- player_status->lives++;
+ player_status->incLives();
return true;
}
if (command == "numberofthebeast") {
- player_status->lives = 55;
+ player_status->coins = 55;
return true;
}
if (command == "lifedown") {
- player_status->lives--;
+ player_status->coins = std::max(player_status->coins-25, 0);
return true;
}
if (command == "grease") {
return true;
}
if (command == "kill") {
- // kill Tux, but without losing a life
- player_status->lives++;
tux.kill(tux.KILL);
return true;
}
return;
} else if (!end_sequence && tux->is_dead()) {
- if (player_status->lives < 0) { // No more lives!?
- exit_status = ES_GAME_OVER;
- } else { // Still has lives, so reset Tux to the levelstart
- restart_level();
+ if (player_status->coins < 0) {
+ // No more coins: restart level from beginning
+ player_status->coins = 0;
+ restart_level(true);
+ } else {
+ // Still has coins: restart level from last reset point
+ restart_level(false);
}
return;
if(config->show_fps) {
char str[60];
snprintf(str, sizeof(str), "%3.1f", fps_fps);
- context.draw_text(white_text, "FPS",
- Vector(SCREEN_WIDTH -
- white_text->get_text_width("FPS ") - BORDER_X, BORDER_Y + 40),
- LEFT_ALLIGN, LAYER_FOREGROUND1);
- context.draw_text(gold_text, str,
- Vector(SCREEN_WIDTH-4*16 - BORDER_X, BORDER_Y + 40),
- LEFT_ALLIGN, LAYER_FOREGROUND1);
+ const char* fpstext = "FPS";
+ context.draw_text(white_text, fpstext, Vector(SCREEN_WIDTH - white_text->get_text_width(fpstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_FOREGROUND1);
+ context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), RIGHT_ALLIGN, LAYER_FOREGROUND1);
}
}
class GameSession : public ConsoleCommandReceiver
{
public:
- enum ExitStatus { ES_NONE, ES_LEVEL_FINISHED, ES_GAME_OVER, ES_LEVEL_ABORT };
+ enum ExitStatus { ES_NONE, ES_LEVEL_FINISHED, /*ES_GAME_OVER,*/ ES_LEVEL_ABORT };
public:
DrawingContext* context;
bool consoleCommand(std::string command); /**< callback from Console; return false if command was unknown, true otherwise */
private:
- void restart_level();
+ void restart_level(bool fromBeginning = true);
void check_end_conditions();
void process_events();
#include "main.hpp"
#include "msg.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)
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;
+ player_status->coins = std::min(player_status->coins+100, MAX_COINS);
sound_manager->play("sounds/lifeup.wav");
}
PlayerStatus::incCoins()
{
coins++;
- if(coins >= 100) {
- incLives();
- coins = 0;
- }
sound_manager->play("sounds/coin.wav");
}
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);
}
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;
void draw_keys(DrawingContext& context);
int coins;
- int lives;
BonusType bonus;
int score_multiplier;
level_finished = false;
/* In case the player's abort the level, keep it using the old
status. But the minimum lives and no bonus. */
- player_status->coins = old_player_status.coins;
- player_status->lives = std::min(old_player_status.lives, player_status->lives);
+ player_status->coins = std::min(old_player_status.coins, player_status->coins);
player_status->bonus = NO_BONUS;
-
break;
+ /*
case GameSession::ES_GAME_OVER:
{
level_finished = false;
- /* draw an end screen */
- /* TODO: in the future, this should make a dialog a la SuperMario, asking
- if the player wants to restart the world map with no score and from
- level 1 */
+ // draw an end screen
+ // TODO: in the future, this should make a dialog a la SuperMario, asking
+ // if the player wants to restart the world map with no score and from
+ // level 1
char str[80];
DrawingContext context;
player_status->reset();
break;
}
+ */
case GameSession::ES_NONE:
assert(false);
// Should never be reached
load_map();
savegame->get("intro-displayed", intro_displayed);
- savegame->get("lives", player_status->lives);
- savegame->get("coins", player_status->coins);
- savegame->get("max-score-multiplier", player_status->max_score_multiplier);
- if (player_status->lives < 0)
- player_status->reset();
const lisp::Lisp* tux_lisp = savegame->get_lisp("tux");
if(tux)
tux_lisp->get("x", p.x);
tux_lisp->get("y", p.y);
tux_lisp->get("back", back_str);
- player_status->read(*tux_lisp);
-
+ player_status->read(*tux_lisp);
+ if (player_status->coins < 0) player_status->reset();
tux->back_direction = string_to_direction(back_str);
tux->set_tile_pos(p);
}
}
else
{
- load_map();
+ load_map();
player_status->reset();
}