From a5eb1a582bf8c975d12293d7e5199a365a7e191b Mon Sep 17 00:00:00 2001 From: Wolfgang Becker Date: Sat, 8 Jul 2006 22:48:47 +0000 Subject: [PATCH] Tux can peek to the left and to the right as far as the camera would move in best case. SVN-Revision: 3960 --- src/control/controller.cpp | 2 ++ src/control/controller.hpp | 2 ++ src/control/joystickkeyboardcontroller.cpp | 43 +++++++++++++++++++++++++----- src/object/camera.cpp | 10 ++++++- src/object/player.cpp | 15 +++++++++++ src/object/player.hpp | 5 ++++ 6 files changed, 69 insertions(+), 8 deletions(-) diff --git a/src/control/controller.cpp b/src/control/controller.cpp index 7cbed0ef3..43f766591 100644 --- a/src/control/controller.cpp +++ b/src/control/controller.cpp @@ -33,6 +33,8 @@ const char* Controller::controlNames[] = { "pause-menu", "menu-select", "console", + "peek-left", + "peek-right", 0 }; diff --git a/src/control/controller.hpp b/src/control/controller.hpp index 37dfa9f8b..deeb8e639 100644 --- a/src/control/controller.hpp +++ b/src/control/controller.hpp @@ -35,6 +35,8 @@ public: PAUSE_MENU, MENU_SELECT, CONSOLE, + PEEK_LEFT, + PEEK_RIGHT, CONTROLCOUNT }; diff --git a/src/control/joystickkeyboardcontroller.cpp b/src/control/joystickkeyboardcontroller.cpp index 931dbfd2e..5fb55820c 100644 --- a/src/control/joystickkeyboardcontroller.cpp +++ b/src/control/joystickkeyboardcontroller.cpp @@ -71,6 +71,8 @@ JoystickKeyboardController::JoystickKeyboardController() keymap.insert(std::make_pair(SDLK_RETURN, MENU_SELECT)); keymap.insert(std::make_pair(SDLK_KP_ENTER, MENU_SELECT)); keymap.insert(std::make_pair(SDLK_CARET, CONSOLE)); + keymap.insert(std::make_pair(SDLK_DELETE, PEEK_LEFT)); + keymap.insert(std::make_pair(SDLK_END, PEEK_RIGHT)); int joystick_count = SDL_NumJoysticks(); min_joybuttons = -1; @@ -109,13 +111,28 @@ JoystickKeyboardController::JoystickKeyboardController() joy_button_map.insert(std::make_pair(0, JUMP)); joy_button_map.insert(std::make_pair(1, ACTION)); - // map the last 2 buttons to menu and pause - if(min_joybuttons > 2) - joy_button_map.insert(std::make_pair(min_joybuttons-1, PAUSE_MENU)); - // map all remaining joystick buttons to MENU_SELECT - for(int i = 2; i < max_joybuttons; ++i) { - if(i != min_joybuttons-1) - joy_button_map.insert(std::make_pair(i, MENU_SELECT)); + // 6 or more Buttons + if( min_joybuttons > 5 ){ + joy_button_map.insert(std::make_pair( 5, PEEK_LEFT)); + joy_button_map.insert(std::make_pair( 6, PEEK_RIGHT)); + // 8 or more + if(min_joybuttons > 7) + joy_button_map.insert(std::make_pair(min_joybuttons-1, PAUSE_MENU)); + // map all remaining joystick buttons to MENU_SELECT + for(int i = 2; i < max_joybuttons; ++i) { + if( i != min_joybuttons-1 && i !=5 && i!= 6 ) + joy_button_map.insert(std::make_pair(i, MENU_SELECT)); + } + + } else { + // map the last 2 buttons to menu and pause + if(min_joybuttons > 2) + joy_button_map.insert(std::make_pair(min_joybuttons-1, PAUSE_MENU)); + // map all remaining joystick buttons to MENU_SELECT + for(int i = 2; i < max_joybuttons; ++i) { + if(i != min_joybuttons-1) + joy_button_map.insert(std::make_pair(i, MENU_SELECT)); + } } // some joysticks or SDL seem to produce some bogus events after being opened @@ -577,6 +594,8 @@ JoystickKeyboardController::KeyboardMenu::KeyboardMenu( add_controlfield(Controller::RIGHT, _("Right")); add_controlfield(Controller::JUMP, _("Jump")); add_controlfield(Controller::ACTION, _("Action")); + add_controlfield(Controller::PEEK_LEFT, _("Peek Left")); + add_controlfield(Controller::PEEK_RIGHT, _("Peek Right")); add_hl(); add_back(_("Back")); update(); @@ -644,6 +663,10 @@ JoystickKeyboardController::KeyboardMenu::update() controller->reversemap_key(Controller::JUMP))); get_item_by_id((int) Controller::ACTION).change_input(get_key_name( controller->reversemap_key(Controller::ACTION))); + get_item_by_id((int) Controller::PEEK_LEFT).change_input(get_key_name( + controller->reversemap_key(Controller::PEEK_LEFT))); + get_item_by_id((int) Controller::PEEK_RIGHT).change_input(get_key_name( + controller->reversemap_key(Controller::PEEK_RIGHT))); } //--------------------------------------------------------------------------- @@ -658,6 +681,8 @@ JoystickKeyboardController::JoystickMenu::JoystickMenu( add_controlfield(Controller::JUMP, _("Jump")); add_controlfield(Controller::ACTION, _("Action")); add_controlfield(Controller::PAUSE_MENU, _("Pause/Menu")); + add_controlfield(Controller::PEEK_LEFT, _("Peek Left")); + add_controlfield(Controller::PEEK_RIGHT, _("Peek Right")); } else { add_deactive(-1, _("No Joysticks found")); } @@ -701,5 +726,9 @@ JoystickKeyboardController::JoystickMenu::update() controller->reversemap_joybutton(Controller::ACTION))); get_item_by_id((int) Controller::PAUSE_MENU).change_input(get_button_name( controller->reversemap_joybutton(Controller::PAUSE_MENU))); + get_item_by_id((int) Controller::PEEK_LEFT).change_input(get_button_name( + controller->reversemap_joybutton(Controller::PEEK_LEFT))); + get_item_by_id((int) Controller::PEEK_RIGHT).change_input(get_button_name( + controller->reversemap_joybutton(Controller::PEEK_RIGHT))); } diff --git a/src/object/camera.cpp b/src/object/camera.cpp index 9c46ca322..a848d2bf5 100644 --- a/src/object/camera.cpp +++ b/src/object/camera.cpp @@ -281,7 +281,15 @@ Camera::update_scroll_normal(float elapsed_time) speed_x = maxv; else if(speed_x < -maxv) speed_x = -maxv; - + + // If player is peeking scroll in that direction. Fast. + if( player->peeking_direction() == ::LEFT ){ + speed_x = maxv; + } + if( player->peeking_direction() == ::RIGHT ){ + speed_x = -maxv; + } + // apply scrolling translation.x -= speed_x * elapsed_time; diff --git a/src/object/player.cpp b/src/object/player.cpp index 23aaf33c8..4aab47f4a 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -144,6 +144,7 @@ Player::init() dead = false; dying = false; + peeking = AUTO; last_ground_y = 0; fall_mode = ON_GROUND; jumping = false; @@ -614,6 +615,20 @@ Player::handle_input() grabbed_object = NULL; } } + + /* Peeking */ + if( controller->released( Controller::PEEK_LEFT ) ) { + peeking = AUTO; + } + if( controller->released( Controller::PEEK_RIGHT ) ) { + peeking = AUTO; + } + if( controller->pressed( Controller::PEEK_LEFT ) ) { + peeking = LEFT; + } + if( controller->pressed( Controller::PEEK_RIGHT ) ) { + peeking = RIGHT; + } /* Handle horizontal movement: */ if (!backflipping) handle_horizontal_input(); diff --git a/src/object/player.hpp b/src/object/player.hpp index 1f69640cf..b7fb3ac26 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -95,6 +95,7 @@ private: bool dying; bool backflipping; int backflip_direction; + Direction peeking; public: Direction dir; @@ -146,6 +147,10 @@ public: { return dying; } + Direction peeking_direction() const + { + return peeking; + } void kill(bool completely); void check_bounds(Camera* camera); -- 2.11.0