You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
bomberclone/src/gfx.c

967 lines
26 KiB

/* gfx.c */
#include <SDL.h>
#include "bomberclone.h"
#include "gfx.h"
#include "sound.h"
int UpdateRects_nr = 0;
SDL_Rect UpdateRects[MAX_UPDATERECTS];
_gfx gfx;
void
getRGBpixel (SDL_Surface * surface, int x, int y, int *R, int *G, int *B)
{
Uint32 pixel = 0;
Uint8 r,
g,
b;
/* Lock the screen for direct access to the pixels */
if (SDL_MUSTLOCK (surface))
if (SDL_LockSurface (surface) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
return;
}
pixel = getpixel (surface, x, y);
if (SDL_MUSTLOCK (surface)) {
SDL_UnlockSurface (surface);
}
SDL_GetRGB (pixel, surface->format, &r, &g, &b);
*R = r;
*G = g;
*B = b;
};
Uint32
getpixel (SDL_Surface * surface, int x, int y)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to retrieve */
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
switch (bpp) {
case 1:
return *p;
case 2:
return *(Uint16 *) p;
case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
case 4:
return *(Uint32 *) p;
default:
return 0; /* shouldn't happen, but avoids warnings */
}
};
void
putpixel (SDL_Surface * surface, int x, int y, Uint32 pixel)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to set */
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
switch (bpp) {
case 1:
*p = pixel;
break;
case 2:
*(Uint16 *) p = pixel;
break;
case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
}
else {
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *) p = pixel;
break;
}
};
void
scale (short int *dpattern, short int x, short int y)
{
int a,
dx,
dy;
if (x >= SCALE_MAXRES || y >= SCALE_MAXRES) {
for (x = 0; x < SCALE_MAXRES; x++)
dpattern[x] = 0;
return;
}
if (x > y) {
dy = 2 * y;
dx = a = 2 * x - dy;
do {
if (a <= 0) {
dpattern[(y--) - 1] = x;
a = a + dx;
}
else
a = a - dy;
} while (x--);
}
else {
dy = 2 * x;
dx = a = 2 * y - dy;
do {
dpattern[y] = x;
if (a <= 0) {
x--;
a = a + dx;
}
else
a = a - dy;
} while (y--);
}
};
SDL_Surface *
scale_image (SDL_Surface * orginal, int newx, int newy)
{
Uint32 rmask,
gmask,
bmask,
amask;
SDL_Surface *surface;
int y,
x;
short int xpattern[SCALE_MAXRES];
short int ypattern[SCALE_MAXRES];
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else /* */
rmask = 0x00ff0000;
gmask = 0x0000ff00;
bmask = 0x000000ff;
amask = 0xff000000;
#endif /* */
surface = SDL_CreateRGBSurface (SDL_SWSURFACE, newx, newy, 32, rmask, gmask, bmask, amask);
if (surface == NULL) {
fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ());
return NULL;
}
/* Lock the screen for direct access to the pixels */
if (SDL_MUSTLOCK (surface))
if (SDL_LockSurface (surface) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
return NULL;
}
if (SDL_MUSTLOCK (orginal))
if (SDL_LockSurface (orginal) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
if (SDL_MUSTLOCK (surface)) {
SDL_UnlockSurface (surface);
}
return NULL;
}
/* do the scaling work */
scale (xpattern, orginal->w - 1, newx);
scale (ypattern, orginal->h - 1, newy);
for (x = newx - 1; x >= 0; x--)
for (y = newy - 1; y >= 0; y--)
putpixel (surface, x, y, getpixel (orginal, xpattern[x], ypattern[y]));
if (SDL_MUSTLOCK (orginal)) {
SDL_UnlockSurface (orginal);
}
if (SDL_MUSTLOCK (surface)) {
SDL_UnlockSurface (surface);
}
return surface;
};
SDL_Surface *
makegray_image (SDL_Surface * org)
{
Uint32 rmask,
gmask,
bmask,
amask;
Uint32 pixel,
transpixel = 0;
SDL_Surface *dest;
int y,
x;
Uint8 r,
g,
b,
gray;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000;
gmask = 0x00ff0000;
bmask = 0x0000ff00;
amask = 0x000000ff;
#else
rmask = 0x00ff0000;
gmask = 0x0000ff00;
bmask = 0x000000ff;
amask = 0xff000000;
#endif
dest = SDL_CreateRGBSurface (SDL_SWSURFACE, org->w, org->h, 32, rmask, gmask, bmask, amask);
if (dest == NULL) {
fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ());
return NULL;
}
/* Lock the screen for direct access to the pixels */
if (SDL_MUSTLOCK (dest))
if (SDL_LockSurface (dest) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
return NULL;
}
if (SDL_MUSTLOCK (org))
if (SDL_LockSurface (org) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
if (SDL_MUSTLOCK (dest)) {
SDL_UnlockSurface (dest);
}
return NULL;
}
for (x = 0; x < org->w; x++)
for (y = 0; y < org->h; y++) {
pixel = getpixel (org, x, y);
if (x == 0 && y == 0)
transpixel = pixel;
if (pixel != transpixel) {
SDL_GetRGB (pixel, org->format, &r, &g, &b);
gray = (r / 3 + g / 3 + b / 3);
pixel = SDL_MapRGB (dest->format, gray, gray, gray);
}
putpixel (dest, x, y, pixel);
}
if (SDL_MUSTLOCK (org)) {
SDL_UnlockSurface (org);
}
if (SDL_MUSTLOCK (dest)) {
SDL_UnlockSurface (dest);
}
SDL_SetColorKey (dest, SDL_SRCCOLORKEY, transpixel);
return dest;
};
SDL_Surface *
gfx_quater_image (SDL_Surface * org1, SDL_Surface * org2, SDL_Surface * org3, SDL_Surface * org4)
{
Uint32 pixel;
SDL_Surface *dest;
int y,
x;
dest = SDL_CreateRGBSurface (SDL_HWSURFACE, org1->w, org1->h, org1->format->BitsPerPixel,
org1->format->Rmask, org1->format->Gmask,
org1->format->Bmask, org1->format->Amask);
if (dest == NULL) {
fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ());
return NULL;
}
/* Lock the screen for direct access to the pixels */
if (SDL_MUSTLOCK (dest))
if (SDL_LockSurface (dest) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
return NULL;
}
if (SDL_MUSTLOCK (org1))
if (SDL_LockSurface (org1) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
if (SDL_MUSTLOCK (dest)) {
SDL_UnlockSurface (dest);
}
return NULL;
}
if (SDL_MUSTLOCK (org2))
if (SDL_LockSurface (org2) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
if (SDL_MUSTLOCK (dest)) {
SDL_UnlockSurface (dest);
}
return NULL;
}
if (SDL_MUSTLOCK (org3))
if (SDL_LockSurface (org3) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
if (SDL_MUSTLOCK (dest)) {
SDL_UnlockSurface (dest);
}
return NULL;
}
if (SDL_MUSTLOCK (org4))
if (SDL_LockSurface (org4) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
if (SDL_MUSTLOCK (dest)) {
SDL_UnlockSurface (dest);
}
return NULL;
}
for (x = 0; x < org1->w / 2; x++)
for (y = 0; y < org1->h / 2; y++) {
pixel = getpixel (org1, x, y);
putpixel (dest, x, y, pixel);
}
for (x = org1->w / 2; x < org1->w; x++)
for (y = 0; y < org1->h / 2; y++) {
pixel = getpixel (org2, x, y);
putpixel (dest, x, y, pixel);
}
for (x = 0; x < org1->w / 2; x++)
for (y = org1->h / 2; y < org1->h; y++) {
pixel = getpixel (org3, x, y);
putpixel (dest, x, y, pixel);
}
for (x = org1->w / 2; x < org1->w; x++)
for (y = org1->h / 2; y < org1->h; y++) {
pixel = getpixel (org4, x, y);
putpixel (dest, x, y, pixel);
}
if (SDL_MUSTLOCK (org1))
SDL_UnlockSurface (org1);
if (SDL_MUSTLOCK (org2))
SDL_UnlockSurface (org2);
if (SDL_MUSTLOCK (org3))
SDL_UnlockSurface (org3);
if (SDL_MUSTLOCK (org4))
SDL_UnlockSurface (org4);
if (SDL_MUSTLOCK (dest)) {
SDL_UnlockSurface (dest);
}
return dest;
};
#define __smalsizeX 12
void
gfx_load_players (int sx, int sy)
{
float sfkt,
ssfkt;
char filename[255];
int i,
j,
r,
g,
b;
SDL_Surface *tmpimage,
*tmpimage1;
sfkt = ((float) sx) / ((float) GFX_IMGSIZE);
ssfkt = ((float) __smalsizeX) / ((float) GFX_IMGSIZE);
/* loading the player images */
for (j = i = 0; i < MAX_PLAYERS; i++) {
sprintf (filename, "%s/player/player%d.bmp", bman.datapath, j);
j++;
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
if (j == 0) { // try again with the first image, if this don't work give up.
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
i--; // load the this image again
j = 0;
}
else {
/* load the game player image */
gfx.players[i].size.y = sy * 2;
gfx.players[i].size.x = (tmpimage->w / 4) * sfkt;
gfx.players[i].ani.frames = tmpimage->h / GFX_PLAYERIMGSIZE_Y;
tmpimage1 =
scale_image (tmpimage, gfx.players[i].size.x * 4,
gfx.players[i].ani.frames * gfx.players[i].size.y);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.players[i].ani.image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage1);
/* calculate the numbers of images for the animation */
gfx.players[i].offset.x = (sx - gfx.players[i].size.x) / 2;
gfx.players[i].offset.y = -sy;
/* load the smal image */
gfx.players[i].smal_size.y = __smalsizeX * 2;
gfx.players[i].smal_size.x = (tmpimage->w / 4) * ssfkt;
tmpimage1 =
scale_image (tmpimage, gfx.players[i].smal_size.x * 4,
gfx.players[i].ani.frames * gfx.players[i].smal_size.y);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.players[i].smal_image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage1);
SDL_FreeSurface (tmpimage);
}
}
/* load the illnessthing */
sprintf (filename, "%s/player/playersick.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
gfx.ill.frames = tmpimage->h / (2 * GFX_IMGSIZE);
tmpimage1 =
scale_image (tmpimage, (tmpimage->w / (2 * GFX_IMGSIZE)) * (2 * sx),
gfx.ill.frames * (2 * sy));
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.ill.image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1);
};
/* frees the player images */
void
gfx_free_players ()
{
int i;
for (i = 0; i < MAX_PLAYERS; i++) {
if (gfx.players[i].ani.image != NULL)
SDL_FreeSurface (gfx.players[i].ani.image);
gfx.players[i].ani.image = NULL;
if (gfx.players[i].smal_image != NULL)
SDL_FreeSurface (gfx.players[i].smal_image);
gfx.players[i].smal_image = NULL;
}
SDL_FreeSurface (gfx.ill.image);
}
/* 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 */
void
gfx_init ()
{
if (gfx.fullscreen)
gfx.screen =
SDL_SetVideoMode (gfx.res.x, gfx.res.y, gfx.bpp,
SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL | SDL_FULLSCREEN);
else
gfx.screen =
SDL_SetVideoMode (gfx.res.x, gfx.res.y, gfx.bpp,
SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL);
if (gfx.screen == NULL) {
d_printf ("Unable to set video mode: %s\n", SDL_GetError ());
return;
}
SDL_ShowCursor (SDL_DISABLE);
gfx_loaddata ();
};
void
gfx_loaddata ()
{
int r,
g,
b;
char filename[255];
SDL_Surface *tmpimage,
*tmpimage1;
/* load the font */
sprintf (filename, "%s/gfx/font.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
sprintf (bman.datapath, "data");
sprintf (filename, "%s/gfx/font.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
}
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 0, 0, 0));
gfx.font.image = SDL_DisplayFormat (tmpimage);
gfx.font.size.x = 16;
gfx.font.size.y = 16;
SDL_FreeSurface (tmpimage);
/* load the font */
sprintf (filename, "%s/gfx/font1.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 0, 0, 0));
gfx.font1.image = SDL_DisplayFormat (tmpimage);
gfx.font1.size.x = 16;
gfx.font1.size.y = 16;
SDL_FreeSurface (tmpimage);
/* load the logo */
sprintf (filename, "%s/gfx/logo.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
tmpimage1 = scale_image (tmpimage, gfx.res.x, gfx.res.y);
SDL_FreeSurface (tmpimage);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, 255, 255, 0));
gfx.logo = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage1);
/* load the menuselector */
sprintf (filename, "%s/gfx/menuselect.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ());
exit (1);
}
gfx.menuselect.frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 = scale_image (tmpimage, gfx.font.size.x, gfx.menuselect.frames * gfx.font.size.y);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.menuselect.image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1);
};
void
gfx_shutdown ()
{
int i;
for (i = 0; i < FT_max; i++)
SDL_FreeSurface (gfx.field[i].image);
for (i = 0; i < MAX_PLAYERS; i++)
SDL_FreeSurface (gfx.players[i].ani.image);
SDL_FreeSurface (gfx.font.image);
SDL_FreeSurface (gfx.font1.image);
SDL_FreeSurface (gfx.logo);
SDL_FreeSurface (gfx.bomb.image);
SDL_FreeSurface (gfx.fire.image);
SDL_FreeSurface (gfx.menuselect.image);
gfx.screen = SDL_SetVideoMode (gfx.res.x, gfx.res.y, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_FreeSurface (gfx.screen);
};
void
gfx_AddUpdateRect (int x, int y, int w, int h)
{
if (UpdateRects_nr >= MAX_UPDATERECTS)
return;
UpdateRects[UpdateRects_nr].x = x;
UpdateRects[UpdateRects_nr].y = y;
UpdateRects[UpdateRects_nr].w = w;
UpdateRects[UpdateRects_nr].h = h;
UpdateRects_nr++;
};
void
gfx_UpdateRects ()
{
if (UpdateRects_nr > 0)
SDL_UpdateRects (gfx.screen, UpdateRects_nr, UpdateRects);
UpdateRects_nr = 0;
};
void
draw_logo ()
{
SDL_BlitSurface (gfx.logo, NULL, gfx.screen, NULL);
UpdateRects_nr = 0;
gfx_AddUpdateRect (0, 0, gfx.screen->w, gfx.screen->h);
};
void
redraw_logo_shaded (int x, int y, int w, int h, int c)
{
SDL_Rect dest;
dest.w = w;
dest.h = h;
dest.x = x;
dest.y = y;
redraw_logo (x, y, w + 1, h + 1);
if (gfx_locksurface (gfx.screen))
return;
dest.h += dest.y;
dest.w += dest.x;
draw_shadefield (gfx.screen, &dest, c);
gfx_unlocksurface (gfx.screen);
};
void
redraw_logo (int x, int y, int w, int h)
{
SDL_Rect src,
dest;
dest.w = src.w = w;
dest.h = src.h = h;
dest.x = x;
dest.y = y;
src.x = x;
src.y = y;
SDL_BlitSurface (gfx.logo, &src, gfx.screen, &dest);
};
void
shade_pixel (SDL_Surface * s, int x, int y, int c)
{
Uint32 p;
Uint8 r,
g,
b;
p = getpixel (s, x, y);
SDL_GetRGB (p, s->format, &r, &g, &b);
if (c > 0) {
if (((Sint16) r) + c < 256) {
r += c;
}
else
r = 255;
if (((Sint16) g) + c < 256) {
g += c;
}
else
g = 255;
if (((Sint16) b) + c < 256) {
b += c;
}
else
b = 255;
}
else {
if (((Sint16) r) + c > 0) {
r += c;
}
else
r = 0;
if (((Sint16) g) + c > 0) {
g += c;
}
else
g = 0;
if (((Sint16) b) + c > 0) {
b += c;
}
else
b = 0;
}
p = SDL_MapRGB (s->format, r, g, b);
putpixel (s, x, y, p);
};
int
gfx_locksurface (SDL_Surface * surface)
{
if (SDL_MUSTLOCK (surface))
if (SDL_LockSurface (surface) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
return -1;
}
return 0;
};
void
gfx_unlocksurface (SDL_Surface * surface)
{
if (SDL_MUSTLOCK (surface)) {
SDL_UnlockSurface (surface);
}
};
void
draw_shadefield (SDL_Surface * s, SDL_Rect * rec, int c)
{
int x1,
x,
x2,
y1,
y;
if (rec->x > rec->w) {
x1 = rec->w;
x2 = rec->x;
}
else {
x2 = rec->w;
x1 = rec->x;
}
if (rec->y > rec->h) {
y = rec->h;
y1 = rec->y;
}
else {
y1 = rec->h;
y = rec->y;
}
for (; y <= y1; y++)
for (x = x1; x <= x2; x++)
shade_pixel (s, x, y, c);
};
SDL_Surface *
gfx_copyscreen (SDL_Rect * wnd)
{
SDL_Surface *res;
SDL_Rect dest;
res =
SDL_CreateRGBSurface (SDL_HWSURFACE, wnd->w, wnd->h, gfx.screen->format->BitsPerPixel,
gfx.screen->format->Rmask, gfx.screen->format->Gmask,
gfx.screen->format->Bmask, gfx.screen->format->Amask);
dest.x = 0;
dest.y = 0;
dest.w = wnd->w;
dest.h = wnd->h;
SDL_BlitSurface (gfx.screen, wnd, res, &dest);
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 image */
sprintf (fullname, "%s/tileset/%s/powerup.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/powerup.bmp", bman.datapath);
tmpimage = SDL_LoadBMP (fullname);
if (tmpimage == NULL) {
printf ("default tileset could not be loaded.\n");
exit (1);
}
}
gfx.powerup.frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 =
scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.bomb.frames * gfx.block.y);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, 255, 0, 255));
gfx.powerup.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) {
tmpimage =
gfx_quater_image (gfx.field[FT_bomb].image, gfx.field[FT_fire].image,
gfx.field[FT_death].image, gfx.field[FT_shoe].image);
gfx.field[i].image = SDL_DisplayFormat (tmpimage);
}
else {
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 (tmpimage);
SDL_FreeSurface (tmpimage1);
}
}
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 (gfx.bomb.image != NULL)
SDL_FreeSurface (gfx.bomb.image);
if (gfx.fire.image != NULL)
SDL_FreeSurface (gfx.fire.image);
if (gfx.powerup.image != NULL)
SDL_FreeSurface (gfx.powerup.image);
gfx.bomb.image = NULL;
gfx.fire.image = NULL;
};