Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * input.c
  3.  * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/
  4.  *
  5.  * Copyright (C) 2001 Chuck Mason <cemason@users.sourceforge.net>
  6.  *
  7.  * Copyright (C) 2002 Florian Schulze <crow@icculus.org>
  8.  *
  9.  * This file is part of Jump'n'Bump.
  10.  *
  11.  * Jump'n'Bump is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 2 of the License, or
  14.  * (at your option) any later version.
  15.  *
  16.  * Jump'n'Bump is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  *
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with this program; if not, write to the Free Software
  23.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  24.  */
  25.  
  26. #include "globals.h"
  27.  
  28.  
  29.  
  30.  
  31.  
  32. static int num_joys=0;
  33. static SDL_Joystick *joys[4];
  34.  
  35. /* assumes joysticks have at least one button, could check numbuttons first? */
  36. #define JOY_LEFT(num) (num_joys>num && SDL_JoystickGetAxis(joys[num], 0)<-3200)
  37. #define JOY_RIGHT(num) (num_joys>num && SDL_JoystickGetAxis(joys[num], 0)>3200)
  38. /* I find using the vertical axis to be annoying -- dnb */
  39. #define JOY_JUMP(num) (num_joys>num && SDL_JoystickGetButton(joys[num], 0))
  40.  
  41. int calib_joy(int type)
  42. {
  43.         return 1;
  44. }
  45.  
  46. void update_player_actions(void)
  47. {
  48.         int tmp;
  49.  
  50.         if (client_player_num < 0) {
  51.                 tmp = (key_pressed(KEY_PL1_LEFT) == 1) || JOY_LEFT(3);
  52.                 if (tmp != player[0].action_left)
  53.                         tellServerPlayerMoved(0, MOVEMENT_LEFT, tmp);
  54.                 tmp = (key_pressed(KEY_PL1_RIGHT) == 1) || JOY_RIGHT(3);
  55.                 if (tmp != player[0].action_right)
  56.                         tellServerPlayerMoved(0, MOVEMENT_RIGHT, tmp);
  57.                 tmp = (key_pressed(KEY_PL1_JUMP) == 1) || JOY_JUMP(3);
  58.                 if (tmp != player[0].action_up)
  59.                         tellServerPlayerMoved(0, MOVEMENT_UP, tmp);
  60.  
  61.                 tmp = (key_pressed(KEY_PL2_LEFT) == 1) || JOY_LEFT(2);
  62.                 if (tmp != player[1].action_left)
  63.                         tellServerPlayerMoved(1, MOVEMENT_LEFT, tmp);
  64.                 tmp = (key_pressed(KEY_PL2_RIGHT) == 1) || JOY_RIGHT(2);
  65.                 if (tmp != player[1].action_right)
  66.                         tellServerPlayerMoved(1, MOVEMENT_RIGHT, tmp);
  67.                 tmp = (key_pressed(KEY_PL2_JUMP) == 1) || JOY_JUMP(2);
  68.                 if (tmp != player[1].action_up)
  69.                         tellServerPlayerMoved(1, MOVEMENT_UP, tmp);
  70.  
  71.                 tmp = (key_pressed(KEY_PL3_LEFT) == 1) || JOY_LEFT(1);
  72.                 if (tmp != player[2].action_left)
  73.                         tellServerPlayerMoved(2, MOVEMENT_LEFT, tmp);
  74.                 tmp = (key_pressed(KEY_PL3_RIGHT) == 1) || JOY_RIGHT(1);
  75.                 if (tmp != player[2].action_right)
  76.                         tellServerPlayerMoved(2, MOVEMENT_RIGHT, tmp);
  77.                 tmp = (key_pressed(KEY_PL3_JUMP) == 1) || JOY_JUMP(1);
  78.                 if (tmp != player[2].action_up)
  79.                         tellServerPlayerMoved(2, MOVEMENT_UP, tmp);
  80.  
  81.                 tmp = (key_pressed(KEY_PL4_LEFT) == 1) || JOY_LEFT(0);
  82.                 if (tmp != player[3].action_left)
  83.                 tellServerPlayerMoved(3, MOVEMENT_LEFT, tmp);
  84.                 tmp = (key_pressed(KEY_PL4_RIGHT) == 1) || JOY_RIGHT(0);
  85.                 if (tmp != player[3].action_right)
  86.                 tellServerPlayerMoved(3, MOVEMENT_RIGHT, tmp);
  87.                 tmp = (key_pressed(KEY_PL4_JUMP) == 1) || JOY_JUMP(0);
  88.                 if (tmp != player[3].action_up)
  89.                 tellServerPlayerMoved(3, MOVEMENT_UP, tmp);
  90.         } else {
  91.                 tmp = (key_pressed(KEY_PL1_LEFT) == 1) || JOY_LEFT(0);
  92.                 if (tmp != player[client_player_num].action_left)
  93.                         tellServerPlayerMoved(client_player_num, MOVEMENT_LEFT, tmp);
  94.                 tmp = (key_pressed(KEY_PL1_RIGHT) == 1) || JOY_RIGHT(0);
  95.                 if (tmp != player[client_player_num].action_right)
  96.                         tellServerPlayerMoved(client_player_num, MOVEMENT_RIGHT, tmp);
  97.                 tmp = (key_pressed(KEY_PL1_JUMP) == 1) || JOY_JUMP(0);
  98.                 if (tmp != player[client_player_num].action_up)
  99.                         tellServerPlayerMoved(client_player_num, MOVEMENT_UP, tmp);
  100.         }
  101. }
  102.  
  103. void init_inputs(void)
  104. {
  105.         int i;
  106.  
  107.         num_joys = SDL_NumJoysticks();
  108.         for(i = 0; i < 4 && i < num_joys; ++i)
  109.                 joys[i] = SDL_JoystickOpen(i);
  110.  
  111.         main_info.mouse_enabled = 0;
  112.         main_info.joy_enabled = 0;
  113. }
  114.