From 31b48aedc736635d8e2e6c97cff93bb59ef179ce Mon Sep 17 00:00:00 2001 From: stpohle Date: Sun, 27 Jul 2003 14:34:37 +0000 Subject: [PATCH] end sequence of the game will now work fine.. without problems... maybe timeouts have to be raised up alittle. --- ChangeLog | 9 +- TODO | 10 +-- src/bomb.c | 5 +- src/bomberclone.h | 3 +- src/field.c | 37 ++++++-- src/map.c | 179 +++++++++++++++++++------------------ src/player.c | 220 ++++++++++++++++++++++++++++------------------ 7 files changed, 277 insertions(+), 186 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4cd6dd5..18f5fe9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,14 @@ -$Id: ChangeLog,v 1.32 2003/07/25 12:28:50 stpohle Exp $ +$Id: ChangeLog,v 1.33 2003/07/27 14:34:37 stpohle Exp $ Version 0.9.10 ============== +- added: two ways the game can end now. the old Bomberman + style with getting the size of the gamefield down and + another one with putting in the game alot of powerups. + the game even have a timeout of 10 minutes + the + 2 minutes of the end game sequenze. + - Makefile.am fixed in the data direktory. Added ${prefix}/ and changed @PREFIX_PACKAGE_DATA_DIR@ to @NO_PREFIX_PACKAGE_DATA_DIR@ . So debian packages @@ -378,4 +384,3 @@ Version 0.1 the bombs are exploding. - Basic Graphics, just some experiments within the game - diff --git a/TODO b/TODO index a9949f6..f1d67aa 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,4 @@ -$Id: TODO,v 1.18 2003/07/25 21:44:47 stpohle Exp $ - -- player selection screen for the single player +$Id: TODO,v 1.19 2003/07/27 14:34:38 stpohle Exp $ - more specials (Kicking Bomb, Pushing Bomb Ver.2) @@ -16,8 +14,10 @@ $Id: TODO,v 1.18 2003/07/25 21:44:47 stpohle Exp $ - add musicfiles with type of mp3, mod, xm, s3m and mid (but i don't know how i can do this) -- animated fire +- better animated fire + +- more gfx players to select? -- more players +- team mode - we need some more sound for picking up items. diff --git a/src/bomb.c b/src/bomb.c index 89aaabd..6af4051 100644 --- a/src/bomb.c +++ b/src/bomb.c @@ -1,4 +1,4 @@ -/* $Id: bomb.c,v 1.37 2003/07/23 02:10:47 stpohle Exp $ */ +/* $Id: bomb.c,v 1.38 2003/07/27 14:34:39 stpohle Exp $ */ /* everything what have to do with the bombs */ #include "bomberclone.h" @@ -198,6 +198,9 @@ bomb_loop () return b; }; + +/* check if on the givin place is a bomb + bombs[].x = player, bombs[].y = bombnumber */ void get_bomb_on (short int x, short int y, _point bombs[]) { diff --git a/src/bomberclone.h b/src/bomberclone.h index 6097049..5ddd054 100644 --- a/src/bomberclone.h +++ b/src/bomberclone.h @@ -1,4 +1,4 @@ -/* $Id: bomberclone.h,v 1.48 2003/07/27 13:29:25 stpohle Exp $ */ +/* $Id: bomberclone.h,v 1.49 2003/07/27 14:34:40 stpohle Exp $ */ /* bomberclone.h */ #ifndef _BOMBERCLONE_H_ @@ -213,6 +213,7 @@ extern void player_ilness_loop (int pl_nr); extern void player_check_powerup (int p_nr); extern void player_set_gfx (_player *p, signed char gfx_nr); extern int player_findfreebomb (_player *player); +extern int player_checkpos (int x, int y); // for the bomb.. extern int bomb_loop (); diff --git a/src/field.c b/src/field.c index 5e9d8ff..672aabb 100644 --- a/src/field.c +++ b/src/field.c @@ -1,4 +1,4 @@ -/* $Id: field.c,v 1.39 2003/07/27 13:29:25 stpohle Exp $ */ +/* $Id: field.c,v 1.40 2003/07/27 14:34:40 stpohle Exp $ */ /* field.c - procedures which are needed to control the field */ #include "bomberclone.h" @@ -386,6 +386,7 @@ void field_hurrysize () { int i; + _point old; if (fieldhurry_to-- <= 0 || fieldhurry_to > FIELDHURRYSIZE) { fieldhurry_to = FIELDHURRYSIZE; @@ -396,7 +397,8 @@ field_hurrysize () } else if (fieldhurrypos.x > 0) { bman.timeout = GAME_TIMEOUTHURRY-1; - + old = fieldhurrypos; /* save old value in case that there + is an explosion or a bomb */ switch (fieldhurryd) { case (right): if (fieldhurrypos.x + 1 >= map.size.x - fieldhurrypos.y) { @@ -443,12 +445,31 @@ field_hurrysize () /* check if we have finished sizing down everything */ if (fieldhurrypos.x > 0) { - /* set the block on the position */ - map.field[fieldhurrypos.x][fieldhurrypos.y].type = FT_block; - stonelist_add (fieldhurrypos.x, fieldhurrypos.y); - - if (GT_MP_PTPM) - net_game_send_field (fieldhurrypos.x, fieldhurrypos.y); + _point bombs[MAX_PLAYERS*MAX_BOMBS]; + int i, d; + + /* check if a bomb is at this position, if so let the bomb explode + and wait untill the explosion is over */ + for (i = 0, d = 0; d < 4; d++) + if (map.field[fieldhurrypos.x][fieldhurrypos.y].ex[d].count > 0) + i++; + + get_bomb_on (fieldhurrypos.x << 8, fieldhurrypos.y << 8, bombs); + if (i) + fieldhurrypos = old; + else if (bombs[0].y != -1 && bombs[0].x != -1) { + fieldhurrypos = old; + bomb_explode (bombs[0].x, bombs[0].y, 1); + } + else { + /* set the block on the position */ + map.field[fieldhurrypos.x][fieldhurrypos.y].type = FT_block; + map.field[fieldhurrypos.x][fieldhurrypos.y].special = FT_nothing; + map.field[fieldhurrypos.x][fieldhurrypos.y].frame = 0; + stonelist_add (fieldhurrypos.x, fieldhurrypos.y); + if (GT_MP_PTPM) + net_game_send_field (fieldhurrypos.x, fieldhurrypos.y); + } } } }; diff --git a/src/map.c b/src/map.c index edb925f..f89539b 100644 --- a/src/map.c +++ b/src/map.c @@ -1,4 +1,4 @@ -/* $Id: map.c,v 1.3 2003/07/22 18:29:08 stpohle Exp $ */ +/* $Id: map.c,v 1.4 2003/07/27 14:34:40 stpohle Exp $ */ /* map handling, like generate and load maps. */ #include "bomberclone.h" @@ -52,8 +52,8 @@ map_new (char *filename) fmap = NULL; // Clean and create the field // - if (fmap == NULL) - map_genrandom (); + if (fmap == NULL) + map_genrandom (); /* delete the bfield data */ for (x = 0; x < MAX_FIELDSIZE_X; x++) @@ -83,38 +83,42 @@ map_new (char *filename) // map_fillitems (FT_sp_kick, GAME_SPECIAL_ITEMSKICK); } -void map_genrandom () { - int x, y, d; - - /* if we can't load the map check first the fieldsize settings */ - if (map.size.x < MIN_FIELDSIZE_X) - map.size.x = MIN_FIELDSIZE_X; - if (map.size.x > MAX_FIELDSIZE_X) - map.size.x = MAX_FIELDSIZE_X; - - for (x = 0; x < map.size.x; x++) - for (y = 0; y < map.size.y; y++) { - if ((y == 0) || (y == map.size.y - 1)) - map.field[x][y].type = FT_block; - else if ((x == 0) || (x == map.size.x - 1)) - map.field[x][y].type = FT_block; - else if (((x & 1) == 0) && ((y & 1) == 0)) - map.field[x][y].type = FT_block; - else { - // create random field - if ((s_random (256) & 3) == 0) - map.field[x][y].type = FT_nothing; - else - map.field[x][y].type = FT_stone; - } +void +map_genrandom () +{ + int x, + y, + d; + + /* if we can't load the map check first the fieldsize settings */ + if (map.size.x < MIN_FIELDSIZE_X) + map.size.x = MIN_FIELDSIZE_X; + if (map.size.x > MAX_FIELDSIZE_X) + map.size.x = MAX_FIELDSIZE_X; + + for (x = 0; x < map.size.x; x++) + for (y = 0; y < map.size.y; y++) { + if ((y == 0) || (y == map.size.y - 1)) + map.field[x][y].type = FT_block; + else if ((x == 0) || (x == map.size.x - 1)) + map.field[x][y].type = FT_block; + else if (((x & 1) == 0) && ((y & 1) == 0)) + map.field[x][y].type = FT_block; + else { + // create random field + if ((s_random (256) & 3) == 0) + map.field[x][y].type = FT_nothing; + else + map.field[x][y].type = FT_stone; + } - for (d = 0; d < 4; d++) - map.field[x][y].ex[d].frame = map.field[x][y].ex[d].count = 0; - map.field[x][y].ex_nr = -1; - map.field[x][y].frame = 0; - map.field[x][y].frameto = 0; - map.field[x][y].special = FT_nothing; -} + for (d = 0; d < 4; d++) + map.field[x][y].ex[d].frame = map.field[x][y].ex[d].count = 0; + map.field[x][y].ex_nr = -1; + map.field[x][y].frame = 0; + map.field[x][y].frameto = 0; + map.field[x][y].special = FT_nothing; + } } @@ -249,54 +253,61 @@ map_set_playerposition (int usermap) PLY = PLY << 8; } }; + #undef PLX #undef PLY /* load a random map */ -void map_random () { - _direntry *destart, *de, *desel; - char path[LEN_PATHFILENAME]; - int max, sel; - - sprintf (path, "%s/maps", bman.datapath); - desel = destart = s_getdir (path); - - for (max = 0, de = destart; de != NULL; de = de->next) - if ((de->flags & DF_file) == DF_file) - max++; - - sel = s_random (max); - for (max = 0, de = destart; max <= sel && de != NULL; de = de->next) - if ((de->flags & DF_file) == DF_file) { - desel = de; - max++; - } - - d_printf ("Random Map %s (%d on %d)\n", desel->name, sel, max); - - if (desel != NULL) - sprintf (map.map, "%s/maps/%s", bman.datapath, desel->name); +void +map_random () +{ + _direntry *destart, + *de, + *desel; + char path[LEN_PATHFILENAME]; + int max, + sel; + + sprintf (path, "%s/maps", bman.datapath); + desel = destart = s_getdir (path); + + for (max = 0, de = destart; de != NULL; de = de->next) + if ((de->flags & DF_file) == DF_file) + max++; + + sel = s_random (max); + for (max = 0, de = destart; max <= sel && de != NULL; de = de->next) + if ((de->flags & DF_file) == DF_file) { + desel = de; + max++; + } + + d_printf ("Random Map %s (%d on %d)\n", desel->name, sel, max); + + if (desel != NULL) + sprintf (map.map, "%s/maps/%s", bman.datapath, desel->name); } // Init the game according to options -void init_map_tileset() +void +init_map_tileset () { - switch (map.map_selection) { - case (0): - map_new (map.map); - break; - case (1): - map_random (); - map_new (map.map); - break; - case (2): - map_new (NULL); - break; - } - - if (map.random_tileset) - tileset_random (); + switch (map.map_selection) { + case (0): + map_new (map.map); + break; + case (1): + map_random (); + map_new (map.map); + break; + case (2): + map_new (NULL); + break; + } + + if (map.random_tileset) + tileset_random (); } @@ -322,22 +333,22 @@ map_load (FILE * fmap) continue; /* now each line correspond to the field */ else if (strstr (currentline, "bombs") == currentline) // bombs - map.bombs = atoi (strchr (currentline, '=') + 1); + map.bombs = atoi (strchr (currentline, '=') + 1); else if (strstr (currentline, "fire") == currentline) // fire - map.fire = atoi (strchr (currentline, '=') + 1); + map.fire = atoi (strchr (currentline, '=') + 1); else if (strstr (currentline, "shoes") == currentline) // shoes - map.shoes = atoi (strchr (currentline, '=') + 1); + map.shoes = atoi (strchr (currentline, '=') + 1); else if (strstr (currentline, "mixed") == currentline) // mixed - map.mixed = atoi (strchr (currentline, '=') + 1); + map.mixed = atoi (strchr (currentline, '=') + 1); else if (strstr (currentline, "death") == currentline) // death - map.death = atoi (strchr (currentline, '=') + 1); + map.death = atoi (strchr (currentline, '=') + 1); else if (strstr (currentline, "sp_trigger") == currentline) // trigger special - map.sp_trigger = atoi (strchr (currentline, '=') + 1); + map.sp_trigger = atoi (strchr (currentline, '=') + 1); else if (strstr (currentline, "sp_push") == currentline) // push special - map.sp_push = atoi (strchr (currentline, '=') + 1); + map.sp_push = atoi (strchr (currentline, '=') + 1); else if (strstr (currentline, "sp_row") == currentline) // row special - map.sp_row = atoi (strchr (currentline, '=') + 1); - else if (currentline[0] == '#') { /* the map itself */ + map.sp_row = atoi (strchr (currentline, '=') + 1); + else if (currentline[0] == '#') { /* the map itself */ for (i = 0; i < length; i++) { switch (currentline[i]) { case '#': @@ -372,6 +383,6 @@ map_load (FILE * fmap) map.field[i][0].type = map.field[i][map.size.y - 1].type = FT_block; for (i = 0; i < map.size.y; i++) map.field[0][i].type = map.field[map.size.x - 1][i].type = FT_block; - - fclose (fmap); + + fclose (fmap); } diff --git a/src/player.c b/src/player.c index 2695a59..667a605 100644 --- a/src/player.c +++ b/src/player.c @@ -15,7 +15,7 @@ draw_player (_player * player) if ((player->pos.x >> 8) < 0 || (player->pos.x >> 8) >= map.size.x || (player->pos.y >> 8) < 0 || (player->pos.y >> 8) >= map.size.y) { d_printf ("FATAL: Draw Player out of range : [%d,%d]\n", (player->pos.x >> 8), - (player->pos.y >> 8)); + (player->pos.y >> 8)); return; } @@ -89,10 +89,9 @@ restore_players_screen () if ((PS_IS_used (bman.players[i].state)) && bman.players[i].old.x != -1) { if ((bman.players[i].old.x >> 8) < 0 || (bman.players[i].old.x >> 8) >= map.size.x - || (bman.players[i].old.y >> 8) < 0 - || (bman.players[i].old.y >> 8) >= map.size.y) + || (bman.players[i].old.y >> 8) < 0 || (bman.players[i].old.y >> 8) >= map.size.y) d_printf ("FATAL: Restore Player out of range : playernr %d [%d,%d]\n", i, - (bman.players[i].old.x >> 8), (bman.players[i].old.y >> 8)); + (bman.players[i].old.x >> 8), (bman.players[i].old.y >> 8)); else { if ((bman.players[i].old.x & 0xFF) > 128) { x = (bman.players[i].old.x >> 8); @@ -216,10 +215,10 @@ int check_field (short int x, short int y) { int res = 0; - + if (map.field[x][y].type != FT_stone && map.field[x][y].type != FT_block) res = 1; - + return res; } @@ -229,13 +228,19 @@ check_field (short int x, short int y) int stepmove_player (int pl_nr) { - _point bomb1[MAX_PLAYERS * MAX_BOMBS], bomb2[MAX_PLAYERS * MAX_BOMBS]; + _point bomb1[MAX_PLAYERS * MAX_BOMBS], + bomb2[MAX_PLAYERS * MAX_BOMBS]; _player *p = &bman.players[pl_nr]; - int speed = 0, i, j, f; - _point fpos, // field position - _pos, // position inside the field - d; - + int speed = 0, + i, + j, + f; + _point fpos, // field position + + _pos, // position inside the field + + d; + if (p->m == 1) { fpos.x = p->pos.x >> 8; @@ -263,56 +268,81 @@ stepmove_player (int pl_nr) speed = _pos.y; else speed = 256 - _pos.y; - + if (speed > p->speed || speed == 0) speed = p->speed; // check the new field position - d.x = d.y = 0; - if (p->d == left && _pos.y == 0 && ((_pos.x == 0 && check_field (fpos.x - 1, fpos.y)) || (_pos.x > 0))) - d.x = -speed; - if (p->d == right && _pos.y == 0 && ((_pos.x == 0 && check_field (fpos.x + 1, fpos.y)) || (_pos.x > 0))) - d.x = speed; - if (p->d == up && _pos.x == 0 && ((_pos.y == 0 && check_field (fpos.x, fpos.y - 1)) || (_pos.y > 0))) - d.y = -speed; - if (p->d == down && _pos.x == 0 && ((_pos.y == 0 && check_field (fpos.x, fpos.y + 1)) || (_pos.y > 0))) - d.y = speed; - - // check if we can move and if there is any bomb - if (d.y != 0 || d.x != 0) { - get_bomb_on (p->pos.x, p->pos.y, bomb1); - get_bomb_on (p->pos.x + d.x, p->pos.y + d.y, bomb2); - - if (bomb1[0].x == -1 && bomb2[0].x != -1) - /* old pos no bomb, new pos no bomb */ - d.x = d.y = 0; - else if (bomb2[0].x != -1) { - /* new pos bomb, old pos bomb... check if it's the same - use f to save if we found the bomb or not - f == 0 no bomb found, f == 1 bomb found */ - for (i = 0, f = 1; (bomb2[i].x != -1 && f == 1); i++) - for (f = 0, j = 0; (bomb1[j].x != -1 && f == 0); j++) - if (bomb1[j].x == bomb2[i].x && bomb1[j].y == bomb2[i].y) - /* identical bomb found ... f = 1 */ - f = 1; - if (f == 0) - d.x = d.y = 0; - } - } - - p->pos.x += d.x; - p->pos.y += d.y; - - player_check_powerup (pl_nr); - } - - if (d.x == 0 && d.y == 0) - return 0; - + d.x = d.y = 0; + if (p->d == left && _pos.y == 0 + && ((_pos.x == 0 && check_field (fpos.x - 1, fpos.y)) || (_pos.x > 0))) + d.x = -speed; + if (p->d == right && _pos.y == 0 + && ((_pos.x == 0 && check_field (fpos.x + 1, fpos.y)) || (_pos.x > 0))) + d.x = speed; + if (p->d == up && _pos.x == 0 + && ((_pos.y == 0 && check_field (fpos.x, fpos.y - 1)) || (_pos.y > 0))) + d.y = -speed; + if (p->d == down && _pos.x == 0 + && ((_pos.y == 0 && check_field (fpos.x, fpos.y + 1)) || (_pos.y > 0))) + d.y = speed; + + // check if we can move and if there is any bomb + if (d.y != 0 || d.x != 0) { + get_bomb_on (p->pos.x, p->pos.y, bomb1); + get_bomb_on (p->pos.x + d.x, p->pos.y + d.y, bomb2); + + if (bomb1[0].x == -1 && bomb2[0].x != -1) + /* old pos no bomb, new pos no bomb */ + d.x = d.y = 0; + else if (bomb2[0].x != -1) { + /* new pos bomb, old pos bomb... check if it's the same + use f to save if we found the bomb or not + f == 0 no bomb found, f == 1 bomb found */ + for (i = 0, f = 1; (bomb2[i].x != -1 && f == 1); i++) + for (f = 0, j = 0; (bomb1[j].x != -1 && f == 0); j++) + if (bomb1[j].x == bomb2[i].x && bomb1[j].y == bomb2[i].y) + /* identical bomb found ... f = 1 */ + f = 1; + if (f == 0) + d.x = d.y = 0; + } + } + + p->pos.x += d.x; + p->pos.y += d.y; + + player_check_powerup (pl_nr); + } + + if (d.x == 0 && d.y == 0) + return 0; + return (p->speed - speed); }; +/* check if the givin position is oky + 1 = ok, 0 = bad */ +int +player_checkpos (int x, int y) +{ + int i, + d; + + for (i = 0, d = 0; d < 4; d++) + if (map.field[x][y].ex[d].count > 0) + i++; + + if (map.field[x][y].type == FT_block || i > 0) + return 0; + else + return 1; +}; + + +/* move the player if he have to move AND check if we are on a block + or over fire */ void move_player (int pl_nr) { @@ -344,6 +374,21 @@ move_player (int pl_nr) net_game_send_playermove (pl_nr, 1); p->old_m = p->m; // save the old state p->m = 0; + + /* check the players position */ + if ((p->pos.x & 0xFF) > EXPLOSION_SAVE_DISTANCE && (p->d == left || p->d == right)) + if (!check_field ((p->pos.x >> 8) + 1, (p->pos.y >> 8))) + player_died (p, -1); + if ((p->pos.y & 0xFF) > EXPLOSION_SAVE_DISTANCE && (p->d == up || p->d == down)) + if (!check_field ((p->pos.x >> 8), (p->pos.y >> 8) + 1)) + player_died (p, -1); + if (((p->pos.x & 0xFF) < (0x100 - EXPLOSION_SAVE_DISTANCE) + && (p->d == left || p->d == right)) + || ((p->pos.y & 0xFF) < (0x100 - EXPLOSION_SAVE_DISTANCE) + && (p->d == up || p->d == down))) + if (!check_field (p->pos.x >> 8, p->pos.y >> 8)) + player_died (p, -1); + }; @@ -358,8 +403,8 @@ player_drop_bomb (int pl_nr) _y; _point bombs[MAX_PLAYERS * MAX_BOMBS]; - i = player_findfreebomb (player); - + i = player_findfreebomb (player); + if (i >= 0 && i < MAX_BOMBS && PS_IS_alife (player->state)) { // free bomb found // get the best position for the bomb. bomb = &player->bombs[i]; @@ -672,7 +717,7 @@ player_set_ilness (_player * p, int t) type = s_random (PI_max); else type = t; - + d_printf ("Ilness : %d\n", type); switch (type) { case PI_slow: @@ -757,32 +802,37 @@ player_set_gfx (_player * p, signed char gfx_nr) /* find a free bomb */ -int player_findfreebomb (_player *player) { - int i, bombused = 0, res = -1, nr; - - /* check every free bomb from next entry of the last - exploded bomb to the last exploded bomb */ - if (player->bomb_lastex < 0 || player->bomb_lastex >= MAX_BOMBS) - player->bomb_lastex = 0; - - for (i = 0; i < MAX_BOMBS; i++) { - nr = player->bomb_lastex + 1 + i; - if (nr < 0 || nr >= MAX_BOMBS) // i out of range .. restart at bomb 0 - nr -= MAX_BOMBS; - - if (player->bombs[i].state == BS_off) { /* check if this bomb is free */ - if (res == -1) - res = i; - } - else - bombused++; // count number of used bombs - } - - if (res == -1 && i == player->bomb_lastex && player->bombs[i].state == BS_off) - res = i; - - if (bombused >= player->bombs_n) - res = -1; /* all max number of bombs lay */ - - return res; +int +player_findfreebomb (_player * player) +{ + int i, + bombused = 0, + res = -1, + nr; + + /* check every free bomb from next entry of the last + exploded bomb to the last exploded bomb */ + if (player->bomb_lastex < 0 || player->bomb_lastex >= MAX_BOMBS) + player->bomb_lastex = 0; + + for (i = 0; i < MAX_BOMBS; i++) { + nr = player->bomb_lastex + 1 + i; + if (nr < 0 || nr >= MAX_BOMBS) // i out of range .. restart at bomb 0 + nr -= MAX_BOMBS; + + if (player->bombs[i].state == BS_off) { /* check if this bomb is free */ + if (res == -1) + res = i; + } + else + bombused++; // count number of used bombs + } + + if (res == -1 && i == player->bomb_lastex && player->bombs[i].state == BS_off) + res = i; + + if (bombused >= player->bombs_n) + res = -1; /* all max number of bombs lay */ + + return res; };