3 * Copyright (C) 1998 Brainchild Design - http://brainchilddesign.com/
5 * Copyright (C) 2001 Chuck Mason <cemason@users.sourceforge.net>
7 * Copyright (C) 2002 Florian Schulze <crow@icculus.org>
9 * Portions of this code are from the MPEG software simulation group
10 * idct implementation. This code will be replaced with a new
11 * implementation soon.
13 * This file is part of Jump'n'Bump.
15 * Jump'n'Bump is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * Jump'n'Bump is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 static int num_joys=0;
33 static SDL_Joystick *joys[4];
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))
41 int calib_joy(int type)
46 void update_player_actions(void)
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);
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);
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);
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);
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);
103 void init_inputs(void)
107 num_joys = SDL_NumJoysticks();
108 for(i = 0; i < 4 && i < num_joys; ++i)
109 joys[i] = SDL_JoystickOpen(i);
111 main_info.mouse_enabled = 0;
112 main_info.joy_enabled = 0;