* Don't kill Tux after winning a level. (Bug 675)
authorWolfgang Becker <uafr@gmx.de>
Sun, 17 Apr 2011 16:15:43 +0000 (16:15 +0000)
committerWolfgang Becker <uafr@gmx.de>
Sun, 17 Apr 2011 16:15:43 +0000 (16:15 +0000)
* Support for heavy objects which slow Tux down.

SVN-Revision: 6682

src/object/player.cpp
src/object/player.hpp
src/object/portable.hpp
src/supertux/game_session.cpp

index 55ffc00..22b2b4f 100644 (file)
@@ -199,6 +199,7 @@ Player::init()
   dead = false;
 
   dying = false;
+  winning = false;
   peekingX = AUTO;
   peekingY = AUTO;
   last_ground_y = 0;
@@ -262,6 +263,15 @@ Player::set_controller(Controller* controller)
   this->controller = controller;
 }
 
+void
+Player::set_winning()
+{
+  if( ! is_winning() ){
+    winning = true;
+    invincible_timer.start(10000.0f);
+  }
+}
+
 void 
 Player::use_scripting_controller(bool use_or_release)
 {
@@ -480,8 +490,8 @@ Player::handle_horizontal_input()
     }
   }
 
-  // do not run if we're holding something
-  if ( false /* grabbed_extra_heavy_object */) {
+  // do not run if we're holding something which slows us down
+  if ( grabbed_object && grabbed_object->is_hampering() ) {
     ax = dirsign * WALK_ACCELERATION_X;
     // limit speed
     if(vx >= MAX_WALK_XM && dirsign > 0) {
@@ -1258,7 +1268,7 @@ Player::make_invincible()
 void
 Player::kill(bool completely)
 {
-  if(dying || deactivated)
+  if(dying || deactivated || is_winning() )
     return;
 
   if(!completely && (safe_timer.started() || invincible_timer.started()))
index b593455..b54a294 100644 (file)
@@ -62,6 +62,15 @@ public:
   virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
 
   void set_controller(Controller* controller);
+  /*
+   * Level solved. Don't kill Tux any more.
+   */
+  void set_winning();
+  bool is_winning()
+  {
+    return winning;
+  }
+
   Controller* get_controller()
   {
     return controller;
@@ -258,6 +267,7 @@ private:
 
 private:
   bool dying;
+  bool winning;
   bool backflipping;
   int  backflip_direction;
   Direction peekingX;
index 5fbabf4..87b6af3 100644 (file)
@@ -45,6 +45,15 @@ public:
   {
     return true;
   }
+  
+  /**
+   * Is the object so heavy/bulky/fragile that Tux can't run while
+   * carrying it?
+   */
+  virtual bool is_hampering()
+  {
+    return false;
+  }
 };
 
 #endif
index 65db045..56c2a9b 100644 (file)
@@ -578,7 +578,7 @@ GameSession::start_sequence(const std::string& sequencename)
   end_sequence->start();
 
   sound_manager->play_music("music/leveldone.ogg", false);
-  currentsector->player->invincible_timer.start(10000.0f);
+  currentsector->player->set_winning();
 
   // Stop all clocks.
   for(std::vector<GameObject*>::iterator i = currentsector->gameobjects.begin();