From b6e8cce81c0c24e4ed693246ad8e9b14c6c28064 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Tue, 20 Apr 2004 12:24:28 +0000 Subject: [PATCH] - turned joystick defines into variables SVN-Revision: 590 --- src/defines.h | 10 ---------- src/gameloop.cpp | 13 +++++-------- src/globals.cpp | 7 +++++++ src/globals.h | 8 ++++++++ src/worldmap.cpp | 9 ++++----- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/defines.h b/src/defines.h index c86ad5dc4..1116b5cbe 100644 --- a/src/defines.h +++ b/src/defines.h @@ -32,16 +32,6 @@ #define FPS (1000 / 25) - -/* Joystick buttons and axes: */ - -#define JOY_A 0 -#define JOY_B 1 -#define JOY_START 9 - -#define JOY_X 0 -#define JOY_Y 1 - /* Direction (keyboard/joystick) states: */ #define UP 0 diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 4a29e0a37..809d9bbd4 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -280,9 +280,8 @@ GameSession::process_events() break; case SDL_JOYAXISMOTION: - switch(event.jaxis.axis) + if (event.jaxis.axis == JOY_X) { - case JOY_X: if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) { tux.input.left = DOWN; @@ -298,20 +297,18 @@ GameSession::process_events() tux.input.left = DOWN; tux.input.right = DOWN; } - break; - case JOY_Y: + } + else if (event.jaxis.axis == JOY_Y) + { if (event.jaxis.value > JOYSTICK_DEAD_ZONE) tux.input.down = DOWN; else if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) tux.input.down = UP; else tux.input.down = UP; - - break; - default: - break; } break; + case SDL_JOYBUTTONDOWN: if (event.jbutton.button == JOY_A) tux.input.up = DOWN; diff --git a/src/globals.cpp b/src/globals.cpp index b6096d4fd..76606205d 100644 --- a/src/globals.cpp +++ b/src/globals.cpp @@ -23,6 +23,13 @@ /** The datadir prefix prepended when loading game data file */ std::string datadir; +int JOY_A = 0; +int JOY_B = 1; +int JOY_START = 9; + +int JOY_X = 0; +int JOY_Y = 1; + SDL_Surface * screen; Text* black_text; Text* gold_text; diff --git a/src/globals.h b/src/globals.h index d4ee9608c..d80e8cff4 100644 --- a/src/globals.h +++ b/src/globals.h @@ -30,6 +30,14 @@ extern std::string datadir; +/* Joystick buttons and axes: */ +extern int JOY_A; +extern int JOY_B; +extern int JOY_START; + +extern int JOY_X; +extern int JOY_Y; + extern SDL_Surface * screen; extern Text* black_text; extern Text* gold_text; diff --git a/src/worldmap.cpp b/src/worldmap.cpp index cd460ace8..1cadbc18f 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -408,20 +408,19 @@ WorldMap::get_input() break; case SDL_JOYAXISMOTION: - switch(event.jaxis.axis) + if (event.jaxis.axis == JOY_X) { - case JOY_X: if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) input_direction = WEST; else if (event.jaxis.value > JOYSTICK_DEAD_ZONE) input_direction = EAST; - break; - case JOY_Y: + } + else if (event.jaxis.axis == JOY_Y) + { if (event.jaxis.value > JOYSTICK_DEAD_ZONE) input_direction = SOUTH; else if (event.jaxis.value < -JOYSTICK_DEAD_ZONE) input_direction = NORTH; - break; } break; -- 2.11.0