just a little cleanup

origin
stpohle 23 years ago
parent 271d996160
commit 9178c7114a

@ -1,4 +1,4 @@
/* $Id: field.c,v 1.6 2003/05/04 21:44:14 ob1kenewb Exp $ */
/* $Id: field.c,v 1.7 2003/05/05 00:22:21 stpohle Exp $ */
/* field.c - procedures which are needed to control the field */
#include <stdlib.h>
@ -85,38 +85,33 @@ draw_field ()
an espace is nothing ' '
% are commentary at the beginning of the map */
void field_load(FILE *map)
void
field_load (FILE * map)
{
size_t length;
char *currentline;
char tmp[MAX_FIELDSIZE_X];
int sizex=0;
int sizey=0;
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]=='%')
while ((currentline = fgets (tmp, MAX_FIELDSIZE_X, map))) {
length = strlen (currentline);
if (currentline[0] == '%')
continue;
/* now each line correspond to the field */
else
{
for(i=0;i<length;i++)
{
switch(currentline[i])
{
else {
for (i = 0; i < length; i++) {
switch (currentline[i]) {
case '#':
bman.field[i][sizey].type=FT_block;
bman.field[i][sizey].type = FT_block;
break;
case '@':
bman.field[i][sizey].type=FT_stone;
bman.field[i][sizey].type = FT_stone;
break;
case ' ':
bman.field[i][sizey].type=FT_nothing;
bman.field[i][sizey].type = FT_nothing;
default:
break;
}
@ -128,13 +123,13 @@ void field_load(FILE *map)
bman.field[i][sizey].special = FT_nothing;
}
sizey++;
if(sizex<length)
sizex=length;
if (sizex < length)
sizex = length;
}
}
bman.fieldsize.x=sizex-1;
bman.fieldsize.y=sizey;
bman.fieldsize.x = sizex - 1;
bman.fieldsize.y = sizey;
}
@ -147,21 +142,19 @@ field_new (char *filename)
FILE *fmap;
float fkt;
int nb_try;
fmap=fopen(filename,"r");
fmap = fopen (filename, "r");
/* if we can't open the given filename for any reason, reverting
to default value else, load the file*/
to default value else, load the file */
if(fmap)
field_load(fmap);
if (fmap)
field_load (fmap);
// 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);
fkt = ((float) (bman.fieldsize.x * bman.fieldsize.y)) / (bman.fieldsize.x * bman.fieldsize.y);
// Clean the field //
if(fmap==NULL)
{
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))
@ -195,65 +188,65 @@ field_new (char *filename)
bman.field[x][y].type = FT_nothing;
if (x > 1)
bman.field[x-1][y].type = FT_nothing;
if (x < bman.fieldsize.x-2)
bman.field[x+1][y].type = FT_nothing;
bman.field[x - 1][y].type = FT_nothing;
if (x < bman.fieldsize.x - 2)
bman.field[x + 1][y].type = FT_nothing;
if (y > 1)
bman.field[x][y-1].type = FT_nothing;
if (y < bman.fieldsize.y -2)
bman.field[x][y+1].type = FT_nothing;
bman.field[x][y - 1].type = FT_nothing;
if (y < bman.fieldsize.y - 2)
bman.field[x][y + 1].type = FT_nothing;
}
nb_try=100;
nb_try = 100; // to prevent infinite loops (maybe there are no stones)
/* 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) {
x = ((float) rand() / (float) RAND_MAX) * (bman.fieldsize.x-1);
y = ((float) rand() / (float) RAND_MAX) * (bman.fieldsize.y-1);
x = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.x - 1);
y = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.y - 1);
nb_try--;
if(nb_try<0)
if (nb_try < 0)
break;
}
bman.field[x][y].special = FT_fire;
x = y = 0;
}
nb_try=100;
nb_try = 100;
/* put the bomb powerups in the field */
for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMBOMB * fkt; d++) {
while (bman.field[x][y].type != FT_stone || bman.field[x][y].special != FT_nothing) {
x = ((float) rand() / (float) RAND_MAX) * (bman.fieldsize.x-1);
y = ((float) rand() / (float) RAND_MAX) * (bman.fieldsize.y-1);
x = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.x - 1);
y = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.y - 1);
nb_try--;
if(nb_try<0)
if (nb_try < 0)
break;
}
bman.field[x][y].special = FT_bomb;
x = y = 0;
}
nb_try=100;
nb_try = 100;
/* put the shoe powerup in the field */
for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMSHOE * fkt; d++) {
while (bman.field[x][y].type != FT_stone || bman.field[x][y].special != FT_nothing) {
x = ((float) rand() / (float) RAND_MAX) * (bman.fieldsize.x-1);
y = ((float) rand() / (float) RAND_MAX) * (bman.fieldsize.y-1);
x = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.x - 1);
y = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.y - 1);
nb_try--;
if(nb_try<0)
if (nb_try < 0)
break;
}
bman.field[x][y].special = FT_shoe;
x = y = 0;
}
nb_try=100;
nb_try = 100;
/* put the death ?powerups? in the field */
for (d = 0, x = 0, y = 0; d < GAME_SPECIAL_ITEMDEATH * fkt; d++) {
while (bman.field[x][y].type != FT_stone || bman.field[x][y].special != FT_nothing) {
x = ((float) rand() / (float) RAND_MAX) * (bman.fieldsize.x-1);
y = ((float) rand() / (float) RAND_MAX) * (bman.fieldsize.y-1);
x = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.x - 1);
y = ((float) rand () / (float) RAND_MAX) * (bman.fieldsize.y - 1);
nb_try--;
if(nb_try<0)
if (nb_try < 0)
break;
}
bman.field[x][y].special = FT_death;

Loading…
Cancel
Save