No lives, no gameover, no worries
authorChristoph Sommer <mail@christoph-sommer.de>
Fri, 7 Apr 2006 11:35:50 +0000 (11:35 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Fri, 7 Apr 2006 11:35:50 +0000 (11:35 +0000)
SVN-Revision: 3256

src/game_session.cpp
src/game_session.hpp
src/player_status.cpp
src/player_status.hpp
src/worldmap.cpp

index 1112cad..ac52179 100644 (file)
@@ -92,11 +92,11 @@ GameSession::GameSession(const std::string& levelfile_, GameSessionMode mode,
   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;
@@ -132,6 +132,7 @@ GameSession::restart_level()
   }
   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) {
@@ -228,7 +229,7 @@ GameSession::levelintro()
   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);
 
@@ -349,9 +350,9 @@ GameSession::consoleCommand(std::string command)
   }
   //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;
@@ -371,15 +372,15 @@ GameSession::consoleCommand(std::string command)
     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") {
@@ -402,8 +403,6 @@ GameSession::consoleCommand(std::string command)
     return true;
   }
   if (command == "kill") {
-    // kill Tux, but without losing a life
-    player_status->lives++;
     tux.kill(tux.KILL);
     return true;
   }
@@ -479,10 +478,13 @@ GameSession::check_end_conditions()
 
     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;
@@ -811,13 +813,9 @@ GameSession::drawstatus(DrawingContext& context)
   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);
   }
 }
 
index d2cd2dc..830428d 100644 (file)
@@ -56,7 +56,7 @@ class CodeController;
 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;
@@ -100,7 +100,7 @@ public:
   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();
index 8241b9b..f5c721f 100644 (file)
 #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)
@@ -66,9 +65,8 @@ PlayerStatus::~PlayerStatus()
 
 void PlayerStatus::reset()
 {
-  coins = 0;
+  coins = START_COINS;
   keys = 0;
-  lives = START_LIVES;
   bonus = NO_BONUS;
   score_multiplier = 1;
   max_score_multiplier = 1;
@@ -77,8 +75,7 @@ void PlayerStatus::reset()
 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");
 }
 
@@ -86,10 +83,6 @@ void
 PlayerStatus::incCoins()
 {
   coins++;
-  if(coins >= 100) {
-    incLives();
-    coins = 0;
-  }
   sound_manager->play("sounds/coin.wav");
 }
 
@@ -130,7 +123,6 @@ PlayerStatus::write(lisp::Writer& writer)
   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);
 }
@@ -167,7 +159,6 @@ PlayerStatus::read(const lisp::Lisp& lisp)
   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);
 }
@@ -197,38 +188,13 @@ PlayerStatus::draw(DrawingContext& context)
   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();
@@ -238,7 +204,6 @@ void
 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;
index ce3dee0..29b8f83 100644 (file)
@@ -54,7 +54,6 @@ public:
   void draw_keys(DrawingContext& context);
 
   int  coins;
-  int  lives;
   BonusType bonus;
 
   int score_multiplier;
index a2f3ac0..e7dfc8c 100644 (file)
@@ -811,18 +811,17 @@ WorldMap::update(float delta)
               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;
@@ -847,6 +846,7 @@ WorldMap::update(float delta)
               player_status->reset();
               break;
               }
+           */
             case GameSession::ES_NONE:
               assert(false);
               // Should never be reached 
@@ -1166,11 +1166,6 @@ WorldMap::loadgame(const std::string& filename)
       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)
@@ -1181,8 +1176,8 @@ WorldMap::loadgame(const std::string& filename)
         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);
       }
@@ -1223,7 +1218,7 @@ WorldMap::loadgame(const std::string& filename)
   }
   else
   {
-       load_map();
+    load_map();
     player_status->reset();
   }