added chatmode, added userdefined keyboard handling needed for two players on one computer mode.

origin
stpohle 22 years ago
parent 74184ed7c2
commit 11def691f9

@ -1,4 +1,8 @@
$Id: ChangeLog,v 1.73 2004/02/11 21:45:05 stpohle Exp $ $Id: ChangeLog,v 1.74 2004/04/03 13:55:28 stpohle Exp $
- WORKING ON: userdefined keyboad settings. read the file
src/keyb.c for the current keyboard settings. Config
screen still not finished.
- Fixed: respawning of the player will continue and - Fixed: respawning of the player will continue and
finish when we go into Hurry Mode. finish when we go into Hurry Mode.

26
TODO

@ -1,6 +1,10 @@
$Id: TODO,v 1.40 2004/02/08 00:43:30 stpohle Exp $ $Id: TODO,v 1.41 2004/04/03 13:55:28 stpohle Exp $
- support for more player on one keyboard **************************************************************
* All Todo entry are to make at the WebPage: *
* http://sourceforge.net/tracker/?group_id=79449&atid=556632 *
* So i can drop this file soon. *
**************************************************************
- better configuration for home made map files - better configuration for home made map files
@ -8,29 +12,11 @@ $Id: TODO,v 1.40 2004/02/08 00:43:30 stpohle Exp $
a new one you will lose the old one and someone else can a new one you will lose the old one and someone else can
catch this one. catch this one.
- multiplayer broadcast in the local network
ip: 10.*.*.* and 192.168.*.*
- more specials - more specials
- network joining menu - network joining menu
Add: information about the playernames and the point list. Add: information about the playernames and the point list.
- keyboard/keybinput cleanup so all keyboard inputs will be read from there.
hopefully we will get so out of this menu problem that sometimes keys are
ignored.
- Sound menu to select the samplerate mono+stereo 8bit or 16bit
- add musicfiles with type of mp3, mod, xm, s3m and
mid (but i don't know how i can do this)
- better animated fire
- more gfx players to select?
- team mode
- we need some more sound for picking up items. - we need some more sound for picking up items.
- ranking system, done by the bomberclonemserv - ranking system, done by the bomberclonemserv

@ -1,4 +1,4 @@
# Anjuta Version 1.1.97 # Anjuta Version 1.2.0
Compatibility Level: 1 Compatibility Level: 1
<PROJECT_DESCRIPTION_START> <PROJECT_DESCRIPTION_START>
@ -39,7 +39,7 @@ echo "T $target H $host B $buid" >cross-target.txt
props.file.type=project props.file.type=project
anjuta.version=1.1.97 anjuta.version=1.2.0
anjuta.compatibility.level=1 anjuta.compatibility.level=1
project.name=bomberclone project.name=bomberclone
@ -74,7 +74,6 @@ preferences.make=make
preferences.build.option.keep.going=0 preferences.build.option.keep.going=0
preferences.build.option.warn.undef=0 preferences.build.option.warn.undef=0
preferences.autoformat.custom.style=-br -brs -l100 -lc100 -lp -hnl -bc -nip -nce -ncdw -bli1 -i4 -ts1-bad -bap preferences.autoformat.custom.style=-br -brs -l100 -lc100 -lp -hnl -bc -nip -nce -ncdw -bli1 -i4 -ts1-bad -bap
preferences.autoformat.style=Custom style
preferences.indent.opening=0 preferences.indent.opening=0
preferences.autoformat.disable=0 preferences.autoformat.disable=0
preferences.indent.automatic=1 preferences.indent.automatic=1
@ -101,7 +100,8 @@ module.include.files=\
menugui.h\ menugui.h\
ogcache-client.h\ ogcache-client.h\
udp.h\ udp.h\
flyingitems.h flyingitems.h\
keyb.h
module.source.name=src module.source.name=src
module.source.type= module.source.type=
@ -142,7 +142,9 @@ module.source.files=\
netsrvlist.c\ netsrvlist.c\
flyingitems.c\ flyingitems.c\
help.c\ help.c\
menuimages.c menuimages.c\
playerinput.c\
keyb.c
module.pixmap.name=pixmaps module.pixmap.name=pixmaps
module.pixmap.type= module.pixmap.type=

@ -22,6 +22,7 @@ bomberclone_include_DATA = \
sound.h \ sound.h \
ogcache-client.h\ ogcache-client.h\
udp.h \ udp.h \
flyingitems.h flyingitems.h \
keyb.h
EXTRA_DIST = $(bomberclone_include_DATA) EXTRA_DIST = $(bomberclone_include_DATA)

@ -1,4 +1,4 @@
/* $Id: bomberclone.h,v 1.23 2004/02/07 13:35:28 stpohle Exp $ */ /* $Id: bomberclone.h,v 1.24 2004/04/03 13:55:29 stpohle Exp $ */
/* bomberclone.h */ /* bomberclone.h */
#ifndef _BOMBERCLONE_H_ #ifndef _BOMBERCLONE_H_
@ -99,6 +99,8 @@ struct {
signed char d; // direction signed char d; // direction
signed char m; // player is moving ? signed char m; // player is moving ?
signed char old_m; // to save the old state.. signed char old_m; // to save the old state..
signed char keyf_bomb; // flag for the bomb key
signed char keyf_special; // flag for the special key
int bombs_n; // maximal number of bombs for the player int bombs_n; // maximal number of bombs for the player
int bomb_lastex; // number of the bomb which explode the last time int bomb_lastex; // number of the bomb which explode the last time
@ -130,7 +132,8 @@ struct {
struct { struct {
char datapath[512]; char datapath[512];
int p_nr; // Playernumber 0 if you host a game or the number of the one you are. int p_nr; // playernumber of the first local player
int p2_nr; // playernumber of the second local player
int p_servnr; // Playernumber of the Server int p_servnr; // Playernumber of the Server
int last_ex_nr; // number of the last explosion int last_ex_nr; // number of the last explosion
int updatestatusbar; // 1 if statusbar has to be updated int updatestatusbar; // 1 if statusbar has to be updated
@ -165,6 +168,8 @@ struct {
unsigned char ai_players; // number of ai players unsigned char ai_players; // number of ai players
} typedef _bomberclone; } typedef _bomberclone;
#define IS_LPLAYER2 (bman.p2_nr != bman.p_nr && bman.p2_nr >= 0 && bman.p2_nr < MAX_PLAYERS)
struct { struct {
signed char dir; signed char dir;
@ -181,6 +186,7 @@ extern int debug;
// Game routines.. // Game routines..
extern void game_draw_info (); extern void game_draw_info ();
extern void game_keys_loop ();
extern void game_loop (); extern void game_loop ();
extern void game_end (); extern void game_end ();
extern void game_start(); extern void game_start();
@ -205,7 +211,7 @@ extern void stonelist_draw ();
extern void dead_playerani (); extern void dead_playerani ();
extern void draw_player (_player * player); extern void draw_player (_player * player);
extern void restore_players_screen (); extern void restore_players_screen ();
extern void move_player (int pl_nr); extern void player_move (int pl_nr);
extern float stepmove_player (int pl_nr); extern float stepmove_player (int pl_nr);
extern void player_drop_bomb (int pl_nr); extern void player_drop_bomb (int pl_nr);
extern void get_player_on (float x, float y, int pl_nr[]); extern void get_player_on (float x, float y, int pl_nr[]);
@ -223,7 +229,12 @@ extern void player_set_gfx (_player *p, signed char gfx_nr);
extern int player_findfreebomb (_player *player); extern int player_findfreebomb (_player *player);
extern int player_checkpos (int x, int y); extern int player_checkpos (int x, int y);
extern void player_checkdeath (int pnr); extern void player_checkdeath (int pnr);
extern void player_check (int pl_nr);
// for the playerinput handling
extern void playerinput_loop (int pl_nr);
extern void playerinput_keyb_loop (int pl_nr);
extern inline void playerinput_keyb_read (int pk_offset, int pl_nr);
// for the bomb.. // for the bomb..
extern int bomb_loop (); extern int bomb_loop ();

@ -10,11 +10,12 @@
struct __chat { struct __chat {
SDL_Rect window; SDL_Rect window;
signed char visible; signed char visible; // the chat is visible
signed char changed; signed char changed;
SDL_Surface *oldscreen; SDL_Surface *oldscreen;
short int startline; short int startline;
short int lastline; short int lastline;
short int active; // if we are in chat mode
struct { struct {
char text[255]; char text[255];
int status; int status;

@ -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);

@ -1,3 +1,4 @@
/* $Id: keybinput.h,v 1.5 2004/04/03 13:55:29 stpohle Exp $ */
#ifndef _KEYBINPUT_H_ #ifndef _KEYBINPUT_H_
#define _KEYBINPUT_H_ #define _KEYBINPUT_H_
@ -17,6 +18,7 @@ struct __keybinput {
int maxlen; int maxlen;
} typedef _keybinput; } typedef _keybinput;
extern void keybinput_new (_keybinput *ki, int type, int maxlen); extern void keybinput_new (_keybinput *ki, int type, int maxlen);
extern int keybinput_loop (_keybinput *ki, SDL_Event *event); extern int keybinput_loop (_keybinput *ki, SDL_Event *event);

@ -40,6 +40,8 @@ bomberclone_SOURCES = \
sound.c\ sound.c\
ogcache-client.c\ ogcache-client.c\
flyingitems.c\ flyingitems.c\
help.c help.c\
playerinput.c\
keyb.c
## bomberclone_LDADD = ## bomberclone_LDADD =

@ -198,6 +198,7 @@ chat_loop (SDL_Event * event)
maxchar; maxchar;
char text[255]; char text[255];
if (chat.active) { /* the chat mode is active */
i = keybinput_loop (&chat.input, event); i = keybinput_loop (&chat.input, event);
if (i == 1 && chat.input.text[0] != 0) { if (i == 1 && chat.input.text[0] != 0) {
@ -206,7 +207,10 @@ chat_loop (SDL_Event * event)
chat_addline (text); chat_addline (text);
keybinput_new (&chat.input, KEYBI_text, 255); keybinput_new (&chat.input, KEYBI_text, 255);
i = 0; i = 0;
chat.active = 0;
} }
}
else i = 0;
if (((i == 0 && chat.input.changed == 1) || chat.changed == 1) && chat.visible == 1) { if (((i == 0 && chat.input.changed == 1) || chat.changed == 1) && chat.visible == 1) {
/* draw the new field */ /* draw the new field */

@ -10,6 +10,7 @@
#include "chat.h" #include "chat.h"
#include "sound.h" #include "sound.h"
#include "menu.h" #include "menu.h"
#include "keyb.h"
void void
config_init (int argc, char **argv) config_init (int argc, char **argv)
@ -28,6 +29,7 @@ config_init (int argc, char **argv)
stonelist_del (); stonelist_del ();
chat.visible = 0; chat.visible = 0;
chat.startline = 0; chat.startline = 0;
keyb_configreset ();
keybinput_new (&chat.input, KEYBI_text, 255); keybinput_new (&chat.input, KEYBI_text, 255);
for (i = 0; i < CHAT_MAX_LINES; i++) for (i = 0; i < CHAT_MAX_LINES; i++)
@ -283,6 +285,49 @@ config_read ()
if (!strcmp (keyword, "dropitemsondeath")) { if (!strcmp (keyword, "dropitemsondeath")) {
bman.dropitemsondeath = atoi (value); bman.dropitemsondeath = atoi (value);
} }
/*
* keyboard config, i will give names to the keys insteed of the numbers,
* this is done to add more keys to the game without destroying the config.
*/
if (!strcmp (keyword, "key_p1_up"))
keyb_gamekeys.keycode[BCPK_up] = atoi (value);
if (!strcmp (keyword, "key_p1_down"))
keyb_gamekeys.keycode[BCPK_down] = atoi (value);
if (!strcmp (keyword, "key_p1_left"))
keyb_gamekeys.keycode[BCPK_left] = atoi (value);
if (!strcmp (keyword, "key_p1_right"))
keyb_gamekeys.keycode[BCPK_right] = atoi (value);
if (!strcmp (keyword, "key_p1_bomb"))
keyb_gamekeys.keycode[BCPK_drop] = atoi (value);
if (!strcmp (keyword, "key_p1_special"))
keyb_gamekeys.keycode[BCPK_special] = atoi (value);
if (!strcmp (keyword, "key_p2_up"))
keyb_gamekeys.keycode[BCPK_max + BCPK_up] = atoi (value);
if (!strcmp (keyword, "key_p2_down"))
keyb_gamekeys.keycode[BCPK_max + BCPK_down] = atoi (value);
if (!strcmp (keyword, "key_p2_left"))
keyb_gamekeys.keycode[BCPK_max + BCPK_left] = atoi (value);
if (!strcmp (keyword, "key_p2_right"))
keyb_gamekeys.keycode[BCPK_max + BCPK_right] = atoi (value);
if (!strcmp (keyword, "key_p2_bomb"))
keyb_gamekeys.keycode[BCPK_max + BCPK_drop] = atoi (value);
if (!strcmp (keyword, "key_p2_special"))
keyb_gamekeys.keycode[BCPK_max + BCPK_special] = atoi (value);
if (!strcmp (keyword, "key_help"))
keyb_gamekeys.keycode[BCK_help] = atoi (value);
if (!strcmp (keyword, "key_playermenu"))
keyb_gamekeys.keycode[BCK_playermenu] = atoi (value);
if (!strcmp (keyword, "key_mapmenu"))
keyb_gamekeys.keycode[BCK_mapmenu] = atoi (value);
if (!strcmp (keyword, "key_chat"))
keyb_gamekeys.keycode[BCK_chat] = atoi (value);
if (!strcmp (keyword, "key_pause"))
keyb_gamekeys.keycode[BCK_pause] = atoi (value);
if (!strcmp (keyword, "key_fullscreen"))
keyb_gamekeys.keycode[BCK_fullscreen] = atoi (value);
} }
fclose (config); fclose (config);
return 0; return 0;
@ -335,6 +380,29 @@ config_write ()
fprintf (config, "start_speed=%f\n", bman.start_speed); fprintf (config, "start_speed=%f\n", bman.start_speed);
fprintf (config, "bomb_ticking=%f\n", bman.bomb_tickingtime); fprintf (config, "bomb_ticking=%f\n", bman.bomb_tickingtime);
fprintf (config, "dropitemsondeath=%d\n", bman.dropitemsondeath); fprintf (config, "dropitemsondeath=%d\n", bman.dropitemsondeath);
/*
* keyboard config
*/
fprintf (config, "key_p1_up=%d\n", keyb_gamekeys.keycode[BCPK_up]);
fprintf (config, "key_p1_down=%d\n", keyb_gamekeys.keycode[BCPK_down]);
fprintf (config, "key_p1_left=%d\n", keyb_gamekeys.keycode[BCPK_left]);
fprintf (config, "key_p1_right=%d\n", keyb_gamekeys.keycode[BCPK_right]);
fprintf (config, "key_p1_bomb=%d\n", keyb_gamekeys.keycode[BCPK_drop]);
fprintf (config, "key_p1_special=%d\n", keyb_gamekeys.keycode[BCPK_special]);
fprintf (config, "key_p2_up=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_up]);
fprintf (config, "key_p2_down=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_down]);
fprintf (config, "key_p2_left=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_left]);
fprintf (config, "key_p2_right=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_right]);
fprintf (config, "key_p2_bomb=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_drop]);
fprintf (config, "key_p2_special=%d\n", keyb_gamekeys.keycode[BCPK_max + BCPK_special]);
fprintf (config, "key_help=%d\n", keyb_gamekeys.keycode[BCK_help]);
fprintf (config, "key_fullscreen=%d\n", keyb_gamekeys.keycode[BCK_fullscreen]);
fprintf (config, "key_chat=%d\n", keyb_gamekeys.keycode[BCK_chat]);
fprintf (config, "key_mapmenu=%d\n", keyb_gamekeys.keycode[BCK_mapmenu]);
fprintf (config, "key_pause=%d\n", keyb_gamekeys.keycode[BCK_pause]);
fprintf (config, "key_playermenu=%d\n", keyb_gamekeys.keycode[BCK_playermenu]);
fclose (config); fclose (config);
return 0; return 0;
} }

@ -1,4 +1,4 @@
/* $Id: game.c,v 1.80 2004/02/08 00:40:20 stpohle Exp $ /* $Id: game.c,v 1.81 2004/04/03 13:55:30 stpohle Exp $
game.c - procedures for the game. */ game.c - procedures for the game. */
#include <string.h> #include <string.h>
@ -11,6 +11,7 @@
#include "chat.h" #include "chat.h"
#include "flyingitems.h" #include "flyingitems.h"
#include "menu.h" #include "menu.h"
#include "keyb.h"
extern int blitdb_nr, extern int blitdb_nr,
blitrects_nr; blitrects_nr;
@ -134,13 +135,55 @@ game_draw_info ()
}; };
/*
* keyboard handling for keys which have nothing to do with the playerkeys
* before calling this function make sure keyb_loop (); was called.
*/
void game_keys_loop () {
if (GT_MP_PTPM && keyb_gamekeys.state[BCK_pause] && !keyb_gamekeys.old[BCK_pause]) {
/* Server is starting the game */
bman.state = GS_running;
net_send_servermode ();
bman.updatestatusbar = 1; // force an update
}
if (keyb_gamekeys.state[BCK_fullscreen] && !keyb_gamekeys.old[BCK_fullscreen]) {
/* Switch Fullscreen */
SDL_WM_ToggleFullScreen(gfx.screen);
gfx.fullscreen = !gfx.fullscreen;
bman.updatestatusbar = 1; // force an update
}
/*
if (keys[SDLK_F9] && event.type == SDL_KEYDOWN) {
// Switch Debugmode
debug = !debug;
bman.updatestatusbar = 1; // force an update
}
*/
if (keyb_gamekeys.state[BCK_esc] && !keyb_gamekeys.old[BCK_esc]) {
if (chat.active) {
chat.active = 0;
d_printf ("Chatmode Disabled\n");
}
else
bman.state = GS_startup;
}
if (keyb_gamekeys.state[BCK_chat] && !keyb_gamekeys.old[BCK_chat]) {
chat.active = 1;
d_printf ("Chatmode Enabled\n");
}
};
void void
game_loop () game_loop ()
{ {
SDL_Event event; SDL_Event event;
Uint8 *keys;
int done = 0, i; int done = 0, i;
unsigned char key_bomb = 0; // last state of the bomb key
gfx_blitupdaterectclear (); gfx_blitupdaterectclear ();
@ -163,73 +206,26 @@ game_loop ()
bman.state = GS_quit; bman.state = GS_quit;
} }
/* keyboard handling */ /*
keys = SDL_GetKeyState (NULL); * input handling
*/
keyb_loop (&event);
/* only do movements if we're alife and GS_running */ game_keys_loop ();
if ((players[bman.p_nr].state & PSFM_alife) == PSFM_alife && bman.state == GS_running) {
if (keys[SDLK_UP]) {
players[bman.p_nr].d = up;
players[bman.p_nr].m = 1;
}
if (keys[SDLK_DOWN]) {
players[bman.p_nr].d = down;
players[bman.p_nr].m = 1;
}
if (keys[SDLK_RIGHT]) {
players[bman.p_nr].d = right;
players[bman.p_nr].m = 1;
}
if (keys[SDLK_LEFT]) {
players[bman.p_nr].d = left;
players[bman.p_nr].m = 1;
}
if (keys[SDLK_LCTRL] || keys[SDLK_RCTRL]) {
if (key_bomb == 0)
player_drop_bomb (bman.p_nr);
key_bomb = 1;
}
else
key_bomb = 0;
if ((keys[SDLK_LSHIFT] || keys[SDLK_RSHIFT]) && players[bman.p_nr].special.type) {
special_use (bman.p_nr);
}
}
else if (GT_MP_PTPM && keys[SDLK_F4] && event.type == SDL_KEYDOWN) {
/* Server is starting the game */
bman.state = GS_running;
net_send_servermode ();
bman.updatestatusbar = 1; // force an update
}
if (keys[SDLK_F8] && event.type == SDL_KEYDOWN) {
/* Switch Fullscreen */
SDL_WM_ToggleFullScreen(gfx.screen);
gfx.fullscreen = !gfx.fullscreen;
bman.updatestatusbar = 1; // force an update
}
if (keys[SDLK_F9] && event.type == SDL_KEYDOWN) {
/* Switch Debugmode */
debug = !debug;
bman.updatestatusbar = 1; // force an update
}
if (event.key.keysym.sym == SDLK_ESCAPE && event.type == SDL_KEYDOWN) {
bman.state = GS_startup;
done = 1;
}
chat_loop (&event); chat_loop (&event);
restore_players_screen (); restore_players_screen ();
player_check (bman.p_nr);
if (IS_LPLAYER2)
player_check (bman.p2_nr);
dead_playerani (); dead_playerani ();
player_ilness_loop (bman.p_nr);
player_checkdeath (bman.p_nr);
special_loop (); special_loop ();
if ((players[bman.p_nr].state & PSFM_alife) == PSFM_alife) player_move (bman.p_nr);
move_player (bman.p_nr); if (IS_LPLAYER2)
player_move (bman.p2_nr);
if (GT_MP) { if (GT_MP) {
player_calcpos (); player_calcpos ();
@ -239,13 +235,11 @@ game_loop ()
if (bman.state == GS_running) if (bman.state == GS_running)
single_loop (); single_loop ();
/* this will even set the variable "bman.player_nr"
to let us know how much Players are still left */
bomb_loop (); bomb_loop ();
field_loop (); field_loop ();
flitems_loop (); flitems_loop ();
draw_players (); draw_players ();
game_draw_info (); game_draw_info (); // will set the var bman.player_nr
/* check if there is only one player left and the game is in multiplayer mode /* check if there is only one player left and the game is in multiplayer mode
and if there the last dieing animation is done */ and if there the last dieing animation is done */

@ -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;
}
};

@ -1,4 +1,4 @@
/* $Id: player.c,v 1.81 2004/02/11 21:46:48 stpohle Exp $ /* $Id: player.c,v 1.82 2004/04/03 13:55:30 stpohle Exp $
* player.c - everything what have to do with the player */ * player.c - everything what have to do with the player */
#include <SDL.h> #include <SDL.h>
@ -417,9 +417,8 @@ player_checkpos (int x, int y)
/* move the player if he have to move AND check if we are on a block /* move the player if he have to move AND check if we are on a block
or over fire */ or over fire */
void void
move_player (int pl_nr) player_move (int pl_nr)
{ {
int oldd, coll_speed; int oldd, coll_speed;
_player *p = &players[pl_nr]; _player *p = &players[pl_nr];
@ -918,3 +917,32 @@ void player_checkdeath (int pnr) {
bman.updatestatusbar = 1; bman.updatestatusbar = 1;
} }
}; };
/*
* check all player related values and work with the key flags
* call the illness check
*/
void player_check (int pl_nr) {
if (bman.state != GS_running)
return;
/* check if the player is still alife */
if ((players[pl_nr].state & PSFM_alife) == PSFM_alife) {
playerinput_loop (pl_nr);
player_ilness_loop (pl_nr);
if (players[pl_nr].keyf_bomb)
player_drop_bomb (pl_nr);
players[pl_nr].keyf_bomb = 0;
if (players[pl_nr].keyf_special)
special_use (pl_nr);
players[pl_nr].keyf_special = 0;
player_move (pl_nr);
}
else {
players[pl_nr].m = 0;
}
player_checkdeath (pl_nr);
};

@ -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;
};

@ -1,4 +1,4 @@
/* $Id: single.c,v 1.60 2004/02/07 15:03:25 stpohle Exp $ */ /* $Id: single.c,v 1.61 2004/04/03 13:55:30 stpohle Exp $ */
/* single player */ /* single player */
#include "basic.h" #include "basic.h"
@ -700,7 +700,7 @@ single_loop ()
pl->m = 1; pl->m = 1;
} }
player_ilness_loop (p); player_ilness_loop (p);
move_player (p); player_move (p);
} }
else else
player_checkdeath (p); player_checkdeath (p);

Loading…
Cancel
Save