From: Ingo Ruhnke Date: Tue, 20 Apr 2004 16:26:08 +0000 (+0000) Subject: - moved joystick mappings into a struct X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1e9cfc896f81063fddb2b04474c5bbee63f778a7;p=supertux.git - moved joystick mappings into a struct SVN-Revision: 593 --- diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 809d9bbd4..02b717b28 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -280,14 +280,14 @@ GameSession::process_events() break; case SDL_JOYAXISMOTION: - if (event.jaxis.axis == JOY_X) + if (event.jaxis.axis == joystick_keymap.x_axis) { - if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) + if (event.jaxis.value < -joystick_keymap.dead_zone) { tux.input.left = DOWN; tux.input.right = UP; } - else if (event.jaxis.value > JOYSTICK_DEAD_ZONE) + else if (event.jaxis.value > joystick_keymap.dead_zone) { tux.input.left = UP; tux.input.right = DOWN; @@ -298,11 +298,11 @@ GameSession::process_events() tux.input.right = DOWN; } } - else if (event.jaxis.axis == JOY_Y) + else if (event.jaxis.axis == joystick_keymap.y_axis) { - if (event.jaxis.value > JOYSTICK_DEAD_ZONE) + if (event.jaxis.value > joystick_keymap.dead_zone) tux.input.down = DOWN; - else if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) + else if (event.jaxis.value < -joystick_keymap.dead_zone) tux.input.down = UP; else tux.input.down = UP; @@ -310,17 +310,17 @@ GameSession::process_events() break; case SDL_JOYBUTTONDOWN: - if (event.jbutton.button == JOY_A) + if (event.jbutton.button == joystick_keymap.a_button) tux.input.up = DOWN; - else if (event.jbutton.button == JOY_B) + else if (event.jbutton.button == joystick_keymap.b_button) tux.input.fire = DOWN; - else if (event.jbutton.button == JOY_START) + else if (event.jbutton.button == joystick_keymap.start_button) on_escape_press(); break; case SDL_JOYBUTTONUP: - if (event.jbutton.button == JOY_A) + if (event.jbutton.button == joystick_keymap.a_button) tux.input.up = UP; - else if (event.jbutton.button == JOY_B) + else if (event.jbutton.button == joystick_keymap.b_button) tux.input.fire = UP; break; diff --git a/src/globals.cpp b/src/globals.cpp index 76606205d..5809b4b35 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -23,12 +23,19 @@ /** The datadir prefix prepended when loading game data file */ std::string datadir; -int JOY_A = 0; -int JOY_B = 1; -int JOY_START = 9; +JoystickKeymap::JoystickKeymap() +{ + a_button = 0; + b_button = 1; + start_button = 9; + + x_axis = 0; + y_axis = 1; + + dead_zone = 4096; +} -int JOY_X = 0; -int JOY_Y = 1; +JoystickKeymap joystick_keymap; SDL_Surface * screen; Text* black_text; @@ -47,7 +54,7 @@ bool use_joystick; bool use_fullscreen; bool debug_mode; bool show_fps; -float game_speed = 1.0f; +float game_speed = 1.2f; int joystick_num = 0; char* level_startup_file = 0; diff --git a/src/globals.h b/src/globals.h index d80e8cff4..d9d82cdc3 100644 --- a/src/globals.h +++ b/src/globals.h @@ -30,13 +30,21 @@ extern std::string datadir; -/* Joystick buttons and axes: */ -extern int JOY_A; -extern int JOY_B; -extern int JOY_START; +struct JoystickKeymap +{ + int a_button; + int b_button; + int start_button; -extern int JOY_X; -extern int JOY_Y; + int x_axis; + int y_axis; + + int dead_zone; + + JoystickKeymap(); +}; + +extern JoystickKeymap joystick_keymap; extern SDL_Surface * screen; extern Text* black_text; @@ -70,6 +78,4 @@ extern SDL_Joystick * js; int wait_for_event(SDL_Event& event,unsigned int min_delay = 0, unsigned int max_delay = 0, bool empty_events = false); -#define JOYSTICK_DEAD_ZONE 4096 - #endif /* SUPERTUX_GLOBALS_H */ diff --git a/src/menu.cpp b/src/menu.cpp index 841fdbe61..14834c1b8 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -634,7 +634,7 @@ Menu::event(SDL_Event& event) } break; case SDL_JOYAXISMOTION: - if(event.jaxis.axis == JOY_Y) + if(event.jaxis.axis == joystick_keymap.y_axis) { if (event.jaxis.value > 1024) menuaction = MENU_ACTION_DOWN; diff --git a/src/player.cpp b/src/player.cpp index b3e1831ec..5018a6176 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -59,6 +59,17 @@ Surface* cape_left[2]; Surface* bigcape_right[2]; Surface* bigcape_left[2]; +PlayerKeymap keymap; + +PlayerKeymap::PlayerKeymap() +{ + keymap.jump = SDLK_UP; + keymap.duck = SDLK_DOWN; + keymap.left = SDLK_LEFT; + keymap.right = SDLK_RIGHT; + keymap.fire = SDLK_LCTRL; +} + void player_input_init(player_input_type* pplayer_input) { pplayer_input->down = UP; @@ -96,12 +107,6 @@ Player::init() player_input_init(&input); - keymap.jump = SDLK_UP; - keymap.duck = SDLK_DOWN; - keymap.left = SDLK_LEFT; - keymap.right = SDLK_RIGHT; - keymap.fire = SDLK_LCTRL; - invincible_timer.init(true); skidding_timer.init(true); safe_timer.init(true); diff --git a/src/player.h b/src/player.h index 524e4d871..2d63f43f7 100644 --- a/src/player.h +++ b/src/player.h @@ -46,13 +46,16 @@ #include -struct player_keymap_type +struct PlayerKeymap { +public: int jump; int duck; int left; int right; int fire; + + PlayerKeymap(); }; struct player_input_type @@ -101,9 +104,7 @@ extern Surface* bigcape_left[2]; class Player { - public: - player_keymap_type keymap; - +public: player_input_type input; bool got_coffee; int size; @@ -123,7 +124,7 @@ class Player Timer frame_timer; Physic physic; - public: +public: void init(); int key_event(SDLKey key, int state); void level_begin(); @@ -140,10 +141,14 @@ class Player bool on_ground(); bool under_solid(); - private: +private: void handle_horizontal_input(); void handle_vertical_input(); void remove_powerups(); }; #endif /*SUPERTUX_PLAYER_H*/ + +/* Local Variables: */ +/* mode:c++ */ +/* End: */ diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 1cadbc18f..f78b3a20f 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -408,26 +408,26 @@ WorldMap::get_input() break; case SDL_JOYAXISMOTION: - if (event.jaxis.axis == JOY_X) + if (event.jaxis.axis == joystick_keymap.x_axis) { - if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) + if (event.jaxis.value < -joystick_keymap.dead_zone) input_direction = WEST; - else if (event.jaxis.value > JOYSTICK_DEAD_ZONE) + else if (event.jaxis.value > joystick_keymap.dead_zone) input_direction = EAST; } - else if (event.jaxis.axis == JOY_Y) + else if (event.jaxis.axis == joystick_keymap.y_axis) { - if (event.jaxis.value > JOYSTICK_DEAD_ZONE) + if (event.jaxis.value > joystick_keymap.dead_zone) input_direction = SOUTH; - else if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) + else if (event.jaxis.value < -joystick_keymap.dead_zone) input_direction = NORTH; } break; case SDL_JOYBUTTONDOWN: - if (event.jbutton.button == JOY_B) + if (event.jbutton.button == joystick_keymap.b_button) enter_level = true; - else if (event.jbutton.button == JOY_START) + else if (event.jbutton.button == joystick_keymap.start_button) on_escape_press(); break;