Little Source Cleanup tileset.c and map.c created... some other things changed..

origin
stpohle 23 years ago
parent 5b50dbe0c2
commit 94202c9983

31
TODO

@ -1,25 +1,28 @@
$Id: TODO,v 1.9 2003/07/13 00:10:59 stpohle Exp $ $Id: TODO,v 1.10 2003/07/15 11:43:08 stpohle Exp $
this version (fix2): next version (0.9.10):
==================== ======================
always changes: - more specials (Kicking Bomb, Pushing Bomb Ver.2)
===============
- animated fire - maps will have more options to set and it will be displayed in the multiplayer menu
- more players
- we need some more sound for picking up items.
- find better way for menus
- network joining menu Add: i on a game for information about the playernames and
next version: the point list.
=============
- gfx, source cleanup. player will now drawn in order they stay - gfx, source cleanup. player will now drawn in order they stay
tileset will change we can support 64x64pixel size and 64x92pixel size tilesets tileset will change we can support 64x64pixel size and 64x92pixel size tilesets
no sdl_blit* calls from game_loop for the game gfx.. working on a new engine with no sdl_blit* calls from game_loop for the game gfx.. working on a new engine with
sorting the tiles and update rects. sorting the tiles and update rects.
- keyboard/keybinput cleanup so all keyboard inputs will be read from there. - 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. hopefully we will get so out of this menu problem that sometimes keys are ignored.
always change if possible:
==========================
- animated fire
- more players
- we need some more sound for picking up items.
- find better way for menus

@ -114,7 +114,9 @@ module.source.files=\
special.c\ special.c\
sound.h\ sound.h\
sound.c\ sound.c\
font.h font.h\
map.c\
tileset.c
module.pixmap.name=pixmaps module.pixmap.name=pixmaps
module.pixmap.type= module.pixmap.type=

@ -4,7 +4,7 @@ dnl If you don't want it to overwrite it,
dnl Please disable it in the Anjuta project configuration dnl Please disable it in the Anjuta project configuration
AC_INIT(configure.in) AC_INIT(configure.in)
AM_INIT_AUTOMAKE(bomberclone, 0.9.9.2) AM_INIT_AUTOMAKE(bomberclone, 0.9.10)
AM_CONFIG_HEADER AM_CONFIG_HEADER
AM_CONFIG_HEADER(config.h) AM_CONFIG_HEADER(config.h)

@ -19,7 +19,9 @@ bomberclone_SOURCES = \
network.c\ network.c\
udp.c\ udp.c\
menu.c\ menu.c\
map.c\
mapmenu.c\ mapmenu.c\
tileset.c\
field.c\ field.c\
network.h\ network.h\
sysfunc.c\ sysfunc.c\

@ -1,4 +1,4 @@
/* $Id: basic.h,v 1.36 2003/07/13 23:07:59 stpohle Exp $ */ /* $Id: basic.h,v 1.37 2003/07/15 11:43:09 stpohle Exp $ */
/* basic types which we need everywhere */ /* basic types which we need everywhere */
#ifndef _BC_BASIC_H_ #ifndef _BC_BASIC_H_
@ -10,7 +10,7 @@
#define GAME_SPECIAL_ITEMSHOE 10 #define GAME_SPECIAL_ITEMSHOE 10
#define GAME_SPECIAL_ITEMDEATH 25 #define GAME_SPECIAL_ITEMDEATH 25
#define GAME_SPECIAL_ITEMMIXED 10 #define GAME_SPECIAL_ITEMMIXED 10
#define GAME_SPECIAL_ITEMSTRIGGER 50 #define GAME_SPECIAL_ITEMSTRIGGER 3
#define GAME_SPECIAL_ITEMSROW 3 #define GAME_SPECIAL_ITEMSROW 3
#define GAME_SPECIAL_ITEMSPUSH 3 #define GAME_SPECIAL_ITEMSPUSH 3
#define GAME_SPECIAL_ITEMSKICK 0 // no use yet #define GAME_SPECIAL_ITEMSKICK 0 // no use yet

@ -1,4 +1,4 @@
/* $Id: bomberclone.h,v 1.42 2003/07/13 22:49:08 stpohle Exp $ */ /* $Id: bomberclone.h,v 1.43 2003/07/15 11:43:09 stpohle Exp $ */
/* bomberclone.h */ /* bomberclone.h */
#ifndef _BOMBERCLONE_H_ #ifndef _BOMBERCLONE_H_
@ -197,18 +197,15 @@ extern int debug;
extern void game_draw_info (); extern void game_draw_info ();
extern void game_loop (); extern void game_loop ();
extern void game_end (); extern void game_end ();
extern void game_set_playerposition(); extern void game_start();
// everything is declared in field.c // everything is declared in field.c
extern void draw_field (); extern void draw_field ();
extern void draw_stone (int x, int y);
extern void field_clear(int x, int y); extern void field_clear(int x, int y);
extern void field_update(int x,int y); extern void field_update(int x,int y);
extern void field_new (char *filename);
extern void field_set_playerposition (int usermap);
extern void tileset_random ();
extern void field_animation_add (int x, int y); extern void field_animation_add (int x, int y);
extern void field_animation (); extern void field_animation ();
extern void draw_stone (int x, int y);
// everything what is declared in players.c // everything what is declared in players.c
extern int dead_playerani (); extern int dead_playerani ();
@ -284,16 +281,24 @@ extern int ai_easyrunaway (_point p);
// mapmenu.c // mapmenu.c
extern void map_random ();
extern void tileset_random ();
extern void mapmenu (); extern void mapmenu ();
extern char* getfilename(char* path);
// map.c
extern void map_random ();
extern void map_genrandom ();
extern void init_map_tileset(); extern void init_map_tileset();
extern void map_new (char *filename);
extern void map_set_playerposition (int usermap);
extern void map_load (FILE * map);
// special.c // special.c
extern void special_use (int p_nr); extern void special_use (int p_nr);
extern void special_pickup (int p_nr, int s_type); extern void special_pickup (int p_nr, int s_type);
extern void special_loop (); extern void special_loop ();
extern void special_clear (int p_nr); extern void special_clear (int p_nr);
#endif
extern void tileset_load (char *tileset);
extern void tileset_random ();
extern void tileset_free ();
#endif

@ -1,4 +1,4 @@
/* $Id: field.c,v 1.33 2003/06/16 21:27:25 stpohle Exp $ */ /* $Id: field.c,v 1.34 2003/07/15 11:43:09 stpohle Exp $ */
/* field.c - procedures which are needed to control the field */ /* field.c - procedures which are needed to control the field */
#include <stdlib.h> #include <stdlib.h>
@ -118,199 +118,6 @@ draw_field ()
draw_stone (x, y); 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))) {
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].frame = bman.field[i][sizey].ex[d].count = 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;
/* darw the border so we know everything is right */
for (i = 0; i < bman.fieldsize.x; i++)
bman.field[i][0].type = bman.field[i][bman.fieldsize.y - 1].type = FT_block;
for (i = 0; i < bman.fieldsize.y; i++)
bman.field[0][i].type = bman.field[bman.fieldsize.x - 1][i].type = FT_block;
}
/* will set the playerposition but in a way that we won't start on a block */
/* i am just too lazy to write this all again and again */
#define PLX bman.players[i].pos.x
#define PLY bman.players[i].pos.y
void
field_set_playerposition (int usermap)
{
int p,
dist,
i,
j,
mx,
my,
dx = 0,
dy = 0;
char txt[255];
p = 50;
dist = 8;
while (p == 50) {
p = 0;
dist--;
for (i = 0; (p < 50 && i < MAX_PLAYERS);) {
if (usermap) {
int maxloop = 0;
while (maxloop < 200 && (PLX == -1 || PLY == -1)) {
maxloop++;
PLX = s_random (bman.fieldsize.x - 2) + 1;
PLY = s_random (bman.fieldsize.y - 2) + 1;
for (dx = 10, dy = 10, j = 0; (j < i && j < MAX_PLAYERS && (dx > 1 || dy > 1)); j++) { /* is ther any other player */
dx = PLX - bman.players[j].pos.x;
if (dx < 0)
dx = -dx;
dy = PLY - bman.players[j].pos.y;
if (dy < 0)
dy = -dy;
}
/* check if there is no block */
if ((dx > 1 || dy > 1)
&& ((bman.field[PLX][PLY].type != FT_block && maxloop > 100)
|| bman.field[PLX][PLY].type == FT_nothing)) {
/* get (up or down) dx and (left or right) dy */
dx = s_random (2);
if (dx == 0)
dx = -1;
dy = s_random (2);
if (dy == 0)
dy = -1;
/* first check if there is and free place for us */
if (!((bman.field[PLX + dx][PLY].type != FT_block && maxloop > 100) ||
bman.field[PLX + dx][PLY].type == FT_nothing))
dx = -dx;
if (!((bman.field[PLX + dx][PLY].type != FT_block && maxloop > 100) ||
bman.field[PLX + dx][PLY].type == FT_nothing))
PLX = -1;
if (!((bman.field[PLX][PLY + dy].type != FT_block && maxloop > 100) ||
bman.field[PLX][PLY + dy].type == FT_nothing))
dy = -dy;
if (!((bman.field[PLX][PLY + dy].type != FT_block && maxloop > 100) ||
bman.field[PLX][PLY + dy].type == FT_nothing))
PLY = -1;
}
else {
PLX = -1;
PLY = -1;
}
/* make some space */
if (PLX != -1 && PLY != -1) {
bman.field[PLX][PLY].type = FT_nothing;
bman.field[PLX + dx][PLY].type = FT_nothing;
bman.field[PLX][PLY + dy].type = FT_nothing;
}
}
}
if (PLX == -1 || PLY == -1) {
/* we could not set all fields or we don't run on a usermap */
if (usermap) {
sprintf (txt, "Not all players could be set (Pl:%d)", i);
menu_displaymessage ("MAP - ERROR", txt);
}
/* now there will be some fields deleted */
PLX = 2 * (s_random ((bman.fieldsize.x - 1) / 2)) + 1;
PLY = 2 * (s_random ((bman.fieldsize.y - 1) / 2)) + 1;
bman.field[PLX][PLY].type = FT_nothing;
dx = s_random (4); // bit 1 = up/down bit 2 = left/right
/* up and down */
if (((dx & 1) == 0 && PLX > 1) || PLX >= bman.fieldsize.x - 2)
bman.field[PLX - 1][PLY].type = FT_nothing;
else
bman.field[PLX + 1][PLY].type = FT_nothing;
/* left and right */
if (((dx & 2) == 0 && PLY > 1) || PLY >= bman.fieldsize.y - 2)
bman.field[PLX][PLY - 1].type = FT_nothing;
else
bman.field[PLX][PLY + 1].type = FT_nothing;
}
mx = my = 100;
for (j = 0; j <= i; j++) { /* search smalest distance */
dy = PLY - bman.players[j].pos.y;
dx = PLX - bman.players[j].pos.x;
if (dy < 0)
dy = -dy;
if (dx < 0)
dx = -dx;
if (mx > dx && i != j)
mx = dx;
if (my > dy && i != j)
my = dy;
}
if (mx > dist || my > dist)
i++;
else
p++;
}
}
for (i = 0; i < MAX_PLAYERS; i++) {
PLX = PLX << 8;
PLY = PLY << 8;
}
};
#undef PLX
#undef PLY
// clear field and send this to all netplayers // clear field and send this to all netplayers
void void
@ -329,121 +136,6 @@ field_update (int x, int y)
} }
// put items into the field
void
field_fillitems (int fieldtype, int num)
{
int nb_try = 100,
d,
x,
y;
/* this is the item factor we multiply it with this so we know
how much items we want in the game */
float fkt = ((float) (bman.fieldsize.x * bman.fieldsize.y)) / (25.0 * 17.0);
/* put the row special in the field */
for (d = 0; d < num * fkt; d++) {
x = y = 0;
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);
nb_try--;
if (nb_try < 0)
break;
}
bman.field[x][y].special = fieldtype;
}
}
void
field_new (char *filename)
{
int x,
y,
d;
FILE *fmap;
if (filename) {
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);
}
else {
fmap = NULL;
}
/* this is the item factor we multiply it with this so we know
how much items we want in the game */
// Clean and create the field //
if (fmap == NULL) {
/* if we can't load the map check first the fieldsize settings */
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;
for (x = 0; x < bman.fieldsize.x; x++)
for (y = 0; y < bman.fieldsize.y; y++) {
if ((y == 0) || (y == bman.fieldsize.y - 1))
bman.field[x][y].type = FT_block;
else if ((x == 0) || (x == bman.fieldsize.x - 1))
bman.field[x][y].type = FT_block;
else if (((x & 1) == 0) && ((y & 1) == 0))
bman.field[x][y].type = FT_block;
else {
// create random field
if ((s_random (256) & 3) == 0)
bman.field[x][y].type = FT_nothing;
else
bman.field[x][y].type = FT_stone;
}
for (d = 0; d < 4; d++)
bman.field[x][y].ex[d].frame = bman.field[x][y].ex[d].count = 0;
bman.field[x][y].ex_nr = -1;
bman.field[x][y].frame = 0;
bman.field[x][y].frameto = 0;
bman.field[x][y].special = FT_nothing;
}
}
/* delete the bfield data */
for (x = 0; x < MAX_FIELDSIZE_X; x++)
for (y = 0; y < MAX_FIELDSIZE_Y; y++)
bman.bfield[x][y] = 0;
/* Set the Playerinformation */
field_set_playerposition (fmap != NULL);
/* put the fire powerups in the field */
field_fillitems (FT_fire, GAME_SPECIAL_ITEMFIRE);
/* put the bomb powerups in the field */
field_fillitems (FT_bomb, GAME_SPECIAL_ITEMBOMB);
/* put the shoe powerup in the field */
field_fillitems (FT_shoe, GAME_SPECIAL_ITEMSHOE);
/* put the death ?powerups? in the field */
field_fillitems (FT_death, GAME_SPECIAL_ITEMDEATH);
/* put the mixed powerrup in the field */
field_fillitems (FT_mixed, GAME_SPECIAL_ITEMMIXED);
/* put the trigger special in the field */
field_fillitems (FT_sp_trigger, GAME_SPECIAL_ITEMSTRIGGER);
/* put the row special in the field */
field_fillitems (FT_sp_row, GAME_SPECIAL_ITEMSROW);
/* put the push special in the field */
field_fillitems (FT_sp_push, GAME_SPECIAL_ITEMSPUSH);
/* put the kick special in the field */
field_fillitems (FT_sp_kick, GAME_SPECIAL_ITEMSKICK);
}
/* run this to every game cycle for the animations on the field */ /* run this to every game cycle for the animations on the field */
void void

@ -253,12 +253,17 @@ game_loop ()
}; };
/* check which player won */ /* check which player won and unload all data */
void void
game_end () game_end ()
{ {
int i; int i;
menu_displaytext ("Freeing..", "Please Wait", 32, 128, 32);
gfx_free_players ();
tileset_free ();
snd_free ();
/* count the points */ /* count the points */
for (i = 0; i < MAX_PLAYERS; i++) for (i = 0; i < MAX_PLAYERS; i++)
if (PS_IS_used (bman.players[i].state)) { if (PS_IS_used (bman.players[i].state)) {
@ -274,3 +279,14 @@ game_end ()
if ((bman.players[i].state & PSF_used) == 0) if ((bman.players[i].state & PSF_used) == 0)
bman.players[i].state = 0; bman.players[i].state = 0;
} }
/* load the images with the right scaleing */
void
game_start ()
{
menu_displaytext ("Loading..", "Please Wait", 32, 128, 32);
tileset_load (gfx.tileset);
gfx_load_players (gfx.block.x, gfx.block.y);
snd_load (gfx.tileset);
};

@ -1,4 +1,4 @@
/* $Id: gfx.c,v 1.22 2003/06/20 22:59:21 stpohle Exp $ */ /* $Id: gfx.c,v 1.23 2003/07/15 11:43:09 stpohle Exp $ */
/* gfx.c */ /* gfx.c */
#include <SDL.h> #include <SDL.h>
@ -484,25 +484,6 @@ gfx_free_players ()
} }
/* load the images with the right scaleing */
void
gfx_game_init ()
{
menu_displaytext ("Loading..", "Please Wait", 32, 128, 32);
gfx_load_tileset (gfx.tileset);
gfx_load_players (gfx.block.x, gfx.block.y);
snd_load (gfx.tileset);
};
void
gfx_game_shutdown ()
{
menu_displaytext ("Freeing..", "Please Wait", 32, 128, 32);
gfx_free_players ();
gfx_free_tileset ();
};
/* init the whole GFX Part */ /* init the whole GFX Part */
void void
gfx_init () gfx_init ()
@ -797,214 +778,3 @@ gfx_copyscreen (SDL_Rect * wnd)
SDL_BlitSurface (gfx.screen, wnd, res, &dest); SDL_BlitSurface (gfx.screen, wnd, res, &dest);
return res; return res;
}; };
/* load the tileset or if not present the files from the default folder */
void
gfx_load_tileset (char *tilesetname)
{
int i,
r,
g,
b;
char fullname[LEN_PATHFILENAME];
char filename[LEN_FILENAME];
char tileset[LEN_TILESETNAME];
SDL_Surface *tmpimage,
*tmpimage1;
float sfkt;
d_printf ("Loading Tileset: %s\n", tilesetname);
strncpy (tileset, tilesetname, LEN_TILESETNAME);
/* Calculate the Best Size of the Images */
gfx.block.x = gfx.res.x / (bman.fieldsize.x + 1);
gfx.block.y = (gfx.res.y - 80) / (bman.fieldsize.y + 1);
if (gfx.block.x < gfx.block.y)
gfx.block.y = gfx.block.x;
else
gfx.block.x = gfx.block.y;
/* create Table of points */
scale (gfx.postab, gfx.block.x, 256);
sfkt = ((float) gfx.block.x) / ((float) GFX_IMGSIZE);
/* calculating the best offset for the field on the screen */
gfx.offset.x = (gfx.res.x - (gfx.block.x * bman.fieldsize.x)) / 2;
gfx.offset.y = gfx.res.y - (gfx.block.y * bman.fieldsize.y);
/* load the fire */
sprintf (fullname, "%s/tileset/%s/fire.bmp", bman.datapath, tileset);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
/* file could not be load, so load teh default tileset */
sprintf (fullname, "%s/tileset/default/fire.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
printf ("default tileset could not be loaded.\n");
exit (1);
}
}
gfx.fire.frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 =
scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.fire.frames * gfx.block.y);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.fire.image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1);
/* load the bomb */
sprintf (fullname, "%s/tileset/%s/bomb.bmp", bman.datapath, tileset);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
/* file could not be load, so load teh default tileset */
sprintf (fullname, "%s/tileset/default/bomb.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
printf ("default tileset could not be loaded.\n");
exit (1);
}
}
gfx.bomb.frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 =
scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.bomb.frames * gfx.block.y);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.bomb.image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1);
/* load the powerup's image */
for (i = 0; i < PWUP_max; i++) {
switch (i) {
case (PWUP_good):
sprintf (filename, "powerup.bmp");
break;
case (PWUP_bad):
sprintf (filename, "powerbad.bmp");
break;
default:
sprintf (filename, "powersp.bmp");
break;
}
sprintf (fullname, "%s/tileset/%s/%s", bman.datapath, tileset, filename);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
/* file could not be load, so load teh default tileset */
sprintf (fullname, "%s/tileset/default/%s", bman.datapath, filename);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
printf ("default tileset could not be loaded.\n");
exit (1);
}
}
gfx.powerup[i].frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 =
scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.powerup[i].frames * gfx.block.y);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, 255, 0, 255));
gfx.powerup[i].image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1);
}
/* loading the field images */
for (i = 0; i < FT_max; i++) {
switch (i) {
case (FT_nothing):
sprintf (filename, "background.bmp");
break;
case (FT_stone):
sprintf (filename, "stone.bmp");
break;
case (FT_block):
sprintf (filename, "block.bmp");
break;
case (FT_death):
sprintf (filename, "pwdeath.bmp");
break;
case (FT_bomb):
sprintf (filename, "pwbomb.bmp");
break;
case (FT_fire):
sprintf (filename, "pwfire.bmp");
break;
case (FT_shoe):
sprintf (filename, "pwshoe.bmp");
break;
case (FT_sp_trigger):
sprintf (filename, "sptrigger.bmp");
break;
case (FT_sp_row):
sprintf (filename, "sprow.bmp");
break;
case (FT_sp_push):
sprintf (filename, "sppush.bmp");
break;
case (FT_sp_kick):
sprintf (filename, "spkick.bmp");
continue; // remove this if you find a kick image
break;
}
if (i != FT_mixed) {
sprintf (fullname, "%s/tileset/%s/%s", bman.datapath, tileset, filename);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
sprintf (fullname, "%s/tileset/default/%s", bman.datapath, filename);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
}
gfx.field[i].frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 = scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.field[i].frames * gfx.block.y);
if (i == FT_nothing || i == FT_block || i == FT_stone)
r = g = b = 255;
else
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.field[i].image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage1);
if (i >= FT_sp_trigger && i < FT_max) {
// create the smal special thing
tmpimage1 = scale_image (tmpimage, 32, 32);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.smal_special[i - FT_sp_trigger] = SDL_DisplayFormat (tmpimage1);
};
SDL_FreeSurface (tmpimage);
}
}
UpdateRects_nr = 0;
};
void
gfx_free_tileset ()
{
int i;
for (i = 0; i < FT_max; i++) {
if (gfx.field[i].image != NULL)
SDL_FreeSurface (gfx.field[i].image);
gfx.field[i].image = NULL;
if (i >= FT_sp_trigger && i < FT_max) {
if (gfx.smal_special[i - FT_sp_trigger] != NULL)
SDL_FreeSurface (gfx.smal_special[i - FT_sp_trigger]);
gfx.smal_special[i - FT_sp_trigger] = NULL;
}
}
if (gfx.bomb.image != NULL)
SDL_FreeSurface (gfx.bomb.image);
if (gfx.fire.image != NULL)
SDL_FreeSurface (gfx.fire.image);
for (i = 0; i < PWUP_max; i++)
if (gfx.powerup[i].image != NULL)
SDL_FreeSurface (gfx.powerup[i].image);
gfx.bomb.image = NULL;
gfx.fire.image = NULL;
};

@ -1,4 +1,4 @@
/* $Id: gfx.h,v 1.11 2003/06/07 14:25:46 stpohle Exp $ */ /* $Id: gfx.h,v 1.12 2003/07/15 11:43:09 stpohle Exp $ */
#ifndef _GFX_H_ #ifndef _GFX_H_
#define _GFX_H_ #define _GFX_H_
@ -64,9 +64,7 @@ extern void gfx_AddUpdateRect (int x, int y, int w, int h);
extern void redraw_logo (int x, int y, int w, int h); extern void redraw_logo (int x, int y, int w, int h);
extern void draw_logo (); extern void draw_logo ();
extern void gfx_init (); // Load Base Image Data extern void gfx_init (); // Load Base Image Data
extern void gfx_game_init (); // Load Game Data extern void gfx_shutdown ();
extern void gfx_game_shutdown (); // Free Image Data
extern void gfx_shutdown (); //
extern void getRGBpixel (SDL_Surface *surface, int x, int y, int *R, int *G, int *B); extern void getRGBpixel (SDL_Surface *surface, int x, int y, int *R, int *G, int *B);
extern Uint32 getpixel(SDL_Surface *surface, int x, int y); extern Uint32 getpixel(SDL_Surface *surface, int x, int y);
extern void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); extern void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
@ -79,8 +77,6 @@ extern void gfx_unlocksurface (SDL_Surface *surface);
extern void redraw_logo_shaded (int x, int y, int w, int h, int c); extern void redraw_logo_shaded (int x, int y, int w, int h, int c);
extern void gfx_load_players (int sx, int sy); extern void gfx_load_players (int sx, int sy);
extern void gfx_free_players (); extern void gfx_free_players ();
extern void gfx_load_tileset (char *tileset);
extern void gfx_free_tileset ();
extern SDL_Surface *makegray_image (SDL_Surface *org); extern SDL_Surface *makegray_image (SDL_Surface *org);
extern SDL_Surface *gfx_copyscreen (SDL_Rect *wnd); extern SDL_Surface *gfx_copyscreen (SDL_Rect *wnd);

@ -0,0 +1,357 @@
/* $Id: map.c,v 1.1 2003/07/15 11:43:09 stpohle Exp $ */
/* map handling, like generate and load maps. */
#include "bomberclone.h"
// put items into the field
void
map_fillitems (int fieldtype, int num)
{
int nb_try = 100,
d,
x,
y;
/* this is the item factor we multiply it with this so we know
how much items we want in the game */
float fkt = ((float) (bman.fieldsize.x * bman.fieldsize.y)) / (25.0 * 17.0);
/* put the row special in the field */
for (d = 0; d < num * fkt; d++) {
x = y = 0;
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);
nb_try--;
if (nb_try < 0)
break;
}
bman.field[x][y].special = fieldtype;
}
}
// loads or generate an map
void
map_new (char *filename)
{
int x,
y;
FILE *fmap;
if (filename) {
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)
map_load (fmap);
}
else
fmap = NULL;
// Clean and create the field //
if (fmap == NULL)
map_genrandom ();
/* delete the bfield data */
for (x = 0; x < MAX_FIELDSIZE_X; x++)
for (y = 0; y < MAX_FIELDSIZE_Y; y++)
bman.bfield[x][y] = 0;
/* Set the Playerinformation */
map_set_playerposition (fmap != NULL);
/* put the fire powerups in the field */
map_fillitems (FT_fire, GAME_SPECIAL_ITEMFIRE);
/* put the bomb powerups in the field */
map_fillitems (FT_bomb, GAME_SPECIAL_ITEMBOMB);
/* put the shoe powerup in the field */
map_fillitems (FT_shoe, GAME_SPECIAL_ITEMSHOE);
/* put the death ?powerups? in the field */
map_fillitems (FT_death, GAME_SPECIAL_ITEMDEATH);
/* put the mixed powerrup in the field */
map_fillitems (FT_mixed, GAME_SPECIAL_ITEMMIXED);
/* put the trigger special in the field */
map_fillitems (FT_sp_trigger, GAME_SPECIAL_ITEMSTRIGGER);
/* put the row special in the field */
map_fillitems (FT_sp_row, GAME_SPECIAL_ITEMSROW);
/* put the push special in the field */
map_fillitems (FT_sp_push, GAME_SPECIAL_ITEMSPUSH);
/* put the kick special in the field */
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 (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;
for (x = 0; x < bman.fieldsize.x; x++)
for (y = 0; y < bman.fieldsize.y; y++) {
if ((y == 0) || (y == bman.fieldsize.y - 1))
bman.field[x][y].type = FT_block;
else if ((x == 0) || (x == bman.fieldsize.x - 1))
bman.field[x][y].type = FT_block;
else if (((x & 1) == 0) && ((y & 1) == 0))
bman.field[x][y].type = FT_block;
else {
// create random field
if ((s_random (256) & 3) == 0)
bman.field[x][y].type = FT_nothing;
else
bman.field[x][y].type = FT_stone;
}
for (d = 0; d < 4; d++)
bman.field[x][y].ex[d].frame = bman.field[x][y].ex[d].count = 0;
bman.field[x][y].ex_nr = -1;
bman.field[x][y].frame = 0;
bman.field[x][y].frameto = 0;
bman.field[x][y].special = FT_nothing;
}
}
/* will set the playerposition but in a way that we won't start on a block */
/* i am just too lazy to write this all again and again */
#define PLX bman.players[i].pos.x
#define PLY bman.players[i].pos.y
void
map_set_playerposition (int usermap)
{
int p,
dist,
i,
j,
mx,
my,
dx = 0,
dy = 0;
char txt[255];
p = 50;
dist = 8;
while (p == 50) {
p = 0;
dist--;
for (i = 0; (p < 50 && i < MAX_PLAYERS);) {
if (usermap) {
int maxloop = 0;
while (maxloop < 200 && (PLX == -1 || PLY == -1)) {
maxloop++;
PLX = s_random (bman.fieldsize.x - 2) + 1;
PLY = s_random (bman.fieldsize.y - 2) + 1;
for (dx = 10, dy = 10, j = 0; (j < i && j < MAX_PLAYERS && (dx > 1 || dy > 1)); j++) { /* is ther any other player */
dx = PLX - bman.players[j].pos.x;
if (dx < 0)
dx = -dx;
dy = PLY - bman.players[j].pos.y;
if (dy < 0)
dy = -dy;
}
/* check if there is no block */
if ((dx > 1 || dy > 1)
&& ((bman.field[PLX][PLY].type != FT_block && maxloop > 100)
|| bman.field[PLX][PLY].type == FT_nothing)) {
/* get (up or down) dx and (left or right) dy */
dx = s_random (2);
if (dx == 0)
dx = -1;
dy = s_random (2);
if (dy == 0)
dy = -1;
/* first check if there is and free place for us */
if (!((bman.field[PLX + dx][PLY].type != FT_block && maxloop > 100) ||
bman.field[PLX + dx][PLY].type == FT_nothing))
dx = -dx;
if (!((bman.field[PLX + dx][PLY].type != FT_block && maxloop > 100) ||
bman.field[PLX + dx][PLY].type == FT_nothing))
PLX = -1;
if (!((bman.field[PLX][PLY + dy].type != FT_block && maxloop > 100) ||
bman.field[PLX][PLY + dy].type == FT_nothing))
dy = -dy;
if (!((bman.field[PLX][PLY + dy].type != FT_block && maxloop > 100) ||
bman.field[PLX][PLY + dy].type == FT_nothing))
PLY = -1;
}
else {
PLX = -1;
PLY = -1;
}
/* make some space */
if (PLX != -1 && PLY != -1) {
bman.field[PLX][PLY].type = FT_nothing;
bman.field[PLX + dx][PLY].type = FT_nothing;
bman.field[PLX][PLY + dy].type = FT_nothing;
}
}
}
if (PLX == -1 || PLY == -1) {
/* we could not set all fields or we don't run on a usermap */
if (usermap) {
sprintf (txt, "Not all players could be set (Pl:%d)", i);
menu_displaymessage ("MAP - ERROR", txt);
}
/* now there will be some fields deleted */
PLX = 2 * (s_random ((bman.fieldsize.x - 1) / 2)) + 1;
PLY = 2 * (s_random ((bman.fieldsize.y - 1) / 2)) + 1;
bman.field[PLX][PLY].type = FT_nothing;
dx = s_random (4); // bit 1 = up/down bit 2 = left/right
/* up and down */
if (((dx & 1) == 0 && PLX > 1) || PLX >= bman.fieldsize.x - 2)
bman.field[PLX - 1][PLY].type = FT_nothing;
else
bman.field[PLX + 1][PLY].type = FT_nothing;
/* left and right */
if (((dx & 2) == 0 && PLY > 1) || PLY >= bman.fieldsize.y - 2)
bman.field[PLX][PLY - 1].type = FT_nothing;
else
bman.field[PLX][PLY + 1].type = FT_nothing;
}
mx = my = 100;
for (j = 0; j <= i; j++) { /* search smalest distance */
dy = PLY - bman.players[j].pos.y;
dx = PLX - bman.players[j].pos.x;
if (dy < 0)
dy = -dy;
if (dx < 0)
dx = -dx;
if (mx > dx && i != j)
mx = dx;
if (my > dy && i != j)
my = dy;
}
if (mx > dist || my > dist)
i++;
else
p++;
}
}
for (i = 0; i < MAX_PLAYERS; i++) {
PLX = PLX << 8;
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 (bman.fieldpath, "%s/maps/%s", bman.datapath, desel->name);
}
// Init the game according to options
void init_map_tileset()
{
switch (bman.random_map) {
case (0):
map_new (bman.fieldpath);
break;
case (1):
map_random ();
map_new (bman.fieldpath);
break;
case (2):
map_new (NULL);
break;
}
if (gfx.random_tileset)
tileset_random ();
}
/* 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
map_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))) {
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].frame = bman.field[i][sizey].ex[d].count = 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;
/* darw the border so we know everything is right */
for (i = 0; i < bman.fieldsize.x; i++)
bman.field[i][0].type = bman.field[i][bman.fieldsize.y - 1].type = FT_block;
for (i = 0; i < bman.fieldsize.y; i++)
bman.field[0][i].type = bman.field[bman.fieldsize.x - 1][i].type = FT_block;
}

@ -4,60 +4,6 @@
#include "bomberclone.h" #include "bomberclone.h"
#include "gfx.h" #include "gfx.h"
/* 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 (bman.fieldpath, "%s/maps/%s", bman.datapath, desel->name);
}
/* load a random tileset */
void tileset_random () {
_direntry *destart, *de, *desel;
char path[LEN_PATHFILENAME];
int max, sel;
sprintf (path, "%s/tileset", bman.datapath);
desel = destart = s_getdir (path);
for (max = 0, de = destart; de != NULL; de = de->next)
if (de->name[0] != '.' && (de->flags & DF_dir) == DF_dir)
max++;
sel = s_random (max);
for (max = 0, de = destart; max <= sel && de != NULL; de = de->next)
if (de->name[0] != '.' && (de->flags & DF_dir) == DF_dir) {
desel = de;
max++;
}
d_printf ("Random Tileset %s (%d on %d)\n", desel->name, sel, max);
if (desel != NULL)
strncpy (gfx.tileset, desel->name, LEN_TILESETNAME);
gfx.tileset[LEN_TILESETNAME-1] = 0;
}
/* launch the map options menu */ /* launch the map options menu */
void mapmenu () void mapmenu ()
@ -212,34 +158,3 @@ void mapmenu ()
} }
} }
} }
// Return only the file name
char* getfilename(char* path)
{
int i;
for(i=strlen(path);i>=0;i--)
if(path[i] == '\\' || path[i] == '/')
return path+i+1;
return path;
}
// Init the game according to options
void init_map_tileset()
{
switch (bman.random_map) {
case (0):
field_new (bman.fieldpath);
break;
case (1):
map_random ();
field_new (bman.fieldpath);
break;
case (2):
field_new (NULL);
break;
}
if (gfx.random_tileset)
tileset_random ();
}

@ -219,7 +219,7 @@ host_multiplayer_game ()
net_new_game (); net_new_game ();
init_map_tileset(); init_map_tileset();
net_send_servermode (); net_send_servermode ();
gfx_game_init (); game_start ();
net_new_gamedata (); net_new_gamedata ();
if (bman.state == GS_ready || bman.state == GS_running) { if (bman.state == GS_ready || bman.state == GS_running) {
@ -236,7 +236,6 @@ host_multiplayer_game ()
net_send_servermode (); net_send_servermode ();
net_send_players (); net_send_players ();
} }
gfx_game_shutdown ();
} }
} }
@ -257,15 +256,13 @@ join_multiplayer_game ()
wait_for_players (); wait_for_players ();
if (bman.p_nr != -1 && (GS_WAITRUNNING || bman.state == GS_update)) { if (bman.p_nr != -1 && (GS_WAITRUNNING || bman.state == GS_update)) {
gfx_game_init (); game_start ();
bman.state = GS_update; bman.state = GS_update;
net_new_game (); net_new_game ();
net_new_gamedata (); net_new_gamedata ();
if (bman.state == GS_ready || bman.state == GS_running) if (bman.state == GS_ready || bman.state == GS_running)
game_loop (); game_loop ();
gfx_game_shutdown ();
} }
else else
bman.state = GS_startup; bman.state = GS_startup;

@ -1,4 +1,4 @@
/* $Id: single.c,v 1.33 2003/07/08 21:16:04 stpohle Exp $ */ /* $Id: single.c,v 1.34 2003/07/15 11:43:09 stpohle Exp $ */
/* single player */ /* single player */
#include "basic.h" #include "basic.h"
@ -631,9 +631,9 @@ single_playergame ()
single_create_ai (bman.ai_players); single_create_ai (bman.ai_players);
single_game_new (); single_game_new ();
gfx_game_init (); game_start ();
game_loop (); game_loop ();
gfx_game_shutdown (); game_end ();
}; };

@ -1,4 +1,4 @@
/* $Id: sysfunc.c,v 1.16 2003/05/29 17:43:38 stpohle Exp $ /* $Id: sysfunc.c,v 1.17 2003/07/15 11:43:09 stpohle Exp $
sysfunc.c - this file hold some routines for the system functions.. sysfunc.c - this file hold some routines for the system functions..
like d_delay like d_delay
*/ */
@ -183,3 +183,13 @@ int s_countbits (int bits, int nr) {
return r; return r;
} }
// Return only the file name
char* getfilename(char* path)
{
int i;
for(i=strlen(path);i>=0;i--)
if(path[i] == '\\' || path[i] == '/')
return path+i+1;
return path;
}

@ -1,4 +1,4 @@
/* $Id: sysfunc.h,v 1.6 2003/05/29 17:43:38 stpohle Exp $ */ /* $Id: sysfunc.h,v 1.7 2003/07/15 11:43:09 stpohle Exp $ */
/* include some system near functions */ /* include some system near functions */
#ifndef _SYSFUNC_H_ #ifndef _SYSFUNC_H_
@ -21,6 +21,7 @@ extern void s_delay (int ms);
extern int s_random (int maxnr); extern int s_random (int maxnr);
extern char *s_gethomedir (); extern char *s_gethomedir ();
extern int s_countbits (int nbomb, int nr); extern int s_countbits (int nbomb, int nr);
extern char* getfilename(char* path);
extern _direntry *s_getdir (char *path); extern _direntry *s_getdir (char *path);
extern _direntry *s_dirfilter (_direntry *dirstart, signed char dirflags); extern _direntry *s_dirfilter (_direntry *dirstart, signed char dirflags);

@ -0,0 +1,245 @@
/* $Id: tileset.c,v 1.1 2003/07/15 11:43:09 stpohle Exp $ */
/* load and select tilesets */
#include "bomberclone.h"
extern int UpdateRects_nr;
/* load a random tileset */
void tileset_random () {
_direntry *destart, *de, *desel;
char path[LEN_PATHFILENAME];
int max, sel;
sprintf (path, "%s/tileset", bman.datapath);
desel = destart = s_getdir (path);
for (max = 0, de = destart; de != NULL; de = de->next)
if (de->name[0] != '.' && (de->flags & DF_dir) == DF_dir)
max++;
sel = s_random (max);
for (max = 0, de = destart; max <= sel && de != NULL; de = de->next)
if (de->name[0] != '.' && (de->flags & DF_dir) == DF_dir) {
desel = de;
max++;
}
d_printf ("Random Tileset %s (%d on %d)\n", desel->name, sel, max);
if (desel != NULL)
strncpy (gfx.tileset, desel->name, LEN_TILESETNAME);
gfx.tileset[LEN_TILESETNAME-1] = 0;
}
/* load the tileset or if not present the files from the default folder */
void
tileset_load (char *tilesetname)
{
int i,
r,
g,
b;
char fullname[LEN_PATHFILENAME];
char filename[LEN_FILENAME];
char tileset[LEN_TILESETNAME];
SDL_Surface *tmpimage,
*tmpimage1;
float sfkt;
d_printf ("Loading Tileset: %s\n", tilesetname);
strncpy (tileset, tilesetname, LEN_TILESETNAME);
/* Calculate the Best Size of the Images */
gfx.block.x = gfx.res.x / (bman.fieldsize.x + 1);
gfx.block.y = (gfx.res.y - 80) / (bman.fieldsize.y + 1);
if (gfx.block.x < gfx.block.y)
gfx.block.y = gfx.block.x;
else
gfx.block.x = gfx.block.y;
/* create Table of points */
scale (gfx.postab, gfx.block.x, 256);
sfkt = ((float) gfx.block.x) / ((float) GFX_IMGSIZE);
/* calculating the best offset for the field on the screen */
gfx.offset.x = (gfx.res.x - (gfx.block.x * bman.fieldsize.x)) / 2;
gfx.offset.y = gfx.res.y - (gfx.block.y * bman.fieldsize.y);
/* load the fire */
sprintf (fullname, "%s/tileset/%s/fire.bmp", bman.datapath, tileset);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
/* file could not be load, so load teh default tileset */
sprintf (fullname, "%s/tileset/default/fire.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
printf ("default tileset could not be loaded.\n");
exit (1);
}
}
gfx.fire.frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 =
scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.fire.frames * gfx.block.y);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.fire.image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1);
/* load the bomb */
sprintf (fullname, "%s/tileset/%s/bomb.bmp", bman.datapath, tileset);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
/* file could not be load, so load teh default tileset */
sprintf (fullname, "%s/tileset/default/bomb.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
printf ("default tileset could not be loaded.\n");
exit (1);
}
}
gfx.bomb.frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 =
scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.bomb.frames * gfx.block.y);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.bomb.image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1);
/* load the powerup's image */
for (i = 0; i < PWUP_max; i++) {
switch (i) {
case (PWUP_good):
sprintf (filename, "powerup.bmp");
break;
case (PWUP_bad):
sprintf (filename, "powerbad.bmp");
break;
default:
sprintf (filename, "powersp.bmp");
break;
}
sprintf (fullname, "%s/tileset/%s/%s", bman.datapath, tileset, filename);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
/* file could not be load, so load teh default tileset */
sprintf (fullname, "%s/tileset/default/%s", bman.datapath, filename);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
printf ("default tileset could not be loaded.\n");
exit (1);
}
}
gfx.powerup[i].frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 =
scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.powerup[i].frames * gfx.block.y);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, 255, 0, 255));
gfx.powerup[i].image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1);
}
/* loading the field images */
for (i = 0; i < FT_max; i++) {
switch (i) {
case (FT_nothing):
sprintf (filename, "background.bmp");
break;
case (FT_stone):
sprintf (filename, "stone.bmp");
break;
case (FT_block):
sprintf (filename, "block.bmp");
break;
case (FT_death):
sprintf (filename, "pwdeath.bmp");
break;
case (FT_bomb):
sprintf (filename, "pwbomb.bmp");
break;
case (FT_fire):
sprintf (filename, "pwfire.bmp");
break;
case (FT_shoe):
sprintf (filename, "pwshoe.bmp");
break;
case (FT_sp_trigger):
sprintf (filename, "sptrigger.bmp");
break;
case (FT_sp_row):
sprintf (filename, "sprow.bmp");
break;
case (FT_sp_push):
sprintf (filename, "sppush.bmp");
break;
case (FT_sp_kick):
sprintf (filename, "spkick.bmp");
continue; // remove this if you find a kick image
break;
}
if (i != FT_mixed) {
sprintf (fullname, "%s/tileset/%s/%s", bman.datapath, tileset, filename);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
sprintf (fullname, "%s/tileset/default/%s", bman.datapath, filename);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
}
gfx.field[i].frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 = scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.field[i].frames * gfx.block.y);
if (i == FT_nothing || i == FT_block || i == FT_stone)
r = g = b = 255;
else
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.field[i].image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage1);
if (i >= FT_sp_trigger && i < FT_max) {
// create the smal special thing
tmpimage1 = scale_image (tmpimage, 32, 32);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.smal_special[i - FT_sp_trigger] = SDL_DisplayFormat (tmpimage1);
};
SDL_FreeSurface (tmpimage);
}
}
UpdateRects_nr = 0;
};
void
tileset_free () {
int i;
for (i = 0; i < FT_max; i++) {
if (gfx.field[i].image != NULL)
SDL_FreeSurface (gfx.field[i].image);
gfx.field[i].image = NULL;
if (i >= FT_sp_trigger && i < FT_max) {
if (gfx.smal_special[i - FT_sp_trigger] != NULL)
SDL_FreeSurface (gfx.smal_special[i - FT_sp_trigger]);
gfx.smal_special[i - FT_sp_trigger] = NULL;
}
}
if (gfx.bomb.image != NULL)
SDL_FreeSurface (gfx.bomb.image);
if (gfx.fire.image != NULL)
SDL_FreeSurface (gfx.fire.image);
for (i = 0; i < PWUP_max; i++)
if (gfx.powerup[i].image != NULL)
SDL_FreeSurface (gfx.powerup[i].image);
gfx.bomb.image = NULL;
gfx.fire.image = NULL;
};
Loading…
Cancel
Save