- moved joystick mappings into a struct
authorIngo Ruhnke <grumbel@gmx.de>
Tue, 20 Apr 2004 16:26:08 +0000 (16:26 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Tue, 20 Apr 2004 16:26:08 +0000 (16:26 +0000)
SVN-Revision: 593

src/gameloop.cpp
src/globals.cpp
src/globals.h
src/menu.cpp
src/player.cpp
src/player.h
src/worldmap.cpp

index 809d9bb..02b717b 100644 (file)
@@ -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;
 
index 7660620..5809b4b 100644 (file)
 /** 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;
index d80e8cf..d9d82cd 100644 (file)
 
 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 */
index 841fdbe..14834c1 100644 (file)
@@ -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;
index b3e1831..5018a61 100644 (file)
@@ -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);
index 524e4d8..2d63f43 100644 (file)
 
 #include <vector>
 
-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: */
index 1cadbc1..f78b3a2 100644 (file)
@@ -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;