Background fileds can now have backgrounds with bigger size

origin
stpohle 23 years ago
parent b8df4ac745
commit c1f8ebcf54

@ -1,5 +1,12 @@
- Changed: You can now change the map settings even in the Player
selection menu. (kitutou)
- Added: tileset support with random tileset selection
thanks to (thaphool) for the jungle tileset
- Added: loadable maps. (ob1kenewb) - Added: loadable maps. (ob1kenewb)
with random map selection (kitutou)
- Changed: now the send packet option will be set for every - Changed: now the send packet option will be set for every
player directly, so if a slow player joinsit should not anymore player directly, so if a slow player joinsit should not anymore

@ -3,7 +3,6 @@ This file will hold some Details about the Game.
A list of files and what every file is used for: A list of files and what every file is used for:
field.c: field.c:
selecting a tileset
loading maps loading maps
generating maps generating maps
drawing the field drawing the field
@ -130,4 +129,23 @@ udp.c:
dns names dns names
start/stop udp server start/stop udp server
mapmenu.c:
map option menu
map initializing
- selects random maps
- loads random tilesets
keypinput.c:
loop for keyboard text fields
sysfunc.c:
s_delay
- waiting for some milliseconds
s_random
- returns a random number
s_gethomedir
- returns the name of the homedir used for the config file
s_getdir
- list of files and directorys
s_filterdir
- filters the list

@ -1,4 +1,4 @@
/* $Id: bomberclone.h,v 1.16 2003/05/07 21:28:12 stpohle Exp $ */ /* $Id: bomberclone.h,v 1.17 2003/05/08 14:35:48 stpohle Exp $ */
/* bomberclone.h */ /* bomberclone.h */
#ifndef _BOMBERCLONE_H_ #ifndef _BOMBERCLONE_H_

@ -1,4 +1,4 @@
/* $Id: field.c,v 1.14 2003/05/07 21:28:12 stpohle Exp $ */ /* $Id: field.c,v 1.15 2003/05/08 14:35:49 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>
@ -49,9 +49,18 @@ draw_stone (int x, int y)
} }
if (stone->frame > 0) if (stone->frame > 0 || stone->type == FT_nothing) {
SDL_BlitSurface (gfx.field[FT_nothing].image, NULL, gfx.screen, &dest); SDL_Rect srcbg;
srcbg.w = dest.w;
srcbg.h = dest.h;
srcbg.x = (x % gfx.field[FT_nothing].frames) * gfx.block.x;
srcbg.y = (y % gfx.field[FT_nothing].frames) * gfx.block.y;
SDL_BlitSurface (gfx.field[FT_nothing].image, &srcbg, gfx.screen, &dest);
}
if (stone->type != FT_nothing)
SDL_BlitSurface (srcimg, &src, gfx.screen, &dest); SDL_BlitSurface (srcimg, &src, gfx.screen, &dest);
// draw explosions if there is any // draw explosions if there is any

@ -8,12 +8,13 @@ int UpdateRects_nr = 0;
SDL_Rect UpdateRects[MAX_UPDATERECTS]; SDL_Rect UpdateRects[MAX_UPDATERECTS];
_gfx gfx; _gfx gfx;
void
getRGBpixel (SDL_Surface * surface, int x, int y, int *R, int *G, int *B)
void getRGBpixel (SDL_Surface *surface, int x, int y, int *R, int *G, int *B) { {
Uint32 pixel = 0; Uint32 pixel = 0;
Uint8 r,g,b; Uint8 r,
g,
b;
/* Lock the screen for direct access to the pixels */ /* Lock the screen for direct access to the pixels */
if (SDL_MUSTLOCK (surface)) if (SDL_MUSTLOCK (surface))
@ -21,13 +22,10 @@ void getRGBpixel (SDL_Surface *surface, int x, int y, int *R, int *G, int *B) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
return; return;
} }
pixel = getpixel (surface, x, y); pixel = getpixel (surface, x, y);
if (SDL_MUSTLOCK (surface)) { if (SDL_MUSTLOCK (surface)) {
SDL_UnlockSurface (surface); SDL_UnlockSurface (surface);
} }
SDL_GetRGB (pixel, surface->format, &r, &g, &b); SDL_GetRGB (pixel, surface->format, &r, &g, &b);
*R = r; *R = r;
*G = g; *G = g;
@ -35,103 +33,107 @@ void getRGBpixel (SDL_Surface *surface, int x, int y, int *R, int *G, int *B) {
}; };
Uint32 getpixel(SDL_Surface *surface, int x, int y) Uint32
getpixel (SDL_Surface * surface, int x, int y)
{ {
int bpp = surface->format->BytesPerPixel; int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to retrieve */ /* Here p is the address to the pixel we want to retrieve */
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
switch (bpp) { switch (bpp) {
case 1: case 1:
return *p; return *p;
case 2: case 2:
return *(Uint16 *) p; return *(Uint16 *) p;
case 3: case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2]; return p[0] << 16 | p[1] << 8 | p[2];
else else
return p[0] | p[1] << 8 | p[2] << 16; return p[0] | p[1] << 8 | p[2] << 16;
case 4: case 4:
return *(Uint32 *) p; return *(Uint32 *) p;
default: default:
return 0; /* shouldn't happen, but avoids warnings */ return 0; /* shouldn't happen, but avoids warnings */
} }
} };
void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) void
putpixel (SDL_Surface * surface, int x, int y, Uint32 pixel)
{ {
int bpp = surface->format->BytesPerPixel; int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to set */ /* Here p is the address to the pixel we want to set */
Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
switch (bpp) { switch (bpp) {
case 1: case 1:
*p = pixel; *p = pixel;
break; break;
case 2: case 2:
*(Uint16 *) p = pixel; *(Uint16 *) p = pixel;
break; break;
case 3: case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff; p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff; p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff; p[2] = pixel & 0xff;
} else { }
else {
p[0] = pixel & 0xff; p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff; p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff; p[2] = (pixel >> 16) & 0xff;
} }
break; break;
case 4: case 4:
*(Uint32 *) p = pixel; *(Uint32 *) p = pixel;
break; break;
} }
} };
void scale (short int *dpattern, short int x, short int y) {
int a, dx, dy;
void
scale (short int *dpattern, short int x, short int y)
{
int a,
dx,
dy;
if (x >= SCALE_MAXRES || y >= SCALE_MAXRES) { if (x >= SCALE_MAXRES || y >= SCALE_MAXRES) {
for (x = 0; x < SCALE_MAXRES; x++) for (x = 0; x < SCALE_MAXRES; x++)
dpattern[x] = 0; dpattern[x] = 0;
return; return;
} }
if (x > y) { if (x > y) {
dy = 2 * y; dy = 2 * y;
dx = a = 2 * x - dy; dx = a = 2 * x - dy;
do { do {
if (a <= 0) { if (a <= 0) {
dpattern[(y--) - 1] = x; dpattern[(y--) - 1] = x;
a = a + dx; a = a + dx;
} }
else else
a = a - dy; a = a - dy;
} while (x--); } while (x--);
} }
else { else {
dy = 2 * x; dy = 2 * x;
dx = a = 2 * y - dy; dx = a = 2 * y - dy;
do { do {
dpattern[y] = x; dpattern[y] = x;
if (a <= 0) { if (a <= 0) {
x--; x--;
a = a + dx; a = a + dx;
} }
else else
a = a - dy; a = a - dy;
} while (y--); } while (y--);
} }
} };
SDL_Surface * SDL_Surface *
@ -142,8 +144,8 @@ scale_image (SDL_Surface * orginal, int newx, int newy)
bmask, bmask,
amask; amask;
SDL_Surface *surface; SDL_Surface *surface;
int y,
int y, x; x;
short int xpattern[SCALE_MAXRES]; short int xpattern[SCALE_MAXRES];
short int ypattern[SCALE_MAXRES]; short int ypattern[SCALE_MAXRES];
@ -152,13 +154,14 @@ scale_image (SDL_Surface * orginal, int newx, int newy)
gmask = 0x00ff0000; gmask = 0x00ff0000;
bmask = 0x0000ff00; bmask = 0x0000ff00;
amask = 0x000000ff; amask = 0x000000ff;
#else
#else /* */
rmask = 0x00ff0000; rmask = 0x00ff0000;
gmask = 0x0000ff00; gmask = 0x0000ff00;
bmask = 0x000000ff; bmask = 0x000000ff;
amask = 0xff000000; amask = 0xff000000;
#endif
#endif /* */
surface = SDL_CreateRGBSurface (SDL_SWSURFACE, newx, newy, 32, rmask, gmask, bmask, amask); surface = SDL_CreateRGBSurface (SDL_SWSURFACE, newx, newy, 32, rmask, gmask, bmask, amask);
if (surface == NULL) { if (surface == NULL) {
fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ()); fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ());
@ -183,44 +186,48 @@ scale_image (SDL_Surface * orginal, int newx, int newy)
/* do the scaling work */ /* do the scaling work */
scale (xpattern, orginal->w - 1, newx); scale (xpattern, orginal->w - 1, newx);
scale (ypattern, orginal->h - 1, newy); scale (ypattern, orginal->h - 1, newy);
for (x = newx - 1; x >= 0; x--) for (x = newx - 1; x >= 0; x--)
for (y = newy - 1; y >= 0; y--) for (y = newy - 1; y >= 0; y--)
putpixel (surface, x, y, getpixel (orginal, xpattern[x], ypattern[y])); putpixel (surface, x, y, getpixel (orginal, xpattern[x], ypattern[y]));
if (SDL_MUSTLOCK (orginal)) { if (SDL_MUSTLOCK (orginal)) {
SDL_UnlockSurface (orginal); SDL_UnlockSurface (orginal);
} }
if (SDL_MUSTLOCK (surface)) { if (SDL_MUSTLOCK (surface)) {
SDL_UnlockSurface (surface); SDL_UnlockSurface (surface);
} }
return surface; return surface;
}; };
SDL_Surface *
SDL_Surface *makegray_image (SDL_Surface *org) { makegray_image (SDL_Surface * org)
{
Uint32 rmask, Uint32 rmask,
gmask, gmask,
bmask, bmask,
amask; amask;
Uint32 pixel, transpixel = 0; Uint32 pixel,
transpixel = 0;
SDL_Surface *dest; SDL_Surface *dest;
int y, x; int y,
Uint8 r,g,b,gray; x;
Uint8 r,
g,
b,
gray;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN #if SDL_BYTEORDER == SDL_BIG_ENDIAN
rmask = 0xff000000; rmask = 0xff000000;
gmask = 0x00ff0000; gmask = 0x00ff0000;
bmask = 0x0000ff00; bmask = 0x0000ff00;
amask = 0x000000ff; amask = 0x000000ff;
#else
#else /* */
rmask = 0x00ff0000; rmask = 0x00ff0000;
gmask = 0x0000ff00; gmask = 0x0000ff00;
bmask = 0x000000ff; bmask = 0x000000ff;
amask = 0xff000000; amask = 0xff000000;
#endif
#endif /* */
dest = SDL_CreateRGBSurface (SDL_SWSURFACE, org->w, org->h, 32, rmask, gmask, bmask, amask); dest = SDL_CreateRGBSurface (SDL_SWSURFACE, org->w, org->h, 32, rmask, gmask, bmask, amask);
if (dest == NULL) { if (dest == NULL) {
fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ()); fprintf (stderr, "CreateRGBSurface failed: %s\n", SDL_GetError ());
@ -233,7 +240,6 @@ SDL_Surface *makegray_image (SDL_Surface *org) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
return NULL; return NULL;
} }
if (SDL_MUSTLOCK (org)) if (SDL_MUSTLOCK (org))
if (SDL_LockSurface (org) < 0) { if (SDL_LockSurface (org) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
@ -242,48 +248,43 @@ SDL_Surface *makegray_image (SDL_Surface *org) {
} }
return NULL; return NULL;
} }
for (x = 0; x < org->w; x++) for (x = 0; x < org->w; x++)
for (y = 0; y < org->h; y++) { for (y = 0; y < org->h; y++) {
pixel = getpixel (org, x, y); pixel = getpixel (org, x, y);
if (x == 0 && y == 0) if (x == 0 && y == 0)
transpixel = pixel; transpixel = pixel;
if (pixel != transpixel) { if (pixel != transpixel) {
SDL_GetRGB (pixel, org->format, &r, &g, &b); SDL_GetRGB (pixel, org->format, &r, &g, &b);
gray = (r / 3 + g / 3 + b / 3); gray = (r / 3 + g / 3 + b / 3);
pixel = SDL_MapRGB (dest->format, gray, gray, gray); pixel = SDL_MapRGB (dest->format, gray, gray, gray);
} }
putpixel (dest, x, y, pixel); putpixel (dest, x, y, pixel);
} }
if (SDL_MUSTLOCK (org)) { if (SDL_MUSTLOCK (org)) {
SDL_UnlockSurface (org); SDL_UnlockSurface (org);
} }
if (SDL_MUSTLOCK (dest)) { if (SDL_MUSTLOCK (dest)) {
SDL_UnlockSurface (dest); SDL_UnlockSurface (dest);
} }
SDL_SetColorKey (dest, SDL_SRCCOLORKEY, transpixel); SDL_SetColorKey (dest, SDL_SRCCOLORKEY, transpixel);
return dest; return dest;
}; };
#define __smalsizeX 12 #define __smalsizeX 12
void gfx_load_players (int sx, int sy) { void
float sfkt, ssfkt; gfx_load_players (int sx, int sy)
{
float sfkt,
ssfkt;
char filename[255]; char filename[255];
int i, int i,
j, j,
r, r,
g, g,
b; b;
SDL_Surface *tmpimage, *tmpimage1; SDL_Surface *tmpimage,
*tmpimage1;
sfkt = ((float) sx) / ((float) GFX_IMGSIZE); sfkt = ((float) sx) / ((float) GFX_IMGSIZE);
ssfkt = ((float) __smalsizeX) / ((float) GFX_IMGSIZE); ssfkt = ((float) __smalsizeX) / ((float) GFX_IMGSIZE);
@ -300,16 +301,21 @@ void gfx_load_players (int sx, int sy) {
i--; // load the this image again i--; // load the this image again
j = 0; j = 0;
} }
else { else {
/* load the game player image */ /* load the game player image */
gfx.players[i].size.y = sy * 2; gfx.players[i].size.y = sy * 2;
gfx.players[i].size.x = (tmpimage->w / 4) * sfkt; gfx.players[i].size.x = (tmpimage->w / 4) * sfkt;
gfx.players[i].ani.frames = tmpimage->h / GFX_PLAYERIMGSIZE_Y; 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); 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); getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.players[i].ani.image = SDL_DisplayFormat (tmpimage1); gfx.players[i].ani.image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage1); SDL_FreeSurface (tmpimage1);
/* calculate the numbers of images for the animation */ /* calculate the numbers of images for the animation */
gfx.players[i].offset.x = (sx - gfx.players[i].size.x) / 2; gfx.players[i].offset.x = (sx - gfx.players[i].size.x) / 2;
gfx.players[i].offset.y = -sy; gfx.players[i].offset.y = -sy;
@ -317,7 +323,9 @@ void gfx_load_players (int sx, int sy) {
/* load the smal image */ /* load the smal image */
gfx.players[i].smal_size.y = __smalsizeX * 2; gfx.players[i].smal_size.y = __smalsizeX * 2;
gfx.players[i].smal_size.x = (tmpimage->w / 4) * ssfkt; 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); 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); getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.players[i].smal_image = SDL_DisplayFormat (tmpimage1); gfx.players[i].smal_image = SDL_DisplayFormat (tmpimage1);
@ -334,20 +342,22 @@ void gfx_load_players (int sx, int sy) {
exit (1); exit (1);
} }
gfx.ill.frames = tmpimage->h / (2 * GFX_IMGSIZE); gfx.ill.frames = tmpimage->h / (2 * GFX_IMGSIZE);
tmpimage1 = scale_image (tmpimage, (tmpimage->w / (2*GFX_IMGSIZE)) * (2 * sx), gfx.ill.frames * (2*sy)); tmpimage1 =
scale_image (tmpimage, (tmpimage->w / (2 * GFX_IMGSIZE)) * (2 * sx),
gfx.ill.frames * (2 * sy));
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.ill.image = SDL_DisplayFormat (tmpimage1); gfx.ill.image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage); SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1); SDL_FreeSurface (tmpimage1);
};
}
/* frees the player images */ /* frees the player images */
void gfx_free_players () { void
gfx_free_players ()
{
int i; int i;
for (i = 0; i < MAX_PLAYERS; i++) { for (i = 0; i < MAX_PLAYERS; i++) {
if (gfx.players[i].ani.image != NULL) if (gfx.players[i].ani.image != NULL)
SDL_FreeSurface (gfx.players[i].ani.image); SDL_FreeSurface (gfx.players[i].ani.image);
@ -356,57 +366,60 @@ void gfx_free_players () {
SDL_FreeSurface (gfx.players[i].smal_image); SDL_FreeSurface (gfx.players[i].smal_image);
gfx.players[i].smal_image = NULL; gfx.players[i].smal_image = NULL;
} }
SDL_FreeSurface (gfx.ill.image); SDL_FreeSurface (gfx.ill.image);
} }
/* load the images with the right scaleing */ /* load the images with the right scaleing */
void gfx_game_init () { void
gfx_game_init ()
{
menu_displaytext ("Loading..", "Please Wait", 32, 128, 32); menu_displaytext ("Loading..", "Please Wait", 32, 128, 32);
gfx_load_tileset (gfx.tileset); gfx_load_tileset (gfx.tileset);
gfx_load_players (gfx.block.x, gfx.block.y); gfx_load_players (gfx.block.x, gfx.block.y);
} };
void gfx_game_shutdown () { void
gfx_game_shutdown ()
{
menu_displaytext ("Freeing..", "Please Wait", 32, 128, 32); menu_displaytext ("Freeing..", "Please Wait", 32, 128, 32);
gfx_free_players (); gfx_free_players ();
gfx_free_tileset (); gfx_free_tileset ();
}; };
/* init the whole GFX Part */ /* init the whole GFX Part */
void gfx_init () { void
gfx_init ()
{
if (gfx.fullscreen) if (gfx.fullscreen)
gfx.screen = SDL_SetVideoMode (gfx.res.x, gfx.res.y, gfx.bpp, gfx.screen =
SDL_SetVideoMode (gfx.res.x, gfx.res.y, gfx.bpp,
SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL | SDL_FULLSCREEN); SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL | SDL_FULLSCREEN);
else else
gfx.screen = SDL_SetVideoMode (gfx.res.x, gfx.res.y, gfx.bpp, gfx.screen =
SDL_SetVideoMode (gfx.res.x, gfx.res.y, gfx.bpp,
SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL); SDL_SWSURFACE | SDL_DOUBLEBUF | SDL_HWACCEL);
if (gfx.screen == NULL) { if (gfx.screen == NULL) {
d_printf ("Unable to set video mode: %s\n", SDL_GetError ()); d_printf ("Unable to set video mode: %s\n", SDL_GetError ());
return; return;
} }
SDL_ShowCursor (SDL_DISABLE); SDL_ShowCursor (SDL_DISABLE);
gfx_loaddata (); gfx_loaddata ();
}; };
void void
gfx_loaddata () gfx_loaddata ()
{ {
int r, int r,
g, g,
b; b;
char filename[255]; char filename[255];
SDL_Surface *tmpimage, *tmpimage1; SDL_Surface *tmpimage,
*tmpimage1;
/* load the font */ /* load the font */
sprintf (filename, "%s/gfx/font.bmp", bman.datapath); sprintf (filename, "%s/gfx/font.bmp", bman.datapath);
@ -415,8 +428,7 @@ gfx_loaddata ()
printf ("Can't load image: %s\n", SDL_GetError ()); printf ("Can't load image: %s\n", SDL_GetError ());
exit (1); exit (1);
} }
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 0, 0, 0));
SDL_MapRGB (tmpimage->format, 0, 0, 0));
gfx.font.image = SDL_DisplayFormat (tmpimage); gfx.font.image = SDL_DisplayFormat (tmpimage);
gfx.font.size.x = 16; gfx.font.size.x = 16;
gfx.font.size.y = 16; gfx.font.size.y = 16;
@ -429,8 +441,7 @@ gfx_loaddata ()
printf ("Can't load image: %s\n", SDL_GetError ()); printf ("Can't load image: %s\n", SDL_GetError ());
exit (1); exit (1);
} }
SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_SetColorKey (tmpimage, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage->format, 0, 0, 0));
SDL_MapRGB (tmpimage->format, 0, 0, 0));
gfx.font1.image = SDL_DisplayFormat (tmpimage); gfx.font1.image = SDL_DisplayFormat (tmpimage);
gfx.font1.size.x = 16; gfx.font1.size.x = 16;
gfx.font1.size.y = 16; gfx.font1.size.y = 16;
@ -445,8 +456,7 @@ gfx_loaddata ()
} }
tmpimage1 = scale_image (tmpimage, gfx.res.x, gfx.res.y); tmpimage1 = scale_image (tmpimage, gfx.res.x, gfx.res.y);
SDL_FreeSurface (tmpimage); SDL_FreeSurface (tmpimage);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, 255, 255, 0));
SDL_MapRGB (tmpimage1->format, 255, 255, 0));
gfx.logo = SDL_DisplayFormat (tmpimage1); gfx.logo = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage1); SDL_FreeSurface (tmpimage1);
@ -466,43 +476,37 @@ gfx_loaddata ()
SDL_FreeSurface (tmpimage1); SDL_FreeSurface (tmpimage1);
}; };
void void
gfx_shutdown () gfx_shutdown ()
{ {
int i; int i;
for (i = 0; i < FT_max; i++) for (i = 0; i < FT_max; i++)
SDL_FreeSurface (gfx.field[i].image); SDL_FreeSurface (gfx.field[i].image);
for (i = 0; i < MAX_PLAYERS; i++) for (i = 0; i < MAX_PLAYERS; i++)
SDL_FreeSurface (gfx.players[i].ani.image); SDL_FreeSurface (gfx.players[i].ani.image);
SDL_FreeSurface (gfx.font.image); SDL_FreeSurface (gfx.font.image);
SDL_FreeSurface (gfx.font1.image); SDL_FreeSurface (gfx.font1.image);
SDL_FreeSurface (gfx.logo); SDL_FreeSurface (gfx.logo);
SDL_FreeSurface (gfx.bomb.image); SDL_FreeSurface (gfx.bomb.image);
SDL_FreeSurface (gfx.fire.image); SDL_FreeSurface (gfx.fire.image);
SDL_FreeSurface (gfx.menuselect.image); SDL_FreeSurface (gfx.menuselect.image);
gfx.screen = SDL_SetVideoMode (gfx.res.x, gfx.res.y, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);
gfx.screen = SDL_SetVideoMode (gfx.res.x, gfx.res.y, 16,
SDL_HWSURFACE | SDL_DOUBLEBUF);
SDL_FreeSurface (gfx.screen); SDL_FreeSurface (gfx.screen);
} };
void void
gfx_AddUpdateRect (int x, int y, int w, int h) gfx_AddUpdateRect (int x, int y, int w, int h)
{ {
if (UpdateRects_nr >= MAX_UPDATERECTS) if (UpdateRects_nr >= MAX_UPDATERECTS)
return; return;
UpdateRects[UpdateRects_nr].x = x; UpdateRects[UpdateRects_nr].x = x;
UpdateRects[UpdateRects_nr].y = y; UpdateRects[UpdateRects_nr].y = y;
UpdateRects[UpdateRects_nr].w = w; UpdateRects[UpdateRects_nr].w = w;
UpdateRects[UpdateRects_nr].h = h; UpdateRects[UpdateRects_nr].h = h;
UpdateRects_nr++; UpdateRects_nr++;
} };
void void
@ -511,85 +515,104 @@ gfx_UpdateRects ()
if (UpdateRects_nr > 0) if (UpdateRects_nr > 0)
SDL_UpdateRects (gfx.screen, UpdateRects_nr, UpdateRects); SDL_UpdateRects (gfx.screen, UpdateRects_nr, UpdateRects);
UpdateRects_nr = 0; UpdateRects_nr = 0;
};
}
void draw_logo () {
void
draw_logo ()
{
SDL_BlitSurface (gfx.logo, NULL, gfx.screen, NULL); SDL_BlitSurface (gfx.logo, NULL, gfx.screen, NULL);
UpdateRects_nr = 0; UpdateRects_nr = 0;
gfx_AddUpdateRect (0, 0, gfx.screen->w, gfx.screen->h); gfx_AddUpdateRect (0, 0, gfx.screen->w, gfx.screen->h);
} };
void redraw_logo_shaded (int x, int y, int w, int h, int c) {
void
redraw_logo_shaded (int x, int y, int w, int h, int c)
{
SDL_Rect dest; SDL_Rect dest;
dest.w = w; dest.w = w;
dest.h = h; dest.h = h;
dest.x = x; dest.x = x;
dest.y = y; dest.y = y;
redraw_logo (x, y, w + 1, h + 1); redraw_logo (x, y, w + 1, h + 1);
if (gfx_locksurface (gfx.screen)) if (gfx_locksurface (gfx.screen))
return; return;
dest.h += dest.y; dest.h += dest.y;
dest.w += dest.x; dest.w += dest.x;
draw_shadefield (gfx.screen, &dest, c); draw_shadefield (gfx.screen, &dest, c);
gfx_unlocksurface (gfx.screen); gfx_unlocksurface (gfx.screen);
}; };
void redraw_logo (int x, int y, int w, int h) { void
redraw_logo (int x, int y, int w, int h)
SDL_Rect src, dest; {
SDL_Rect src,
dest;
dest.w = src.w = w; dest.w = src.w = w;
dest.h = src.h = h; dest.h = src.h = h;
dest.x = x; dest.x = x;
dest.y = y; dest.y = y;
src.x = x; src.x = x;
src.y = y; src.y = y;
SDL_BlitSurface (gfx.logo, &src, gfx.screen, &dest); SDL_BlitSurface (gfx.logo, &src, gfx.screen, &dest);
// gfx_AddUpdateRect ();
}; };
void void
shade_pixel(SDL_Surface *s, int x, int y, int c) { shade_pixel (SDL_Surface * s, int x, int y, int c)
{
Uint32 p; Uint32 p;
Uint8 r,g,b; Uint8 r,
g,
b;
p = getpixel (s, x, y); p = getpixel (s, x, y);
SDL_GetRGB (p, s->format, &r, &g, &b); SDL_GetRGB (p, s->format, &r, &g, &b);
if (c > 0) { if (c > 0) {
if (((Sint16) r) + c < 256) {r += c;} else r = 255; if (((Sint16) r) + c < 256) {
if (((Sint16) g) + c < 256) {g += c;} else g = 255; r += c;
if (((Sint16) b) + c < 256) {b += c;} else b = 255;
} }
else { else
if (((Sint16) r) + c > 0) {r += c;} else r = 0; r = 255;
if (((Sint16) g) + c > 0) {g += c;} else g = 0; if (((Sint16) g) + c < 256) {
if (((Sint16) b) + c > 0) {b += c;} else b = 0; 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); p = SDL_MapRGB (s->format, r, g, b);
putpixel (s, x, y, p); putpixel (s, x, y, p);
} };
int gfx_locksurface (SDL_Surface *surface) {
int
gfx_locksurface (SDL_Surface * surface)
{
if (SDL_MUSTLOCK (surface)) if (SDL_MUSTLOCK (surface))
if (SDL_LockSurface (surface) < 0) { if (SDL_LockSurface (surface) < 0) {
fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ()); fprintf (stderr, "Can't lock screen: %s\n", SDL_GetError ());
@ -599,7 +622,10 @@ int gfx_locksurface (SDL_Surface *surface) {
}; };
void gfx_unlocksurface (SDL_Surface *surface) {
void
gfx_unlocksurface (SDL_Surface * surface)
{
if (SDL_MUSTLOCK (surface)) { if (SDL_MUSTLOCK (surface)) {
SDL_UnlockSurface (surface); SDL_UnlockSurface (surface);
} }
@ -607,69 +633,74 @@ void gfx_unlocksurface (SDL_Surface *surface) {
void void
draw_shadefield (SDL_Surface *s, SDL_Rect *rec, int c) { draw_shadefield (SDL_Surface * s, SDL_Rect * rec, int c)
int x1, x, x2, y1, y; {
int x1,
x,
x2,
y1,
y;
if (rec->x > rec->w) { if (rec->x > rec->w) {
x1 = rec->w; x1 = rec->w;
x2 = rec->x; x2 = rec->x;
} }
else { else {
x2 = rec->w; x2 = rec->w;
x1 = rec->x; x1 = rec->x;
} }
if (rec->y > rec->h) { if (rec->y > rec->h) {
y = rec->h; y = rec->h;
y1 = rec->y; y1 = rec->y;
} }
else { else {
y1 = rec->h; y1 = rec->h;
y = rec->y; y = rec->y;
} }
for (; y <= y1; y++) for (; y <= y1; y++)
for (x = x1; x <= x2; x++) for (x = x1; x <= x2; x++)
shade_pixel (s, x, y, c); shade_pixel (s, x, y, c);
}; };
SDL_Surface *gfx_copyscreen (SDL_Rect *wnd) { SDL_Surface *
gfx_copyscreen (SDL_Rect * wnd)
{
SDL_Surface *res; SDL_Surface *res;
SDL_Rect dest; SDL_Rect dest;
res =
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); 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.x = 0;
dest.y = 0; dest.y = 0;
dest.w = wnd->w; dest.w = wnd->w;
dest.h = wnd->h; dest.h = wnd->h;
SDL_BlitSurface (gfx.screen, wnd, res, &dest); SDL_BlitSurface (gfx.screen, wnd, res, &dest);
return res; return res;
}; };
void
gfx_load_tileset (char *tilesetname)
void gfx_load_tileset (char *tilesetname) { {
int i, int i,
r, r,
g, g,
b; b;
char filename[LEN_PATHFILENAME]; char filename[LEN_PATHFILENAME];
char tileset[LEN_TILESETNAME]; char tileset[LEN_TILESETNAME];
SDL_Surface *tmpimage, *tmpimage1; SDL_Surface *tmpimage,
*tmpimage1;
float sfkt; float sfkt;
d_printf ("Loading Tileset: %s\n", tilesetname); d_printf ("Loading Tileset: %s\n", tilesetname);
strncpy (tileset, tilesetname, LEN_TILESETNAME); strncpy (tileset, tilesetname, LEN_TILESETNAME);
/* Calculate the Best Size of the Images */ /* Calculate the Best Size of the Images */
gfx.block.x = gfx.res.x / (bman.fieldsize.x + 1); gfx.block.x = gfx.res.x / (bman.fieldsize.x + 1);
gfx.block.y = (gfx.res.y - 80) / (bman.fieldsize.y + 1); gfx.block.y = (gfx.res.y - 80) / (bman.fieldsize.y + 1);
if (gfx.block.x < gfx.block.y) if (gfx.block.x < gfx.block.y)
gfx.block.y = gfx.block.x; gfx.block.y = gfx.block.x;
else else
gfx.block.x = gfx.block.y; gfx.block.x = gfx.block.y;
@ -685,6 +716,7 @@ void gfx_load_tileset (char *tilesetname) {
sprintf (filename, "%s/tileset/%s/fire.bmp", bman.datapath, tileset); sprintf (filename, "%s/tileset/%s/fire.bmp", bman.datapath, tileset);
tmpimage = SDL_LoadBMP (filename); tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) { if (tmpimage == NULL) {
/* file could not be load, so load teh default tileset */ /* file could not be load, so load teh default tileset */
printf ("Can't load tileset: %s\n", SDL_GetError ()); printf ("Can't load tileset: %s\n", SDL_GetError ());
if (strcmp (tileset, "default") != 0) { if (strcmp (tileset, "default") != 0) {
@ -695,13 +727,18 @@ void gfx_load_tileset (char *tilesetname) {
printf ("default tileset could not be loaded.\n"); printf ("default tileset could not be loaded.\n");
exit (1); exit (1);
} }
else else
printf ("switching to default tileset.\n"); printf ("switching to default tileset.\n");
} }
else exit (1);
else
exit (1);
} }
gfx.fire.frames = tmpimage->h / GFX_IMGSIZE; gfx.fire.frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 = scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x, gfx.fire.frames * gfx.block.y); tmpimage1 =
scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.fire.frames * gfx.block.y);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.fire.image = SDL_DisplayFormat (tmpimage1); gfx.fire.image = SDL_DisplayFormat (tmpimage1);
@ -716,7 +753,9 @@ void gfx_load_tileset (char *tilesetname) {
exit (1); exit (1);
} }
gfx.bomb.frames = tmpimage->h / GFX_IMGSIZE; gfx.bomb.frames = tmpimage->h / GFX_IMGSIZE;
tmpimage1 = scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x, gfx.bomb.frames * gfx.block.y); tmpimage1 =
scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.bomb.frames * gfx.block.y);
getRGBpixel (tmpimage1, 0, 0, &r, &g, &b); getRGBpixel (tmpimage1, 0, 0, &r, &g, &b);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b)); SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, r, g, b));
gfx.bomb.image = SDL_DisplayFormat (tmpimage1); gfx.bomb.image = SDL_DisplayFormat (tmpimage1);
@ -748,40 +787,36 @@ void gfx_load_tileset (char *tilesetname) {
sprintf (filename, "%s/tileset/%s/fieldshoe.bmp", bman.datapath, tileset); sprintf (filename, "%s/tileset/%s/fieldshoe.bmp", bman.datapath, tileset);
break; break;
} }
tmpimage = SDL_LoadBMP (filename); tmpimage = SDL_LoadBMP (filename);
if (tmpimage == NULL) { if (tmpimage == NULL) {
printf ("Can't load image: %s\n", SDL_GetError ()); printf ("Can't load image: %s\n", SDL_GetError ());
exit (1); exit (1);
} }
gfx.field[i].frames = tmpimage->h / GFX_IMGSIZE; 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); tmpimage1 = scale_image (tmpimage, (tmpimage->w / GFX_IMGSIZE) * gfx.block.x,
gfx.field[i].frames * gfx.block.y);
SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, 255, 255, 255)); SDL_SetColorKey (tmpimage1, SDL_SRCCOLORKEY, SDL_MapRGB (tmpimage1->format, 255, 255, 255));
gfx.field[i].image = SDL_DisplayFormat (tmpimage1); gfx.field[i].image = SDL_DisplayFormat (tmpimage1);
SDL_FreeSurface (tmpimage); SDL_FreeSurface (tmpimage);
SDL_FreeSurface (tmpimage1); SDL_FreeSurface (tmpimage1);
} }
UpdateRects_nr = 0; UpdateRects_nr = 0;
}; };
void gfx_free_tileset () { void
gfx_free_tileset ()
{
int i; int i;
for (i = 0; i < FT_max; i++) { for (i = 0; i < FT_max; i++) {
if (gfx.field[i].image != NULL) if (gfx.field[i].image != NULL)
SDL_FreeSurface (gfx.field[i].image); SDL_FreeSurface (gfx.field[i].image);
gfx.field[i].image = NULL; gfx.field[i].image = NULL;
} }
if (gfx.bomb.image != NULL) if (gfx.bomb.image != NULL)
SDL_FreeSurface (gfx.bomb.image); SDL_FreeSurface (gfx.bomb.image);
if (gfx.fire.image != NULL) if (gfx.fire.image != NULL)
SDL_FreeSurface (gfx.fire.image); SDL_FreeSurface (gfx.fire.image);
gfx.bomb.image = NULL; gfx.bomb.image = NULL;
gfx.fire.image = NULL; gfx.fire.image = NULL;
}; };

@ -1,4 +1,4 @@
/* $Id: menu.c,v 1.17 2003/05/07 21:30:36 stpohle Exp $ */ /* $Id: menu.c,v 1.18 2003/05/08 14:35:49 stpohle Exp $ */
/* menu's for the game */ /* menu's for the game */
#include <SDL.h> #include <SDL.h>

@ -1,4 +1,4 @@
/* $Id: network.c,v 1.15 2003/05/07 21:28:12 stpohle Exp $ */ /* $Id: network.c,v 1.16 2003/05/08 14:35:49 stpohle Exp $ */
/* /*
network routines. network routines.
*/ */

@ -1,4 +1,4 @@
/* $Id: single.c,v 1.9 2003/05/07 21:28:13 stpohle Exp $ */ /* $Id: single.c,v 1.10 2003/05/08 14:35:49 stpohle Exp $ */
/* single player */ /* single player */
#include "basic.h" #include "basic.h"

@ -1,4 +1,4 @@
/* $Id: sysfunc.h,v 1.4 2003/05/07 21:28:13 stpohle Exp $ */ /* $Id: sysfunc.h,v 1.5 2003/05/08 14:35:49 stpohle Exp $ */
/* include some system near functions */ /* include some system near functions */
#ifndef _SYSFUNC_H_ #ifndef _SYSFUNC_H_

@ -1,4 +1,4 @@
/* $Id: udp.c,v 1.6 2003/05/07 21:28:13 stpohle Exp $ */ /* $Id: udp.c,v 1.7 2003/05/08 14:35:49 stpohle Exp $ */
/* udp.c code for the network /* udp.c code for the network
File Version 0.2 File Version 0.2
*/ */

Loading…
Cancel
Save