@ -1,4 +1,4 @@
/* $Id: gfx.c,v 1.3 6 2004/09/12 20:54:24 stpohle Exp $ */
/* $Id: gfx.c,v 1.3 7 2004/09/25 10:57:51 stpohle Exp $ */
/* gfx.c */
# include "bomberclone.h"
@ -6,7 +6,34 @@
_gfx gfx ;
# define __smalsizeX 12
static int gfx_get_nr_of_playergfx ( ) ;
static void gfx_load_menusmall_players ( ) ;
static void gfx_load_fieldtype_menu ( ) ;
/*
* count all playergfx
*/
static int gfx_get_nr_of_playergfx ( ) {
int i = 0 ;
FILE * f = NULL ;
char filename [ 255 ] ;
do {
if ( f ) {
fclose ( f ) ;
i + + ;
}
sprintf ( filename , " %s/player/player%d.png " , bman . datapath , i ) ;
f = fopen ( filename , " r " ) ;
} while ( f ) ;
return i ;
}
/*
* Load all players graphics we have
*/
void
gfx_load_players ( int sx , int sy )
{
@ -14,31 +41,26 @@ gfx_load_players (int sx, int sy)
ssfkt ;
char filename [ 255 ] ;
int i ,
j ,
r ,
g ,
b ;
SDL_Surface * tmpimage ,
* tmpimage1 ;
sfkt = ( ( float ) sx ) / ( ( float ) GFX_IMGSIZE ) ;
ssfkt = ( ( float ) __smalsize X) / ( ( float ) GFX_IMGSIZE ) ;
ssfkt = ( ( float ) GFX _SMALLPLAYERIMGSIZE _X) / ( ( float ) GFX_IMGSIZE ) ;
d_printf ( " gfx_load_players (%d, %d) \n " , sx , sy ) ;
/* loading the player images */
for ( j = i = 0 ; i < MAX_PLAYERS ; i + + ) {
sprintf ( filename , " %s/player/player%d.png " , bman . datapath , j ) ;
j + + ;
for ( i = 0 ; i < gfx . player_gfx_count ; i + + ) {
sprintf ( filename , " %s/player/player%d.png " , bman . datapath , i ) ;
tmpimage = IMG_Load ( 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 ;
}
printf ( " Can't load image: %s \n " , SDL_GetError ( ) ) ;
exit ( 1 ) ;
}
else {
/* load the game player image */
gfx . players [ i ] . ani . h = sy * 2 ;
gfx . players [ i ] . ani . w = ( tmpimage - > w / 4 ) * sfkt ;
@ -55,18 +77,7 @@ gfx_load_players (int sx, int sy)
gfx . players [ i ] . offset . x = ( sx - gfx . players [ i ] . ani . w ) / 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 ) ;
}
}
@ -129,13 +140,12 @@ gfx_free_players ()
{
int i ;
for ( i = 0 ; i < MAX_PLAYERS ; i + + ) {
d_printf ( " gfx_free_players \n " ) ;
for ( i = 0 ; i < gfx . player_gfx_count ; 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 ;
}
if ( gfx . dead . image ! = NULL )
@ -151,6 +161,8 @@ gfx_free_players ()
void
gfx_init ( )
{
int i ;
if ( gfx . fullscreen )
gfx . screen =
SDL_SetVideoMode ( gfx . res . x , gfx . res . y , gfx . bpp ,
@ -165,11 +177,24 @@ gfx_init ()
return ;
}
SDL_ShowCursor ( SDL_DISABLE ) ;
/* delete small gfx und the menu player gfx */
gfx . player_gfx_count = gfx_get_nr_of_playergfx ( ) ;
gfx . players = malloc ( gfx . player_gfx_count * sizeof ( _gfxplayer ) ) ;
for ( i = 0 ; i < gfx . player_gfx_count ; i + + ) {
gfx . players [ i ] . ani . image = NULL ;
gfx . players [ i ] . small_image = NULL ;
gfx . players [ i ] . menu_image = NULL ;
}
for ( i = 0 ; i < FT_max ; i + + ) gfx . menu_field [ i ] = NULL ;
gfx_blitupdaterectclear ( ) ;
gfx_loaddata ( ) ;
} ;
void
gfx_loaddata ( )
{
@ -182,18 +207,8 @@ gfx_loaddata ()
sprintf ( filename , " %s/gfx/logo.png " , bman . datapath ) ;
tmpimage = IMG_Load ( filename ) ;
if ( tmpimage = = NULL ) {
sprintf ( bman . datapath , " data " ) ;
sprintf ( filename , " %s/gfx/logo.png " , bman . datapath ) ;
tmpimage = IMG_Load ( filename ) ;
if ( tmpimage = = NULL ) {
sprintf ( bman . datapath , " ../data " ) ;
sprintf ( filename , " %s/gfx/logo.png " , bman . datapath ) ;
tmpimage = IMG_Load ( filename ) ;
if ( tmpimage = = NULL ) {
printf ( " Can't load image: %s \n " , SDL_GetError ( ) ) ;
exit ( 1 ) ;
}
}
printf ( " Can't load image: %s \n " , SDL_GetError ( ) ) ;
exit ( 1 ) ;
}
tmpimage1 = scale_image ( tmpimage , gfx . res . x , gfx . res . y ) ;
SDL_FreeSurface ( tmpimage ) ;
@ -263,9 +278,185 @@ gfx_loaddata ()
exit ( 1 ) ;
}
gfx . menuselect . frames = tmpimage - > h / ( 2 * GFX_IMGSIZE ) ;
gfx_load_fieldtype_menu ( ) ;
gfx_load_menusmall_players ( ) ;
} ;
/***
* load a single frame of the player
*/
static void gfx_load_menusmall_players ( ) {
SDL_Surface * orgimg , * tmpimg ;
int i , r , g , b ;
float sfkt ;
char filename [ 255 ] ;
for ( i = 0 ; i < gfx . player_gfx_count ; i + + ) {
if ( gfx . players [ i ] . small_image = = NULL | | gfx . players [ i ] . menu_image = = NULL ) {
SDL_Surface * img ;
SDL_Rect rect ;
sprintf ( filename , " %s/player/player%d.png " , bman . datapath , i ) ;
orgimg = IMG_Load ( filename ) ;
if ( orgimg = = NULL ) {
printf ( " Can't load image: %s \n " , SDL_GetError ( ) ) ;
exit ( 1 ) ;
}
rect . x = 3 * ( orgimg - > w / 4 ) ;
rect . y = 0 ;
rect . w = orgimg - > w / 4 ;
rect . h = GFX_PLAYERIMGSIZE_Y ;
img = gfx_copyfrom ( orgimg , & rect ) ;
SDL_FreeSurface ( orgimg ) ;
/* small image */
sfkt = ( float ) ( ( ( float ) ( GFX_SMALLPLAYERIMGSIZE_X * 2 ) ) / ( ( float ) img - > h ) ) ;
if ( gfx . players [ i ] . small_image = = NULL ) {
tmpimg = scale_image ( img , ( int ) ( ( ( float ) img - > w ) * sfkt ) , GFX_SMALLPLAYERIMGSIZE_X * 2 ) ;
getRGBpixel ( tmpimg , 0 , 0 , & r , & g , & b ) ;
SDL_SetColorKey ( tmpimg , SDL_SRCCOLORKEY , SDL_MapRGB ( tmpimg - > format , r , g , b ) ) ;
gfx . players [ i ] . small_image = SDL_DisplayFormat ( tmpimg ) ;
SDL_FreeSurface ( tmpimg ) ;
}
/* menu image */
sfkt = ( float ) ( ( ( float ) ( GFX_MENUPLAYERIMGSIZE_X * 2 ) ) / ( ( float ) img - > h ) ) ;
if ( gfx . players [ i ] . menu_image = = NULL ) {
tmpimg = scale_image ( img , ( int ) ( ( ( float ) img - > w ) * sfkt ) , GFX_MENUPLAYERIMGSIZE_X * 2 ) ;
getRGBpixel ( tmpimg , 0 , 0 , & r , & g , & b ) ;
SDL_SetColorKey ( tmpimg , SDL_SRCCOLORKEY , SDL_MapRGB ( tmpimg - > format , r , g , b ) ) ;
gfx . players [ i ] . menu_image = SDL_DisplayFormat ( tmpimg ) ;
SDL_FreeSurface ( tmpimg ) ;
}
SDL_FreeSurface ( img ) ;
}
}
}
/***
* load a single frame from the powerups
*/
static void gfx_load_fieldtype_menu ( ) {
int i , ft , r , g , b ;
SDL_Surface * background = NULL , * orgimg = NULL , * tmpimg = NULL ;
char filename [ 255 ] ;
SDL_Rect rect ;
for ( i = 0 ; i < FT_max ; i + + ) {
if ( gfx . menu_field [ i ] ! = NULL ) SDL_FreeSurface ( gfx . menu_field [ i ] ) ;
gfx . menu_field [ i ] = NULL ;
}
rect . x = 0 ;
rect . y = 0 ;
rect . w = GFX_IMGSIZE ;
rect . h = GFX_IMGSIZE ;
for ( ft = 0 ; ft < FT_max ; ft + + ) if ( ft ! = FT_mixed ) {
/*
* load background image
*/
if ( ft = = 0 ) {
if ( background ! = NULL ) SDL_FreeSurface ( background ) ;
sprintf ( filename , " %s/tileset/default/background.png " , bman . datapath ) ;
orgimg = IMG_Load ( filename ) ;
if ( ! orgimg ) {
printf ( " Can't load image. :%s \n " , SDL_GetError ( ) ) ;
exit ( 1 ) ;
}
tmpimg = gfx_copyfrom ( orgimg , & rect ) ;
SDL_FreeSurface ( orgimg ) ;
orgimg = scale_image ( tmpimg , GFX_IMGSIZE / 2 , GFX_IMGSIZE / 2 ) ;
SDL_FreeSurface ( tmpimg ) ;
background = SDL_DisplayFormat ( orgimg ) ;
SDL_FreeSurface ( orgimg ) ;
}
if ( ft = = FT_death ) {
if ( background ! = NULL ) SDL_FreeSurface ( background ) ;
sprintf ( filename , " %s/tileset/default/powerbad.png " , bman . datapath ) ;
orgimg = IMG_Load ( filename ) ;
if ( ! orgimg ) {
printf ( " Can't load image. :%s \n " , SDL_GetError ( ) ) ;
exit ( 1 ) ;
}
tmpimg = gfx_copyfrom ( orgimg , & rect ) ;
SDL_FreeSurface ( orgimg ) ;
orgimg = scale_image ( tmpimg , GFX_IMGSIZE / 2 , GFX_IMGSIZE / 2 ) ;
SDL_FreeSurface ( tmpimg ) ;
background = SDL_DisplayFormat ( orgimg ) ;
SDL_FreeSurface ( orgimg ) ;
}
if ( ft = = FT_fire ) {
if ( background ! = NULL ) SDL_FreeSurface ( background ) ;
sprintf ( filename , " %s/tileset/default/powerup.png " , bman . datapath ) ;
orgimg = IMG_Load ( filename ) ;
if ( ! orgimg ) {
printf ( " Can't load image. :%s \n " , SDL_GetError ( ) ) ;
exit ( 1 ) ;
}
tmpimg = gfx_copyfrom ( orgimg , & rect ) ;
SDL_FreeSurface ( orgimg ) ;
orgimg = scale_image ( tmpimg , GFX_IMGSIZE / 2 , GFX_IMGSIZE / 2 ) ;
SDL_FreeSurface ( tmpimg ) ;
background = SDL_DisplayFormat ( orgimg ) ;
SDL_FreeSurface ( orgimg ) ;
}
if ( ft = = FT_sp_trigger ) {
if ( background ! = NULL ) SDL_FreeSurface ( background ) ;
sprintf ( filename , " %s/tileset/default/powersp.png " , bman . datapath ) ;
orgimg = IMG_Load ( filename ) ;
if ( ! orgimg ) {
printf ( " Can't load image. :%s \n " , SDL_GetError ( ) ) ;
exit ( 1 ) ;
}
tmpimg = gfx_copyfrom ( orgimg , & rect ) ;
SDL_FreeSurface ( orgimg ) ;
orgimg = scale_image ( tmpimg , GFX_IMGSIZE / 2 , GFX_IMGSIZE / 2 ) ;
SDL_FreeSurface ( tmpimg ) ;
background = SDL_DisplayFormat ( orgimg ) ;
SDL_FreeSurface ( orgimg ) ;
}
/*
* load fieldgfx for the menu
*/
gfx . menu_field [ ft ] = gfx_copyfrom ( background , & rect ) ;
sprintf ( filename , " %s/tileset/default/%s.png " , bman . datapath , ft_filenames [ ft ] ) ;
orgimg = IMG_Load ( filename ) ;
if ( ! orgimg ) {
printf ( " Can't load image. :%s \n " , SDL_GetError ( ) ) ;
exit ( 1 ) ;
}
tmpimg = gfx_copyfrom ( orgimg , & rect ) ;
SDL_FreeSurface ( orgimg ) ;
orgimg = scale_image ( tmpimg , GFX_IMGSIZE / 2 , GFX_IMGSIZE / 2 ) ;
SDL_FreeSurface ( tmpimg ) ;
getRGBpixel ( orgimg , 0 , 0 , & r , & g , & b ) ;
SDL_SetColorKey ( orgimg , SDL_SRCCOLORKEY , SDL_MapRGB ( orgimg - > format , r , g , b ) ) ;
tmpimg = SDL_DisplayFormat ( orgimg ) ;
SDL_FreeSurface ( orgimg ) ;
SDL_BlitSurface ( tmpimg , NULL , gfx . menu_field [ ft ] , NULL ) ;
SDL_FreeSurface ( tmpimg ) ;
}
if ( background )
SDL_FreeSurface ( background ) ;
}
void
gfx_shutdown ( )
{
@ -280,14 +471,29 @@ gfx_shutdown ()
}
for ( j = 0 ; j < 2 ; j + + )
SDL_FreeSurface ( menulistimages [ j ] [ i ] ) ;
}
for ( i = 0 ; i < gfx . player_gfx_count ; i + + ) {
if ( gfx . players [ i ] . small_image ! = NULL ) {
SDL_FreeSurface ( gfx . players [ i ] . small_image ) ;
gfx . players [ i ] . small_image = NULL ;
}
if ( gfx . players [ i ] . menu_image ! = NULL ) {
SDL_FreeSurface ( gfx . players [ i ] . menu_image ) ;
gfx . players [ i ] . menu_image = NULL ;
}
}
for ( i = 0 ; i < FT_max ; i + + ) if ( gfx . menu_field [ i ] ! = NULL ) {
SDL_FreeSurface ( gfx . menu_field [ i ] ) ;
gfx . menu_field [ i ] = NULL ;
}
SDL_FreeSurface ( gfx . logo ) ;
SDL_FreeSurface ( gfx . menuselect . image ) ;
gfx . screen = SDL_SetVideoMode ( gfx . res . x , gfx . res . y , 16 , SDL_HWSURFACE | SDL_DOUBLEBUF ) ;
SDL_FreeSurface ( gfx . screen ) ;
font_free ( ) ;
} ;