Added File map loading functionnality, only one

map per game is supported. You specify it in the menu
origin
ob1kenewb 23 years ago
parent ae69cf1709
commit 19af4f0e00

@ -1,3 +1,4 @@
/* $Id: bomberclone.h,v 1.7 2003/05/04 19:23:00 ob1kenewb Exp $ */
/* bomberclone.h */
#ifndef _BOMBERCLONE_H_
@ -107,6 +108,7 @@ struct __bomberclone {
int p_nr; // Playernumber 0 if you host a game or the number of the one you are.
_field field[MAX_FIELDSIZE_X][MAX_FIELDSIZE_Y];
char fieldpath[512]; // path of the field file
int last_ex_nr; // number of the last explosion
@ -151,7 +153,7 @@ extern void game_set_playerposition();
// everything is declared in field.c
extern void draw_field ();
extern void draw_stone (int x, int y);
extern void field_new ();
extern void field_new (char *filename);
// everything what is declared in players.c
extern void dead_playerani ();

@ -46,6 +46,7 @@ game_init ()
bman.fieldsize.x = 25;
bman.fieldsize.y = 17;
sprintf (bman.datapath, "data/bomberclone.gfx");
bman.fieldpath[0] = 0;
};
int
@ -130,6 +131,15 @@ ReadConfig ()
if (!strcmp (keyword, "resolutiony")) {
gfx.res.y = atoi (value);
}
if (!strcmp (keyword, "fieldpath")) {
if (strlen (value) > 510) {
d_printf
("*** Error - fieldpath too long (maximum size permitted is %d characters)!\n\n",
510);
}
value[511] = 0;
strcpy(bman.fieldpath,value);
}
if (!strcmp (keyword, "fieldsizex")) {
bman.fieldsize.x = atoi (value);
}
@ -184,6 +194,7 @@ WriteConfig ()
fprintf (config, "resolutionx=%d\n", gfx.res.x);
fprintf (config, "resolutiony=%d\n", gfx.res.y);
fprintf (config, "fullscreen=%d\n", gfx.fullscreen);
fprintf (config, "fieldpath=%s\n", bman.fieldpath);
fprintf (config, "fieldsizex=%d\n", bman.fieldsize.x);
fprintf (config, "fieldsizey=%d\n", bman.fieldsize.y);
fprintf (config, "notify=%d\n", bman.notifygamemaster);
@ -197,7 +208,7 @@ WriteConfig ()
fprintf (config, "askplayername=%d\n", bman.askplayername);
fprintf (config, "playername=%s\n", bman.playername);
fprintf (config, "bitsperpixel=%d\n", gfx.bpp);
fclose (config);
return 0;
}
@ -291,31 +302,35 @@ configuration ()
{1, "Video Options"},
{2, "Sound Options"},
{3, "Customize Keyboard"},
{4, "Field Size X:"},
{5, "Field Size Y:"},
{6, "Prompt For Player Name"},
{7, "Debug"},
{8, "Save Config"},
{9, "Return To Main Manu"},
{4, "Field File:"},
{5, "Field Size X:"},
{6, "Field Size Y:"},
{7, "Prompt For Player Name"},
{8, "Debug"},
{9, "Save Config"},
{10, "Return To Main Manu"},
{-1, ""}
};
while (menuselect != -1) {
sprintf (menu[0].text, "Player Name: %s", bman.playername);
sprintf (menu[4].text, "Field Size X: %d", bman.fieldsize.x);
sprintf (menu[5].text, "Field Size Y: %d", bman.fieldsize.y);
if(bman.fieldpath[0])
sprintf (menu[4].text, "Field File: %s", bman.fieldpath);
else
sprintf (menu[4].text, "Field File: <not used>");
sprintf (menu[5].text, "Field Size X: %d", bman.fieldsize.x);
sprintf (menu[6].text, "Field Size Y: %d", bman.fieldsize.y);
if (debug == 1)
sprintf (menu[6].text, "Debug Messages ON");
sprintf (menu[8].text, "Debug Messages ON");
else
sprintf (menu[6].text, "Debug Messages OFF");
sprintf (menu[8].text, "Debug Messages OFF");
if (bman.askplayername == 1)
sprintf (menu[6].text, "Prompt For Name: Yes");
sprintf (menu[7].text, "Prompt For Name: Yes");
else
sprintf (menu[6].text, "Prompt For Name: No");
sprintf (menu[7].text, "Prompt For Name: No");
menuselect = menu_loop ("Configuration", menu, menuselect);
@ -331,35 +346,39 @@ configuration ()
case (2): // Sound Options
case (3): // Customize Keyboard
break;
case (4): // Change X Fieldsize
sprintf (menu[4].text, "%d", bman.fieldsize.x);
case (4): // Field File
menu_get_text ("Enter the path of a field file", bman.fieldpath, 30);
bman.fieldpath[511] = 0;
break;
case (5): // Change X Fieldsize
sprintf (menu[5].text, "%d", bman.fieldsize.x);
sprintf (text, "Field Size X (%d - %d)", MIN_FIELDSIZE_X, MAX_FIELDSIZE_X);
menu_get_text (text, menu[4].text, 3);
bman.fieldsize.x = atoi (menu[4].text) | 1;
menu_get_text (text, menu[5].text, 3);
bman.fieldsize.x = atoi (menu[5].text) | 1;
if (bman.fieldsize.x < MIN_FIELDSIZE_X)
bman.fieldsize.x = MIN_FIELDSIZE_X;
if (bman.fieldsize.x > MAX_FIELDSIZE_X)
bman.fieldsize.x = MAX_FIELDSIZE_X;
break;
case (5): // Change Y Fieldsize
sprintf (menu[5].text, "%d", bman.fieldsize.y);
case (6): // Change Y Fieldsize
sprintf (menu[6].text, "%d", bman.fieldsize.y);
sprintf (text, "Field Size Y (%d - %d)", MIN_FIELDSIZE_Y, MAX_FIELDSIZE_Y);
menu_get_text (text, menu[5].text, 3);
bman.fieldsize.y = atoi (menu[5].text) | 1;
menu_get_text (text, menu[6].text, 3);
bman.fieldsize.y = atoi (menu[6].text) | 1;
if (bman.fieldsize.y < MIN_FIELDSIZE_Y)
bman.fieldsize.y = MIN_FIELDSIZE_Y;
if (bman.fieldsize.y > MAX_FIELDSIZE_Y)
bman.fieldsize.y = MAX_FIELDSIZE_Y;
break;
case (6): // Debugging On / Off
case (7): // Debugging On / Off
if (bman.askplayername == 1)
bman.askplayername = 0;
else
bman.askplayername = 1;
break;
case (7): // Debugging On / Off
case (8): // Debugging On / Off
if (debug == 1)
debug = 0;
else {
@ -367,10 +386,10 @@ configuration ()
d_printf ("BomberClone ver.%s\n", VERSION);
}
break;
case (8): // Save Configuration
case (9): // Save Configuration
WriteConfig ();
break;
case (9): // Return to main menu
case (10): // Return to main menu
menuselect = -1;
break;
}

@ -1,3 +1,4 @@
/* $Id: field.c,v 1.4 2003/05/04 19:23:00 ob1kenewb Exp $ */
/* field.c - procedures which are needed to control the field */
#include <stdlib.h>
@ -78,17 +79,89 @@ draw_field ()
draw_stone (x, y);
};
/* read from an open file map, determine field.x and field.y
and fill the field.
(# correspond to a bloc and @ correspond to a stone,
an espace is nothing ' '
% are commentary at the beginning of the map */
void field_load(FILE *map)
{
size_t length;
char *currentline;
char tmp[MAX_FIELDSIZE_X];
int sizex=0;
int sizey=0;
int i;
int d;
while((currentline=fgets(&tmp,MAX_FIELDSIZE_X,map)))
/* fgetln is only implemented on *BSD */
/* while((currentline=fgetln(map,&length))) */
{
length=strlen(currentline);
if(currentline[0]=='%')
continue;
/* now each line correspond to the field */
else
{
for(i=0;i<length;i++)
{
switch(currentline[i])
{
case '#':
bman.field[i][sizey].type=FT_block;
break;
case '@':
bman.field[i][sizey].type=FT_stone;
break;
case ' ':
bman.field[i][sizey].type=FT_nothing;
default:
break;
}
for (d = 0; d < 4; d++)
bman.field[i][sizey].ex[d] = 0;
bman.field[i][sizey].ex_nr = -1;
bman.field[i][sizey].frame = 0;
bman.field[i][sizey].frameto = 0;
bman.field[i][sizey].special = FT_nothing;
}
sizey++;
if(sizex<length)
sizex=length;
}
}
bman.fieldsize.x=sizex-1;
bman.fieldsize.y=sizey;
}
void
field_new ()
field_new (char *filename)
{
int x,
y,
d;
FILE *fmap;
float fkt;
fmap=fopen(filename,"r");
/* if we can't open the given filename for any reason, reverting
to default value else, load the file*/
if(fmap)
field_load(fmap);
float fkt = ((float)(bman.fieldsize.x * bman.fieldsize.y))/(25.0 * 17.0);
// fkt = ((float)(bman.fieldsize.x * bman.fieldsize.y))/(25.0 * 17.0);
fkt = ((float)(bman.fieldsize.x * bman.fieldsize.y))/(bman.fieldsize.x * bman.fieldsize.y);
// Clean the field //
if(fmap==NULL)
{
for (x = 0; x < bman.fieldsize.x; x++)
for (y = 0; y < bman.fieldsize.y; y++) {
if ((y == 0) || (y == bman.fieldsize.y - 1))
@ -112,6 +185,7 @@ field_new ()
bman.field[x][y].frameto = 0;
bman.field[x][y].special = FT_nothing;
}
}
/* get some free space for the playerstart position */
for (d = 0; d < MAX_PLAYERS; d++)
@ -129,7 +203,7 @@ field_new ()
if (y < bman.fieldsize.y -2)
bman.field[x][y+1].type = FT_nothing;
}
/* put the fire powerups in the field */
for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMFIRE * fkt; d++) {
while (bman.field[x][y].type != FT_stone || bman.field[x][y].special != FT_nothing) {

@ -1,3 +1,4 @@
/* $Id: menu.c,v 1.4 2003/05/04 19:23:00 ob1kenewb Exp $ */
/* menu's for the game */
#include <SDL.h>
@ -179,7 +180,9 @@ menu_get_text (char *title, char *text, int len)
SDL_Event event;
Uint8 *keys;
text[len]=0;
curpos = strlen (text);
if(curpos>=len) curpos=len-1;
strcpy (t, text);
if (len > strlen (title)) {
len_ = len;

@ -1,3 +1,4 @@
/* $Id: network.c,v 1.10 2003/05/04 19:23:00 ob1kenewb Exp $ */
/*
network routines.
*/
@ -776,7 +777,7 @@ net_host_new_game ()
}
}
field_new ();
field_new (bman.fieldpath);
bman.players[bman.p_nr].state &= (0xFF - PSF_net); // we are the local player
bman.last_ex_nr = 1;

@ -1,3 +1,4 @@
/* $Id: single.c,v 1.3 2003/05/04 19:23:00 ob1kenewb Exp $ */
/* single player */
#include "basic.h"
@ -36,8 +37,7 @@ single_game_new (int ai_players)
player_set_gfx (&bman.players[bman.p_nr], 0);
bman.last_ex_nr = 1;
field_new ();
field_new (bman.fieldpath);
bman.players_nr_s = 1;
bman.players_nr = 1;
bman.gametype = GT_single;

Loading…
Cancel
Save