SinglePlayer setp 1 - you will see now some singleplayers. But they are still not walking.. but illness and all this will already work on them

origin
stpohle 23 years ago
parent 008a712d21
commit 871e349f63

@ -7,7 +7,7 @@
#define GAME_SPECIAL_ITEMBOMB 10
#define GAME_SPECIAL_ITEMFIRE 10
#define GAME_SPECIAL_ITEMSHOE 15
#define GAME_SPECIAL_ITEMDEATH 25
#define GAME_SPECIAL_ITEMDEATH 25
#define GAME_SPECIAL_ITEMMIXED 10
#define START_BOMBS 1
@ -50,7 +50,7 @@
#define DEFAULT_UDPPORT 11000
#define DEFAULT_GMUDPPORT "11100"
#define DEFAULT_GAMEMASTER "x.yz.to:11100"
#define GAMESRV_TIMEOUT 2000 /* Timeout of the GameSrv_GetEntry */
#define GAMESRV_TIMEOUT 2000 /* Timeout of the GameSrv_GetEntry */
#define UDP_TIMEOUT 15000
#define BUF_SIZE 1024
@ -89,26 +89,26 @@ enum _fieldtype {
FT_nothing = 0, // Nothing in here
FT_stone, // Stones you can bomb away
FT_block, // Stones which can't bomb away
FT_death, // The bad Powerup
FT_death, // The bad Powerup
FT_fire, // The fire Powerup
FT_bomb, // The bomb Powerup
FT_shoe, // The shoe Powerup
FT_mixed, // The mixed Powerup
FT_bomb, // The bomb Powerup
FT_shoe, // The shoe Powerup
FT_mixed, // The mixed Powerup
FT_max // just to know how many types there are
};
enum _playerillnestype {
PI_keys = 0, // switch keys
PI_range, // set exploding range to 1
PI_slow, // sets speed to 6
PI_fast, // sets speed to 150
PI_bomb, // player is dropping bombs permanently
PI_nobomb, // player cannot drop a bomb or only 1 bomb
PI_max // just to know what is the last number
PI_keys = 0, // switch keys
PI_range, // set exploding range to 1
PI_slow, // sets speed to 6
PI_fast, // sets speed to 150
PI_bomb, // player is dropping bombs permanently
PI_nobomb, // player cannot drop a bomb or only 1 bomb
PI_max // just to know what is the last number
};
@ -120,10 +120,10 @@ enum _bombstate {
enum _playerstateflags {
PSF_used = 1, // Player Unused | Player Used
PSF_net = 2, // Local Player | AI / Network Player
PSF_alife = 4, // Player is Dead | Player is Alife
PSF_playing = 8, // Watching Player | Playing Player -- as long as one don't delete
PSF_used = 1, // Player Unused | Player Used
PSF_net = 2, // Local Player | AI / Network Player
PSF_alife = 4, // Player is Dead | Player is Alife
PSF_playing = 8, // Watching Player | Playing Player -- as long as one don't delete
};
#define PSFM_used (PSF_used + PSF_playing)
@ -142,8 +142,8 @@ enum _direction { // to handle directions better
};
struct __point {
short int x;
short int y;
short int x;
short int y;
} typedef _point;
#endif

@ -1,4 +1,4 @@
/* $Id: bomberclone.h,v 1.19 2003/05/11 03:27:18 patty21 Exp $ */
/* $Id: bomberclone.h,v 1.20 2003/05/11 17:27:30 stpohle Exp $ */
/* bomberclone.h */
#ifndef _BOMBERCLONE_H_
@ -192,7 +192,7 @@ extern void player_calcstep (_player * pl);
extern void player_calcpos ();
extern void player_set_ilness (_player *p, int t);
extern void player_clear_ilness (_player *p, int type);
extern void player_ilness_loop ();
extern void player_ilness_loop (int pl_nr);
extern void player_check_powerup (_player * p);
extern void player_set_gfx (_player *p, signed char gfx_nr);
@ -231,8 +231,9 @@ extern void d_printf (char *fmt,...);
// single.c
extern void single_game_new ();
extern void single_create_ai ();
extern void single_create_ai (int players);
extern void single_loop();
extern void single_playergame ();
// mapmenu.c
extern void map_random ();

@ -11,7 +11,8 @@
extern int UpdateRects_nr;
static Uint32 timediff;
static Uint32 timediff,
timediff1;
void
game_draw_info ()
@ -21,37 +22,42 @@ game_draw_info ()
j;
char text[255];
char scrtext[255];
SDL_Rect src, dest;
redraw_logo (0, 0, gfx.res.x, 3*16);
if (bman.updatestatusbar) {gfx_AddUpdateRect (0,0, gfx.res.x, 3*16);bman.updatestatusbar=0;}
SDL_Rect src,
dest;
redraw_logo (0, 0, gfx.res.x, 3 * 16);
if (bman.updatestatusbar) {
gfx_AddUpdateRect (0, 0, gfx.res.x, 3 * 16);
bman.updatestatusbar = 0;
}
bman.players_nr = 0;
/* draw Player names */
if (GT_MP_PTP) {
/* In Multiplayer mode draw Player names and
count the players who are still alife. */
for (x = 0, j = 0, i = 0; i < MAX_PLAYERS; i++)
if ((bman.players[i].state & PSFM_used) != 0) {
if (bman.players[i].gfx_nr != -1 && PS_IS_used (bman.players[i].state)) {
src.x = 3 * bman.players[i].gfx->smal_size.x;
src.y = 0;
src.w = dest.w = bman.players[i].gfx->smal_size.x;
src.h = dest.h = bman.players[i].gfx->smal_size.y;
dest.x = x;
dest.y = j - 4;
SDL_BlitSurface (bman.players[i].gfx->smal_image, &src, gfx.screen, &dest);
}
if (bman.players[i].gfx_nr != -1 && PS_IS_used (bman.players[i].state)) {
src.x = 3 * bman.players[i].gfx->smal_size.x;
src.y = 0;
src.w = dest.w = bman.players[i].gfx->smal_size.x;
src.h = dest.h = bman.players[i].gfx->smal_size.y;
dest.x = x;
dest.y = j - 4;
SDL_BlitSurface (bman.players[i].gfx->smal_image, &src, gfx.screen, &dest);
}
sprintf (scrtext, "%10s:%2d", bman.players[i].name, bman.players[i].points);
if ((bman.players[i].state & PSFM_alife) != PSFM_alife) { // Player is dead
draw_text (x, j, scrtext, 0);
draw_text (x, j, scrtext, 0);
if ((bman.players[i].state & PSF_used) != PSF_used)
draw_text (x, j, "-------------", 1);
}
else { // players is alife
draw_text (x, j, "-------------", 1);
}
else { // players is alife
draw_text (x, j, scrtext, 1);
bman.players_nr++;
}
@ -63,6 +69,12 @@ game_draw_info ()
}
}
}
else
/* in single mode count the player's who are still alife */
for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_alife (bman.players[i].state))
bman.players_nr++;
x = gfx.res.x - 120;
sprintf (text, "Bombs: %2d", bman.players[bman.p_nr].bombs_n);
@ -76,31 +88,30 @@ game_draw_info ()
draw_text (100, 32, "Press F4 to start the game", 1);
else if (bman.state == GS_ready)
draw_text (100, 32, "Waiting for the Server to Start", 1);
// gfx_AddUpdateRect (100, 32, gfx.res.x - 100, 16);
redraw_logo (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.res.y);
if (debug) { /* do some debug informations on the screen */
for (x = 0; x < bman.fieldsize.x; x++)
draw_stone (x, bman.fieldsize.y-1);
if (GT_MP_PTP) {
sprintf (text, "NET_STAT: [");
for (i = 0 ; i < MAX_PLAYERS; i++)
sprintf (text, "%s%3d ", text, bman.players[i].net.pkgopt.send_set);
text[strlen(text)+1] = 0;
text[strlen(text)] = ']';
draw_text (0, gfx.res.y - (gfx.font.size.y << 1), text, 1);
}
sprintf (text, "TILESET: %s Timediff: %d", gfx.tileset, timediff);
sprintf (text, "%s GFX_RECTS:%d", text, UpdateRects_nr);
draw_text (0, gfx.res.y - gfx.font.size.y, text, 1);
gfx_AddUpdateRect (0, gfx.res.y - (gfx.font.size.y << 1), gfx.res.x, gfx.font.size.y << 1);
}
if (chat.visible == 0 && GT_MP_PTP) {
chat_show (4, 3*16, gfx.res.x - 4, gfx.offset.y);
}
redraw_logo (0, gfx.res.y - gfx.font.size.y, gfx.res.x, gfx.res.y);
if (debug) { /* do some debug informations on the screen */
for (x = 0; x < bman.fieldsize.x; x++)
draw_stone (x, bman.fieldsize.y - 1);
if (GT_MP_PTP) {
sprintf (text, "NET_STAT: [");
for (i = 0; i < MAX_PLAYERS; i++)
sprintf (text, "%s%3d ", text, bman.players[i].net.pkgopt.send_set);
text[strlen (text) + 1] = 0;
text[strlen (text)] = ']';
draw_text (0, gfx.res.y - (gfx.font.size.y << 1), text, 1);
}
sprintf (text, "TILESET: %s Tframe: %d Tloop: %d", gfx.tileset, timediff, timediff1);
sprintf (text, "%s GFX_RECTS:%d", text, UpdateRects_nr);
draw_text (0, gfx.res.y - gfx.font.size.y, text, 1);
gfx_AddUpdateRect (0, gfx.res.y - (gfx.font.size.y << 1), gfx.res.x, gfx.font.size.y << 1);
}
if (chat.visible == 0 && GT_MP_PTP) {
chat_show (4, 3 * 16, gfx.res.x - 4, gfx.offset.y);
}
};
@ -111,8 +122,7 @@ game_loop ()
Uint8 *keys;
int done = 0;
Uint32 timeloop1;
int move=0;
int gameovertimeout = TIME_FACTOR * 5; // gameovertimeout
int gameovertimeout = TIME_FACTOR * 5; // gameovertimeout
unsigned char key_bomb = 0; // last state of the bomb key
draw_logo ();
@ -125,7 +135,8 @@ game_loop ()
timestamp = SDL_GetTicks (); // needed for time sync.
d_gamedetail ("GAME START");
draw_players();
draw_players ();
while (!done && (bman.state == GS_running || bman.state == GS_ready)) {
if (SDL_PollEvent (&event) != 0)
switch (event.type) {
@ -176,35 +187,33 @@ game_loop ()
bman.state = GS_startup;
done = 1;
}
move=bman.players[bman.p_nr].m;
chat_loop (&event);
if (move ||dead_playerani () || GT_MP_PTP) restore_players_screen ();
player_ilness_loop ();
chat_loop (&event);
restore_players_screen ();
dead_playerani ();
player_ilness_loop (bman.p_nr);
if ((bman.players[bman.p_nr].state & PSFM_alife) == PSFM_alife)
move_player ();
player_calcpos ();
if (bman.gametype != GT_single)
network_loop ();
else
single_loop ();
else
single_loop ();
/* this will even set the variable "bman.player_nr"
to let us know how much Players are still left */
if (bomb_loop () || move || GT_MP_PTP) draw_players ();
move=0;
bomb_loop ();
draw_players ();
game_draw_info ();
gfx_UpdateRects ();
/* check if there is only one player left and the game is in multiplayer mode
and if there the last dieing animation is done */
if ((GT_MP_PTPM) && bman.players_nr < 2)
gameovertimeout--;
/* check if we died and we are in single mode and the animation is done */
if (bman.gametype == GT_single && !PS_IS_alife(bman.players[bman.p_nr].state))
if (bman.players_nr < 2)
gameovertimeout--;
if (gameovertimeout <= 0) {
@ -214,18 +223,19 @@ game_loop ()
// calculate time sync.
timeloop1 = SDL_GetTicks ();
timediff = timeloop1 - timestamp; // only for debugging needed
timediff = timeloop1 - timestamp; // only for debugging needed
while (timeloop1 - timestamp >= 0 && timeloop1 - timestamp < 20) {
s_delay (20 - (timeloop1 - timestamp) - 1);
timeloop1 = SDL_GetTicks ();
}
timediff1 = timeloop1 - timestamp;
timestamp = timeloop1;
}
chat_show (-1, -1, -1, -1);
chat_show (-1, -1, -1, -1);
d_gamedetail ("GAME END");
d_printf ("done = %d\n", done);
};
@ -235,22 +245,20 @@ game_loop ()
void
game_end ()
{
int i;
/* count the points */
int i;
/* count the points */
for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_used (bman.players[i].state)) {
if (PS_IS_alife (bman.players[i].state)) {
bman.lastwinner = i;
bman.players[i].wins++;
bman.players[i].points += bman.players_nr_s;
bman.players[i].points += bman.players_nr_s;
}
}
/* check which player is now free ,i.e. disconnected during the game and was playing */
for (i = 0; i < MAX_PLAYERS; i++)
if ((bman.players[i].state & PSF_used ) == 0)
bman.players[i].state = 0;
}
/* check which player is now free ,i.e. disconnected during the game and was playing */
for (i = 0; i < MAX_PLAYERS; i++)
if ((bman.players[i].state & PSF_used) == 0)
bman.players[i].state = 0;
}

@ -52,11 +52,7 @@ main (int argc, char **argv)
switch (menuselect) {
case (0) : // Singleplayer
single_game_new ();
single_create_ai ();
gfx_game_init ();
game_loop ();
gfx_game_shutdown ();
single_playergame ();
break;
case (1) : // Multiplayer
netmenu();

@ -58,9 +58,8 @@ restore_players_screen ()
{
int i,
x,
xs,
xe,
xs,
xe,
y,
ys,
ye;
@ -86,14 +85,15 @@ restore_players_screen ()
ys = 0;
if (ye >= bman.fieldsize.y)
ye = bman.fieldsize.y - 1;
xs=x;
xs = x;
for (; x <= xe; x++)
for (y = ys; y <= ye; y++)
draw_stone (x, y);
gfx_AddUpdateRect(xs*gfx.block.x+gfx.offset.x,ys*gfx.block.y+gfx.offset.y,gfx.block.x*3,gfx.block.y*3);
gfx_AddUpdateRect (xs * gfx.block.x + gfx.offset.x, ys * gfx.block.y + gfx.offset.y,
gfx.block.x * 3, gfx.block.y * 3);
}
}
};
@ -104,7 +104,8 @@ player_check_powerup (_player * p)
int fy = p->pos.y >> 8;
int _x = p->pos.x & 255;
int _y = p->pos.y & 255;
int ft,i;
int ft,
i;
/* Get the right field position */
if (_x > 128)
@ -113,59 +114,74 @@ player_check_powerup (_player * p)
if (_y > 128)
fy = fy + 1;
ft=bman.field[fx][fy].type;
/* we found a mixed powerup */
if (ft==FT_mixed) {
i=s_random(6);
switch (i) {
case 0:ft=FT_bomb;break;
case 1:ft=FT_fire;break;
case 2:ft=FT_shoe;break;
case 3:
case 4:
case 5:ft=FT_death;break;
}
}
switch(ft) {
/* we found a bomb powerup */
ft = bman.field[fx][fy].type;
/* we found a mixed powerup */
if (ft == FT_mixed) {
i = s_random (6);
switch (i) {
case 0:
ft = FT_bomb;
break;
case 1:
ft = FT_fire;
break;
case 2:
ft = FT_shoe;
break;
case 3:
case 4:
case 5:
ft = FT_death;
break;
}
}
switch (ft) {
/* we found a bomb powerup */
case FT_bomb:
if (p->bombs_n < MAX_BOMBS && p->ill[PI_nobomb].to <= 0)
{p->bombs_n++;bman.updatestatusbar=1;}
if (p->bombs_n < MAX_BOMBS && p->ill[PI_nobomb].to <= 0) {
p->bombs_n++;
bman.updatestatusbar = 1;
}
bman.field[fx][fy].type = FT_nothing;
if (bman.gametype != GT_single)
net_game_send_field (fx, fy);
break;
break;
/* we found a fire powerup */
/* we found a fire powerup */
case FT_fire:
if (p->range < MAX_RANGE && p->ill[PI_range].to <= 0)
{p->range++;bman.updatestatusbar=1;}
if (p->range < MAX_RANGE && p->ill[PI_range].to <= 0) {
p->range++;
bman.updatestatusbar = 1;
}
bman.field[fx][fy].type = FT_nothing;
if (bman.gametype != GT_single)
net_game_send_field (fx, fy);
break;
break;
/* we found a shoe powerup */
/* we found a shoe powerup */
case FT_shoe:
if (p->speed < MAX_SPEED && p->ill[PI_slow].to <= 0)
{p->speed *= SPEEDMUL;bman.updatestatusbar=1;}
if (p->speed < MAX_SPEED && p->ill[PI_slow].to <= 0) {
p->speed *= SPEEDMUL;
bman.updatestatusbar = 1;
}
bman.field[fx][fy].type = FT_nothing;
if (bman.gametype != GT_single)
net_game_send_field (fx, fy);
break;
break;
/* we found a death ?powerup? */
/* we found a death ?powerup? */
case FT_death:
player_set_ilness (p, -1);
bman.updatestatusbar=1;
net_game_send_ill (bman.p_nr);
bman.updatestatusbar = 1;
if (bman.gametype != GT_single)
net_game_send_ill (bman.p_nr);
bman.field[fx][fy].type = FT_nothing;
if (bman.gametype != GT_single)
net_game_send_field (fx, fy);
break;
}
break;
}
};
@ -389,7 +405,8 @@ player_died (_player * player, signed char dead_by)
player->state &= (0xFF - PSF_alife);
player->dead_by = dead_by;
net_game_send_player (bman.p_nr);
if (GT_MP_PTP)
net_game_send_player (bman.p_nr);
};
@ -428,12 +445,15 @@ player_animation (_player * player)
int
dead_playerani ()
{
int i,b=0;
int i,
b = 0;
for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_dead (bman.players[i].state))
{player_animation (&bman.players[i]);b++;}
return b;
if (PS_IS_dead (bman.players[i].state)) {
player_animation (&bman.players[i]);
b++;
}
return b;
};
@ -505,7 +525,7 @@ player_calcpos ()
void
player_ilness_loop ()
player_ilness_loop (int pl_nr)
{
_player *p;
int type,
@ -516,28 +536,29 @@ player_ilness_loop ()
int pl[MAX_PLAYERS + 1];
/* do the illness for the network players */
for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
if (pnr != bman.p_nr && PS_IS_alife (bman.players[pnr].state)) {
p = &bman.players[pnr];
for (type = 0; type < PI_max; type++)
if (p->ill[type].to > 0) {
p->ill[type].to--;
p->illframeto--;
if (p->illframeto <= 0 || p->illframeto > ANI_PLAYERILLTIMEOUT) {
p->illframeto = ANI_PLAYERILLTIMEOUT;
p->illframe++;
if (p->illframe < 0 || p->illframe >= gfx.ill.frames)
p->illframe = 0;
if (GT_MP_PTP) {
for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
if (pnr != pl_nr && PS_IS_alife (bman.players[pnr].state)) {
p = &bman.players[pnr];
for (type = 0; type < PI_max; type++)
if (p->ill[type].to > 0) {
p->ill[type].to--;
p->illframeto--;
if (p->illframeto <= 0 || p->illframeto > ANI_PLAYERILLTIMEOUT) {
p->illframeto = ANI_PLAYERILLTIMEOUT;
p->illframe++;
if (p->illframe < 0 || p->illframe >= gfx.ill.frames)
p->illframe = 0;
}
}
}
}
}
}
/* check if we have contact with an other ill player */
p = &bman.players[bman.p_nr];
p = &bman.players[pl_nr];
get_player_on (p->pos.x, p->pos.y, pl);
for (i = 0; (pl[i] != -1 && i < MAX_PLAYERS); i++)
if (pl[i] != bman.p_nr) {
if (pl[i] != pl_nr) {
send = 0;
for (type = 0; type < PI_max; type++) {
if (bman.players[pl[i]].ill[type].to > p->ill[type].to) {
@ -548,11 +569,11 @@ player_ilness_loop ()
send = 1;
}
}
if (send != 0)
net_game_send_ill (bman.p_nr);
if (send != 0 && GT_MP_PTP)
net_game_send_ill (pl_nr);
}
/* do the illness for our own player */
/* do the illness for the givin player */
for (type = 0; type < PI_max; type++)
if (p->ill[type].to > 0) {
p->ill[type].to--;
@ -644,7 +665,7 @@ player_set_ilness (_player * p, int t)
break;
}
bman.updatestatusbar=1;
bman.updatestatusbar = 1;
p->ill[type].to += TIME_FACTOR * IL_TIMEOUT;
};
@ -669,8 +690,9 @@ player_clear_ilness (_player * p, int type)
}
p->ill[type].to = 0;
net_game_send_ill (bman.p_nr);
bman.updatestatusbar=1;
if (bman.gametype != GT_single)
net_game_send_ill (bman.p_nr);
bman.updatestatusbar = 1;
};

@ -1,21 +1,30 @@
/* $Id: single.c,v 1.10 2003/05/08 14:35:49 stpohle Exp $ */
/* $Id: single.c,v 1.11 2003/05/11 17:27:30 stpohle Exp $ */
/* single player */
#include "basic.h"
#include "bomberclone.h"
void
single_game_new (int ai_players)
single_game_new ()
{
int p,
i;
// set players on field 1,1
bman.players_nr_s = 1;
bman.players_nr = 1;
// set players variables
for (p = 0; p < MAX_PLAYERS; p++) {
bman.players[p].pos.x = -1;
bman.players[p].pos.y = -1;
bman.players[p].state = 0;
if (PS_IS_used (bman.players[p].state)) {
bman.players_nr_s++;
bman.players_nr++;
bman.players[p].state = PSF_used + PSF_alife + PSF_playing;
}
else
bman.players[p].state = 0;
// reset bombs
bman.players[p].bombs_n = START_BOMBS;
bman.players[p].range = START_RANGE;
@ -32,35 +41,73 @@ single_game_new (int ai_players)
bman.players[p].d = 0;
}
bman.p_nr = 0;
for (bman.p_nr = -1, p = 0; (bman.p_nr == -1 && p < MAX_PLAYERS); p++)
if (!(PS_IS_used (bman.players[p].state)))
bman.p_nr = p;
if (bman.p_nr >= MAX_PLAYERS) {
printf ("ERROR in function (single_game_new): couldn't find any free player\n");
exit (1);
}
bman.players[bman.p_nr].state = PSFM_alife;
player_set_gfx (&bman.players[bman.p_nr], 0);
player_set_gfx (&bman.players[bman.p_nr], 0);
bman.last_ex_nr = 1;
init_map_tileset();
init_map_tileset ();
bman.players_nr_s = 1;
bman.players_nr = 1;
bman.gametype = GT_single;
bman.state = GS_running;
};
void single_loop () {
void
single_loop ()
{
int p;
_player *pl;
for (p = 0; p < MAX_PLAYERS; p++)
if (p != bman.p_nr && PS_IS_playing (bman.players[p].state)) {
pl = &bman.players[p];
player_ilness_loop (p);
}
};
/* create a giving number of ai players */
void
single_create_ai (int players)
{
int p;
int count;
_player *pl;
for (count = 0; count < players; count++) {
/* find free players */
for (pl = NULL, p = 0; (pl == NULL && p < MAX_PLAYERS); p++)
if (!(PS_IS_used (bman.players[p].state))) {
pl = &bman.players[p];
pl->state |= PSF_used + PSF_alife + PSF_playing;
player_set_gfx (pl, s_random (MAX_PLAYERS));
}
if (pl == NULL)
return;
}
};
void single_create_ai () {
void single_playergame () {
int p;
_player *pl;
/* find free players */
for (pl = NULL, p = 0; (pl == NULL && p < MAX_PLAYERS); p++)
if (!(PS_IS_used (bman.players[p].state)))
pl = &bman.players[p];
if (pl == NULL)
return;
};
/* delete player from the game */
for (p = 0; p < MAX_PLAYERS; p++)
bman.players[p].state = 0;
single_create_ai (4);
single_game_new ();
gfx_game_init ();
game_loop ();
gfx_game_shutdown ();
};
Loading…
Cancel
Save