void GetPlayerConfig()
{
- int old_joystick_nr = setup.joystick_nr;
+ int old_joystick_nr = setup.joy_input[0].joystick_nr;
if (sound_status==SOUND_OFF)
local_player->setup &= ~SETUP_SOUND;
setup.direct_draw_on = SETUP_DIRECT_DRAW_ON(local_player->setup);
setup.fading_on = SETUP_FADING_ON(local_player->setup);
setup.autorecord_on = SETUP_AUTO_RECORD_ON(local_player->setup);
+
+#if 0
setup.joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup);
+#endif
+
+ setup.joy_input[0].joystick_nr = SETUP_2ND_JOYSTICK_ON(local_player->setup);
+
setup.quick_doors = SETUP_QUICK_DOORS_ON(local_player->setup);
setup.scroll_delay_on = SETUP_SCROLL_DELAY_ON(local_player->setup);
setup.soft_scrolling_on = SETUP_SOFT_SCROLL_ON(local_player->setup);
#ifndef MSDOS
- if (setup.joystick_nr != old_joystick_nr)
+ if (setup.joy_input[0].joystick_nr != old_joystick_nr)
{
if (joystick_device)
close(joystick_device);
{
int i;
- /* initialize local player's setup */
+ /* initialize local setup */
setup.sound_on = TRUE;
setup.sound_loops_on = FALSE;
setup.sound_music_on = FALSE;
setup.fading_on = FALSE;
setup.autorecord_on = FALSE;
setup.quick_doors = FALSE;
- setup.joystick_nr = 0;
+ for (i=0; i<MAX_PLAYERS; i++)
+ {
+ setup.joy_input[i].use_joystick = FALSE;
+ setup.joy_input[i].joystick_nr = i;
+ setup.joy_input[i].button_snap = JOY_BUTTON_1;
+ setup.joy_input[i].button_bomb = JOY_BUTTON_2;
+ setup.key_input[i].left = DEFAULT_KEY_LEFT;
+ setup.key_input[i].right = DEFAULT_KEY_RIGHT;
+ setup.key_input[i].up = DEFAULT_KEY_UP;
+ setup.key_input[i].down = DEFAULT_KEY_DOWN;
+ setup.key_input[i].snap = DEFAULT_KEY_SNAP;
+ setup.key_input[i].bomb = DEFAULT_KEY_BOMB;
+ }
/* choose default local player */
local_player = &stored_player[0];
void InitJoystick()
{
+ int joystick_nr = setup.joy_input[0].joystick_nr;
+
if (global_joystick_status == JOYSTICK_OFF)
return;
#ifndef MSDOS
- if (access(joystick_device_name[setup.joystick_nr], R_OK) < 0)
+ if (access(joystick_device_name[joystick_nr], R_OK) < 0)
{
Error(ERR_RETURN, "cannot access joystick device '%s'",
- joystick_device_name[setup.joystick_nr]);
+ joystick_device_name[joystick_nr]);
joystick_status = JOYSTICK_OFF;
return;
}
if ((joystick_device =
- open(joystick_device_name[setup.joystick_nr], O_RDONLY)) < 0)
+ open(joystick_device_name[joystick_nr], O_RDONLY)) < 0)
{
Error(ERR_RETURN, "cannot open joystick device '%s'",
- joystick_device_name[setup.joystick_nr]);
+ joystick_device_name[joystick_nr]);
joystick_status = JOYSTICK_OFF;
return;
}
} joy_ctrl;
#endif
+ int joystick_nr = setup.joy_input[0].joystick_nr;
int js_x,js_y, js_b1,js_b2;
int left, right, up, down;
int result=0;
js_b2 = joy_ctrl.buttons & 2;
#endif
- left = JoystickPosition(joystick[setup.joystick_nr].xmiddle,
- joystick[setup.joystick_nr].xleft, js_x);
- right = JoystickPosition(joystick[setup.joystick_nr].xmiddle,
- joystick[setup.joystick_nr].xright, js_x);
- up = JoystickPosition(joystick[setup.joystick_nr].ymiddle,
- joystick[setup.joystick_nr].yupper, js_y);
- down = JoystickPosition(joystick[setup.joystick_nr].ymiddle,
- joystick[setup.joystick_nr].ylower, js_y);
+ left = JoystickPosition(joystick[joystick_nr].xmiddle,
+ joystick[joystick_nr].xleft, js_x);
+ right = JoystickPosition(joystick[joystick_nr].xmiddle,
+ joystick[joystick_nr].xright, js_x);
+ up = JoystickPosition(joystick[joystick_nr].ymiddle,
+ joystick[joystick_nr].yupper, js_y);
+ down = JoystickPosition(joystick[joystick_nr].ymiddle,
+ joystick[joystick_nr].ylower, js_y);
if (left>JOYSTICK_PERCENT)
result |= JOY_LEFT;
struct LevelDirInfo leveldir[MAX_LEVDIR_ENTRIES];
struct LevelInfo level;
-struct PlayerInfo stored_player[MAX_PLAYERS+1];
-struct PlayerInfo *local_player;
+struct PlayerInfo stored_player[MAX_PLAYERS], *local_player;
struct HiScore highscore[MAX_SCORE_ENTRIES];
struct SoundInfo Sound[NUM_SOUNDS];
struct RecordingInfo tape;
boolean verbose;
};
+struct SetupKeyboardInfo
+{
+ KeySym left;
+ KeySym right;
+ KeySym up;
+ KeySym down;
+ KeySym snap;
+ KeySym bomb;
+};
+
+struct SetupJoystickInfo
+{
+ boolean use_joystick;
+ int joystick_nr;
+ int button_snap;
+ int button_bomb;
+};
+
struct SetupInfo
{
boolean sound_on;
boolean fading_on;
boolean autorecord_on;
boolean quick_doors;
- int joystick_nr;
+ struct SetupKeyboardInfo key_input[MAX_PLAYERS];
+ struct SetupJoystickInfo joy_input[MAX_PLAYERS];
};
struct PlayerInfo
extern struct LevelDirInfo leveldir[];
extern struct LevelInfo level;
-extern struct PlayerInfo stored_player[];
-extern struct PlayerInfo *local_player;
+extern struct PlayerInfo stored_player[], *local_player;
extern struct HiScore highscore[];
extern struct RecordingInfo tape;
extern struct SoundInfo Sound[];
extern struct JoystickInfo joystick[];
-struct OptionInfo options;
-struct SetupInfo setup;
+extern struct OptionInfo options;
+extern struct SetupInfo setup;
extern char *sound_name[];
extern int background_loop[];
(s)==SND_TYGER || (s)==SND_VOYAGER || \
(s)==SND_TWILIGHT)
+/* default input keys */
+#define DEFAULT_KEY_LEFT XK_Left
+#define DEFAULT_KEY_RIGHT XK_Right
+#define DEFAULT_KEY_UP XK_Up
+#define DEFAULT_KEY_DOWN XK_Down
+#define DEFAULT_KEY_SNAP XK_Shift_L
+#define DEFAULT_KEY_BOMB XK_Shift_R
/* directions for moving */
#define MV_NO_MOVING 0
return ptr;
}
+
+char *getKeySymName(KeySym key)
+{
+ static char key_name[20];
+ static struct
+ {
+ KeySym keysym;
+ char *name;
+ } translate[] =
+ {
+ { XK_Left, "cursor left" },
+ { XK_Right, "cursor right" },
+ { XK_Up, "cursor up" },
+ { XK_Down, "cursor down" },
+
+#ifdef XK_KP_Left
+ { XK_KP_Left, "keypad left" },
+ { XK_KP_Right, "keypad right" },
+ { XK_KP_Up, "keypad up" },
+ { XK_KP_Down, "keypad down" },
+#endif
+
+ { XK_BackSpace, "backspace" },
+ { XK_Delete, "delete" },
+ { XK_Insert, "insert" },
+ { XK_Tab, "tab" },
+ { XK_Home, "home" },
+ { XK_End, "end" },
+ { XK_Page_Up, "page up" },
+ { XK_Page_Down, "page down" },
+ { XK_space, "space" },
+
+ { XK_Shift_L, "left shift" },
+ { XK_Shift_R, "right shift" },
+ { XK_Control_L, "left ctrl" },
+ { XK_Control_R, "right ctrl" },
+ { XK_Meta_L, "left meta" },
+ { XK_Meta_R, "right meta" },
+ { XK_Alt_L, "left alt" },
+ { XK_Alt_R, "right alt" },
+ { XK_Mode_switch, "mode switch" },
+ { XK_Multi_key, "multi key" },
+
+ { 0, NULL }
+ };
+
+ if (key >= XK_A && key <= XK_Z)
+ {
+ sprintf(key_name, "%c", 'A' + (char)(key - XK_A));
+ return key_name;
+ }
+ else if (key >= XK_a && key <= XK_z)
+ {
+ sprintf(key_name, "%c", 'a' + (char)(key - XK_a));
+ return key_name;
+ }
+ else if (key >= XK_0 && key <= XK_9)
+ {
+ sprintf(key_name, "%c", '0' + (char)(key - XK_0));
+ return key_name;
+ }
+ else if (key >= XK_KP_0 && key <= XK_KP_9)
+ {
+ sprintf(key_name, "keypad %c", '0' + (char)(key - XK_KP_0));
+ return key_name;
+ }
+ else
+ {
+ int i = 0;
+
+ do
+ {
+ if (key == translate[i].keysym)
+ return translate[i].name;
+ }
+ while (translate[++i].name);
+
+ sprintf(key_name, "(unknown)");
+ return key_name;
+ }
+}
void GetOptions(char **);
void Error(int, char *, ...);
void *checked_malloc(unsigned long);
+char *getKeySymName(KeySym);
#endif
}
else if (y==14)
{
+ /*
CalibrateJoystick();
+ */
+
+ CustomizeKeyboard();
+
redraw = TRUE;
}
else if (y==pos_end-1 || y==pos_end)
DoAnimation();
}
+void CustomizeKeyboard( /* int player_nr */ )
+{
+ int player_nr = 0;
+
+ int i;
+ boolean finished = FALSE;
+ static struct SetupKeyboardInfo custom_key;
+ static struct
+ {
+ KeySym *keysym;
+ char *text;
+ } customize_step[] =
+ {
+ { &custom_key.left, "Move Left" },
+ { &custom_key.right, "Move Right" },
+ { &custom_key.up, "Move Up" },
+ { &custom_key.down, "Move Down" },
+ { &custom_key.snap, "Snap Field" },
+ { &custom_key.bomb, "Place Bomb" }
+ };
+
+ custom_key = setup.key_input[player_nr];
+
+ ClearWindow();
+ DrawText(SX+16, SY+16, "Keyboard Input", FS_BIG, FC_YELLOW);
+
+ BackToFront();
+ InitAnimation();
+
+ i = 0;
+ DrawText(SX, SY+(2+2*i)*32, customize_step[i].text, FS_BIG, FC_GREEN);
+ DrawText(SX, SY+(2+2*i+1)*32, "Key:", FS_BIG, FC_GREEN);
+ DrawText(SX + 5*32, SY+(2+2*i+1)*32,
+ getKeySymName(*customize_step[i].keysym), FS_BIG, FC_BLUE);
+
+ while(!finished)
+ {
+ if (XPending(display)) /* got event from X server */
+ {
+ XEvent event;
+
+ XNextEvent(display, &event);
+ switch(event.type)
+ {
+ case Expose:
+ HandleExposeEvent((XExposeEvent *) &event);
+ break;
+ case UnmapNotify:
+ SleepWhileUnmapped();
+ break;
+ case KeyPress:
+ {
+ KeySym key = XLookupKeysym((XKeyEvent *)&event,
+ ((XKeyEvent *)&event)->state);
+
+ if (key == XK_Escape || (key == XK_Return && i == 6))
+ {
+ finished = TRUE;
+ break;
+ }
+
+ if (key == XK_Return || i == 6)
+ break;
+
+ /* got new key binding */
+ *customize_step[i].keysym = key;
+ DrawText(SX + 5*32, SY+(2+2*i+1)*32,
+ " ", FS_BIG, FC_YELLOW);
+ DrawText(SX + 5*32, SY+(2+2*i+1)*32,
+ getKeySymName(key), FS_BIG, FC_YELLOW);
+
+ i++;
+
+ if (i == 6)
+ {
+ DrawText(SX+16, SY+15*32+16, "Press Enter", FS_BIG, FC_YELLOW);
+ break;
+ }
+
+ /* ask for next key binding */
+ DrawText(SX, SY+(2+2*i)*32,
+ customize_step[i].text, FS_BIG, FC_GREEN);
+ DrawText(SX, SY+(2+2*i+1)*32, "Key:", FS_BIG, FC_GREEN);
+ DrawText(SX + 5*32, SY+(2+2*i+1)*32,
+ getKeySymName(*customize_step[i].keysym),
+ FS_BIG, FC_BLUE);
+ }
+ break;
+ case KeyRelease:
+ key_joystick_mapping = 0;
+ break;
+ case FocusIn:
+ case FocusOut:
+ HandleFocusEvent((XFocusChangeEvent *) &event);
+ break;
+ case ClientMessage:
+ HandleClientMessageEvent((XClientMessageEvent *) &event);
+ break;
+ default:
+ break;
+ }
+ }
+
+ BackToFront();
+ DoAnimation();
+
+ /* don't eat all CPU time */
+ Delay(10);
+ }
+
+ StopAnimation();
+ DrawSetupScreen();
+}
+
void CalibrateJoystick()
{
#ifdef __FreeBSD__
char joy_nr[4];
#endif
+ int joystick_nr = setup.joy_input[0].joystick_nr;
int new_joystick_xleft = 128, new_joystick_xright = 128;
int new_joystick_yupper = 128, new_joystick_ylower = 128;
int new_joystick_xmiddle, new_joystick_ymiddle;
new_joystick_ymiddle =
new_joystick_yupper + (new_joystick_ylower - new_joystick_yupper) / 2;
- joystick[setup.joystick_nr].xleft = new_joystick_xleft;
- joystick[setup.joystick_nr].yupper = new_joystick_yupper;
- joystick[setup.joystick_nr].xright = new_joystick_xright;
- joystick[setup.joystick_nr].ylower = new_joystick_ylower;
- joystick[setup.joystick_nr].xmiddle = new_joystick_xmiddle;
- joystick[setup.joystick_nr].ymiddle = new_joystick_ymiddle;
+ joystick[joystick_nr].xleft = new_joystick_xleft;
+ joystick[joystick_nr].yupper = new_joystick_yupper;
+ joystick[joystick_nr].xright = new_joystick_xright;
+ joystick[joystick_nr].ylower = new_joystick_ylower;
+ joystick[joystick_nr].xmiddle = new_joystick_xmiddle;
+ joystick[joystick_nr].ymiddle = new_joystick_ymiddle;
CheckJoystickData();
#if 0
printf("LEFT / MIDDLE / RIGHT == %d / %d / %d\n",
- joystick[setup.joystick_nr].xleft,
- joystick[setup.joystick_nr].xmiddle,
- joystick[setup.joystick_nr].xright);
+ joystick[joystick_nr].xleft,
+ joystick[joystick_nr].xmiddle,
+ joystick[joystick_nr].xright);
printf("UP / MIDDLE / DOWN == %d / %d / %d\n",
- joystick[setup.joystick_nr].yupper,
- joystick[setup.joystick_nr].ymiddle,
- joystick[setup.joystick_nr].ylower);
+ joystick[joystick_nr].yupper,
+ joystick[joystick_nr].ymiddle,
+ joystick[joystick_nr].ylower);
#endif
}
char joy_nr[4];
#endif
+ int joystick_nr = setup.joy_input[0].joystick_nr;
int new_joystick_xleft, new_joystick_xright, new_joystick_xmiddle;
int new_joystick_yupper, new_joystick_ylower, new_joystick_ymiddle;
new_joystick_xmiddle = joy_ctrl.x;
new_joystick_ymiddle = joy_ctrl.y;
- joystick[setup.joystick_nr].xleft = new_joystick_xleft;
- joystick[setup.joystick_nr].yupper = new_joystick_yupper;
- joystick[setup.joystick_nr].xright = new_joystick_xright;
- joystick[setup.joystick_nr].ylower = new_joystick_ylower;
- joystick[setup.joystick_nr].xmiddle = new_joystick_xmiddle;
- joystick[setup.joystick_nr].ymiddle = new_joystick_ymiddle;
+ joystick[joystick_nr].xleft = new_joystick_xleft;
+ joystick[joystick_nr].yupper = new_joystick_yupper;
+ joystick[joystick_nr].xright = new_joystick_xright;
+ joystick[joystick_nr].ylower = new_joystick_ylower;
+ joystick[joystick_nr].xmiddle = new_joystick_xmiddle;
+ joystick[joystick_nr].ymiddle = new_joystick_ymiddle;
CheckJoystickData();
void HandleHallOfFame(int);
void DrawSetupScreen(void);
void HandleSetupScreen(int, int, int, int, int);
+void CustomizeKeyboard(void);
void CalibrateJoystick(void);
void HandleGameActions(byte);
void HandleVideoButtons(int, int, int);