origin
parent
74184ed7c2
commit
11def691f9
@ -0,0 +1,38 @@
|
||||
/* $:ID $
|
||||
* keyboard handling */
|
||||
|
||||
enum _bcplayerkeys {
|
||||
BCPK_up = 0,
|
||||
BCPK_down,
|
||||
BCPK_left,
|
||||
BCPK_right,
|
||||
BCPK_special,
|
||||
BCPK_drop,
|
||||
|
||||
BCPK_max
|
||||
};
|
||||
|
||||
enum _bckeys {
|
||||
BCK_help = BCPK_max * 2,
|
||||
BCK_esc,
|
||||
BCK_fullscreen,
|
||||
BCK_chat,
|
||||
BCK_pause,
|
||||
BCK_playermenu,
|
||||
BCK_mapmenu,
|
||||
|
||||
BCK_max
|
||||
};
|
||||
|
||||
struct {
|
||||
Uint8 state [BCK_max]; // current state
|
||||
Uint8 old [BCK_max]; // old state
|
||||
int keycode [BCK_max]; // keycode
|
||||
} typedef BCGameKeys;
|
||||
|
||||
extern BCGameKeys keyb_gamekeys;
|
||||
|
||||
extern void keyb_config ();
|
||||
extern void keyb_configreset ();
|
||||
extern void keyb_init ();
|
||||
extern void keyb_loop (SDL_Event *event);
|
@ -0,0 +1,92 @@
|
||||
/* $Id: keyb.c,v 1.1 2004/04/03 13:55:30 stpohle Exp $
|
||||
* keyb.c
|
||||
*/
|
||||
|
||||
#include "bomberclone.h"
|
||||
#include "keyb.h"
|
||||
|
||||
BCGameKeys keyb_gamekeys;
|
||||
|
||||
|
||||
/*
|
||||
* set the default keyboard settings
|
||||
*/
|
||||
void keyb_configreset () {
|
||||
/* player 1 */
|
||||
keyb_gamekeys.keycode[BCPK_up] = SDLK_UP;
|
||||
keyb_gamekeys.keycode[BCPK_down] = SDLK_DOWN;
|
||||
keyb_gamekeys.keycode[BCPK_left] = SDLK_LEFT;
|
||||
keyb_gamekeys.keycode[BCPK_right] = SDLK_RIGHT;
|
||||
keyb_gamekeys.keycode[BCPK_drop] = SDLK_RCTRL;
|
||||
keyb_gamekeys.keycode[BCPK_special] = SDLK_RSHIFT;
|
||||
|
||||
/* player 2 */
|
||||
keyb_gamekeys.keycode[BCPK_max + BCPK_up] = 'W';
|
||||
keyb_gamekeys.keycode[BCPK_max + BCPK_down] = 'S';
|
||||
keyb_gamekeys.keycode[BCPK_max + BCPK_left] = 'A';
|
||||
keyb_gamekeys.keycode[BCPK_max + BCPK_right] = 'D';
|
||||
keyb_gamekeys.keycode[BCPK_max + BCPK_drop] = SDLK_LCTRL;
|
||||
keyb_gamekeys.keycode[BCPK_max + BCPK_special] = SDLK_LSHIFT;
|
||||
|
||||
/* game keys */
|
||||
keyb_gamekeys.keycode[BCK_help] = SDLK_F1;
|
||||
keyb_gamekeys.keycode[BCK_playermenu] = SDLK_F2;
|
||||
keyb_gamekeys.keycode[BCK_mapmenu] = SDLK_F3;
|
||||
keyb_gamekeys.keycode[BCK_chat] = SDLK_F5;
|
||||
keyb_gamekeys.keycode[BCK_pause] = SDLK_F4;
|
||||
keyb_gamekeys.keycode[BCK_fullscreen] = SDLK_F8;
|
||||
keyb_gamekeys.keycode[BCK_esc] = SDLK_ESCAPE;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* only for debug reasons, print out the states of the keys
|
||||
*/
|
||||
void keyb_print () {
|
||||
int i;
|
||||
|
||||
printf ("keyb_gamekeys.state/old : ");
|
||||
for (i = 0; i < BCK_max; i++)
|
||||
printf ("%1d%1d ", keyb_gamekeys.state[i], keyb_gamekeys.old[i]);
|
||||
printf ("\n");
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* keyboard configuration screen
|
||||
*/
|
||||
void keyb_config () {
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* delete all old data of the keyb_gamekeys
|
||||
*/
|
||||
void keyb_init () {
|
||||
memset (keyb_gamekeys.state, 0, sizeof (Uint8) * BCK_max);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* read all keys and set the keyb_gamekeys
|
||||
*/
|
||||
void keyb_loop (SDL_Event *event) {
|
||||
int i;
|
||||
|
||||
Uint8 *keys = SDL_GetKeyState (NULL);
|
||||
|
||||
/* copy the state into the old state */
|
||||
memcpy (keyb_gamekeys.old, keyb_gamekeys.state, sizeof (Uint8) * BCK_max);
|
||||
memset (keyb_gamekeys.state, 0, sizeof (Uint8) * BCK_max);
|
||||
|
||||
/* read the new state of the pressed keys */
|
||||
for (i = 0; i < BCK_max; i++) {
|
||||
if (keyb_gamekeys.keycode[i] >= 'A' && keyb_gamekeys.keycode[i] <= 'Z') {
|
||||
if (keys[keyb_gamekeys.keycode[i]] || keys[tolower (keyb_gamekeys.keycode[i])])
|
||||
keyb_gamekeys.state[i] |= 1;
|
||||
}
|
||||
else if (keys[keyb_gamekeys.keycode[i]])
|
||||
keyb_gamekeys.state[i] |= 1;
|
||||
}
|
||||
};
|
@ -0,0 +1,86 @@
|
||||
/* $Id: playerinput.c,v 1.1 2004/04/03 13:55:30 stpohle Exp $
|
||||
* playerinput
|
||||
*
|
||||
* the playerinput system will only set some values and flags of the player
|
||||
* not call a player_*() itself (i.e. for dropping a bomb). this will be
|
||||
* done with the player_*() functions which should be called only from the
|
||||
* game_loop();
|
||||
*
|
||||
* direction keys will set the moveing state (player->m) and the direction
|
||||
* value (player->d) the bomb and special key will set a special flag this
|
||||
* the values will be used in player_loop () and the flags will be reset in
|
||||
* there too.
|
||||
*/
|
||||
|
||||
|
||||
#include "bomberclone.h"
|
||||
#include "keyb.h"
|
||||
#include "chat.h"
|
||||
|
||||
/*
|
||||
* handle the diffrent types of input devices and set the player informations
|
||||
* to use this function the function keyb_loop() have to be called first.
|
||||
*/
|
||||
void
|
||||
playerinput_loop (int pl_nr)
|
||||
{
|
||||
if (!chat.active)
|
||||
playerinput_keyb_loop (pl_nr);
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* keyboard handling read keyboard and set playervariables
|
||||
* if only one player is used player one can even use the keys
|
||||
* of player two.
|
||||
*/
|
||||
void
|
||||
playerinput_keyb_loop (int pl_nr)
|
||||
{
|
||||
int pk_offset; // offset for the player keys
|
||||
|
||||
if (bman.state != GS_running)
|
||||
return;
|
||||
|
||||
/* select the current playerkeys (pk_offset) */
|
||||
if (pl_nr == bman.p_nr)
|
||||
pk_offset = 0;
|
||||
else if (pl_nr == bman.p2_nr)
|
||||
pk_offset = BCPK_max;
|
||||
else
|
||||
return; // not a local player
|
||||
|
||||
/* read the keys and set playervariables */
|
||||
playerinput_keyb_read (pk_offset, pl_nr);
|
||||
if (!IS_LPLAYER2 && pk_offset == 0)
|
||||
playerinput_keyb_read (BCPK_max, pl_nr);
|
||||
};
|
||||
|
||||
|
||||
inline void playerinput_keyb_read (int pk_offset, int pl_nr) {
|
||||
if (keyb_gamekeys.state[pk_offset + BCPK_up]) {
|
||||
players[pl_nr].d = up;
|
||||
players[pl_nr].m = 1;
|
||||
}
|
||||
|
||||
if (keyb_gamekeys.state[pk_offset + BCPK_down]) {
|
||||
players[pl_nr].d = down;
|
||||
players[pl_nr].m = 1;
|
||||
}
|
||||
|
||||
if (keyb_gamekeys.state[pk_offset + BCPK_right]) {
|
||||
players[pl_nr].d = right;
|
||||
players[pl_nr].m = 1;
|
||||
}
|
||||
|
||||
if (keyb_gamekeys.state[pk_offset + BCPK_left]) {
|
||||
players[pl_nr].d = left;
|
||||
players[pl_nr].m = 1;
|
||||
}
|
||||
|
||||
if (keyb_gamekeys.state[pk_offset + BCPK_drop] && !keyb_gamekeys.old[pk_offset + BCPK_drop])
|
||||
players[pl_nr].keyf_bomb = 1;
|
||||
|
||||
if (keyb_gamekeys.state[pk_offset + BCPK_special])
|
||||
players[pl_nr].keyf_special = 1;
|
||||
};
|
Loading…
Reference in new issue