Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Joystick support.

Signed-off-by: Paul Brook <paul@codesourcery.com>
  • Loading branch information...
commit 390be52790c8664dc359f5d145f2061a1f247044 1 parent e2530ac
Paul Brook authored
View
14 chuckie.c
@@ -530,16 +530,16 @@ static void MovePlayer(void)
move_x = 0;
move_y = 0;
- if (buttons & 0x01) {
+ if (buttons & BUTTON_RIGHT) {
move_x++;
}
- if (buttons & 0x02) {
+ if (buttons & BUTTON_LEFT) {
move_x--;
}
- if (buttons & 0x04) {
+ if (buttons & BUTTON_DOWN) {
move_y--;
}
- if (buttons & 0x08) {
+ if (buttons & BUTTON_UP) {
move_y++;
}
move_y <<= 1;
@@ -578,7 +578,7 @@ static void MovePlayer(void)
}
break;
case PLAYER_CLIMB:
- if ((buttons & 0x10) != 0) {
+ if ((buttons & BUTTON_JUMP) != 0) {
StartPlayerJump();
break;
}
@@ -612,7 +612,7 @@ static void MovePlayer(void)
player_face = 0;
break;
case 4: /* On lift */
- if ((buttons & 0x10) != 0) {
+ if ((buttons & BUTTON_JUMP) != 0) {
StartPlayerJump();
break;
}
@@ -631,7 +631,7 @@ static void MovePlayer(void)
is_dead++;
break;
case PLAYER_WALK:
- if (buttons & 0x10) {
+ if (buttons & BUTTON_JUMP) {
StartPlayerJump();
break;
}
View
6 chuckie.h
@@ -7,6 +7,11 @@
/*** Game interface. */
+#define BUTTON_RIGHT 1
+#define BUTTON_LEFT 2
+#define BUTTON_DOWN 4
+#define BUTTON_UP 8
+#define BUTTON_JUMP 0x10
extern uint8_t buttons;
extern uint8_t button_ack;
extern int cheat;
@@ -26,6 +31,7 @@ extern short next_buffer[BUFSIZE];
void mix_buffer(void);
void sound_start(int, int);
void init_sound(void);
+void init_input(void);
/*** Misc. */
extern const uint8_t *const levels[8];
View
2  gl.c
@@ -476,6 +476,8 @@ int main(int argc, const char *argv[])
init_sound();
+ init_input();
+
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
View
2  gl2.c
@@ -753,6 +753,8 @@ int main(int argc, const char *argv[])
init_sound();
+ init_input();
+
InitGL();
SDL_AddTimer(30, do_timer, NULL);
View
18 ncurses.c
@@ -32,23 +32,23 @@ void PollKeys(void)
c = getch();
switch (c) {
case '.':
- buttons |= 1;
- buttons &= ~2;
+ buttons |= BUTTON_RIGHT;
+ buttons &= ~BUTTON_LEFT;
break;
case ',':
- buttons |= 2;
- buttons &= ~1;
+ buttons |= BUTTON_LEFT;
+ buttons &= ~BUTTON_RIGHT;
break;
case 'z':
- buttons |= 4;
- buttons &= ~8;
+ buttons |= BUTTON_DOWN;
+ buttons &= ~BUTTON_UP;
break;
case 'a':
- buttons |= 8;
- buttons &= ~4;
+ buttons |= BUTTON_UP;
+ buttons &= ~BUTTON_DOWN;
break;
case ' ':
- buttons |= 0x10;
+ buttons |= BUTTON_JUMP;
break;
case 'q':
case 'Q':
View
43 sdl-input.c
@@ -118,7 +118,50 @@ void PollKeys(void)
break;
}
break;
+ case SDL_JOYAXISMOTION:
+ if (event.jaxis.axis == 0) {
+ buttons &= ~(BUTTON_LEFT | BUTTON_RIGHT);
+ if (event.jaxis.value < -3200) {
+ buttons |= BUTTON_LEFT;
+ } else if (event.jaxis.value > 3200) {
+ buttons |= BUTTON_RIGHT;
+ }
+ } else if (event.jaxis.axis == 1) {
+ buttons &= ~(BUTTON_UP | BUTTON_DOWN);
+ if (event.jaxis.value < -3200) {
+ buttons |= BUTTON_UP;
+ } else if (event.jaxis.value > 3200) {
+ buttons |= BUTTON_DOWN;
+ }
+ }
+ break;
+ case SDL_JOYBUTTONDOWN:
+ /* Don't care which button. */
+ buttons |= BUTTON_JUMP;
+ break;
+ case SDL_JOYBUTTONUP:
+ buttons &= ~BUTTON_JUMP;
+ break;
}
}
}
+static SDL_Joystick *joystick;
+
+void init_input(void)
+{
+ int err;
+
+ err = SDL_InitSubSystem(SDL_INIT_JOYSTICK);
+ if (err < 0) {
+ printf("SDL_INIT_JOYSTICK failed\n");
+ return;
+ }
+ if (SDL_NumJoysticks() == 0) {
+ printf("No joystick found\n");
+ return;
+ }
+
+ SDL_JoystickEventState(SDL_ENABLE);
+ joystick = SDL_JoystickOpen(0);
+}
View
2  sdl.c
@@ -138,6 +138,8 @@ int main(int argc, const char *argv[])
init_sound();
+ init_input();
+
SDL_AddTimer(30, do_timer, NULL);
run_game();
Please sign in to comment.
Something went wrong with that request. Please try again.