From: Wolfgang Becker Date: Sat, 20 Jan 2007 18:07:18 +0000 (+0000) Subject: Set a speed limit for Tux. Used at the endsequence and for the title ATM. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=a1bbd50a338ffcda9933848e20bb1de344f25104;p=supertux.git Set a speed limit for Tux. Used at the endsequence and for the title ATM. SVN-Revision: 4613 --- diff --git a/src/object/endsequence.cpp b/src/object/endsequence.cpp index 3a56cac46..dac0b8f5c 100644 --- a/src/object/endsequence.cpp +++ b/src/object/endsequence.cpp @@ -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(); } diff --git a/src/object/player.cpp b/src/object/player.cpp index ea2fedfeb..12e750f86 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -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! diff --git a/src/object/player.hpp b/src/object/player.hpp index fec7007cb..ce94e29e0 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -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; diff --git a/src/title.cpp b/src/title.cpp index 08259e870..c82b485ed 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -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);