Set a speed limit for Tux. Used at the endsequence and for the title ATM.
authorWolfgang Becker <uafr@gmx.de>
Sat, 20 Jan 2007 18:07:18 +0000 (18:07 +0000)
committerWolfgang Becker <uafr@gmx.de>
Sat, 20 Jan 2007 18:07:18 +0000 (18:07 +0000)
SVN-Revision: 4613

src/object/endsequence.cpp
src/object/player.cpp
src/object/player.hpp
src/title.cpp

index 3a56cac..dac0b8f 100644 (file)
@@ -69,6 +69,7 @@ EndSequence::start()
   Player& tux = *Sector::current()->player;
   end_sequence_controller = new CodeController();
   tux.set_controller(end_sequence_controller);
+  tux.set_speedlimit(230); //MAX_WALK_XM
 
   starting();
 }
index ea2fedf..12e750f 100644 (file)
@@ -162,6 +162,7 @@ Player::init()
   backflip_direction = 0;
   visible = true;
   swimming = false;
+  speedlimit = 0; //no special limit
 
   on_ground_flag = false;
   grabbed_object = NULL;
@@ -187,6 +188,18 @@ Player::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
   Scripting::unexpose_object(vm, table_idx, name);
 }
 
+float
+Player::get_speedlimit()
+{
+  return speedlimit;
+}
+
+void
+Player::set_speedlimit(float newlimit)
+{
+  speedlimit=newlimit; 
+}
+
 void
 Player::set_controller(Controller* controller)
 {
@@ -412,6 +425,12 @@ Player::handle_horizontal_input()
     vx = dirsign * WALK_SPEED;
   }
 
+  //Check speedlimit.
+  if( speedlimit > 0 &&  vx * dirsign >= speedlimit ) {
+      vx = dirsign * speedlimit;
+      ax = 0;
+  }
+
   // changing directions?
   if(on_ground() && ((vx < 0 && dirsign >0) || (vx>0 && dirsign<0))) {
     // let's skid!
index fec7007..ce94e29 100644 (file)
@@ -90,6 +90,9 @@ public:
   PlayerStatus* player_status;
   bool duck;
   bool dead;
+  //Tux can only go this fast. If set to 0 no special limit is used, only the default limits.   
+  void set_speedlimit(float newlimit); 
+  float get_speedlimit();
 
 private:
   bool dying;
@@ -97,6 +100,7 @@ private:
   int  backflip_direction;
   Direction peeking;
   bool swimming;
+  float speedlimit;
 
 public:
   Direction dir;
index 08259e8..c82b485 100644 (file)
@@ -267,6 +267,7 @@ TitleScreen::TitleScreen()
 
   Player* player = titlesession->get_current_sector()->player;
   player->set_controller(controller.get());
+  player->set_speedlimit(230); //MAX_WALK_XM
 
   main_menu.reset(new Menu());
   main_menu->set_pos(SCREEN_WIDTH/2, 335);