Iām sorry ,my English is not good
Im SDL beginner,i try make some image Effects,i got a game resource file ,in this game have a effect like this
i try make it,i uses follow code:
//The headers
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <string>
//Screen attributes
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 600;
const int SCREEN_BPP = 32;
SDL_Color BGC={125,120,255};
//The surfaces
SDL_Surface *screen = NULL;
SDL_Surface *bg = NULL;
SDL_Surface *tm = NULL;
SDL_Surface *yf = NULL;
SDL_Surface *wp = NULL;
SDL_Surface *mz = NULL;
//The event structure
SDL_Event event;
SDL_Surface *load_image( std::string filename )
{
//The image that's loaded
SDL_Surface* loadedImage = NULL;
//The optimized surface that will be used
SDL_Surface* optimizedImage = NULL;
//Load the image
loadedImage = IMG_Load( filename.c_str() );
//If the image loaded
if( loadedImage != NULL )
{
//Create an optimized surface
optimizedImage = SDL_DisplayFormat( loadedImage );
//Free the old surface
SDL_FreeSurface( loadedImage );
//If the surface was optimized
if( optimizedImage != NULL )
{
//Color key surface
SDL_SetColorKey( optimizedImage, SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0, 0 ) );
}
}
//Return the optimized surface
return optimizedImage;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination, SDL_Rect* clip = NULL )
{
//Holds offsets
SDL_Rect offset;
//Get offsets
offset.x = x;
offset.y = y;
//Blit
SDL_BlitSurface( source, clip, destination, &offset );
}
bool init()
{
//Initialize all SDL subsystems
if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
{
return false;
}
//Set up the screen
screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
//If there was an error in setting up the screen
if( screen == NULL )
{
return false;
}
SDL_WM_SetCaption( "alpha", NULL );
//If everything initialized fine
return true;
}
bool load_files()
{
//Load the background image
bg = load_image( "mbg.bmp" );
tm = load_image( "tc2.bmp" );
yf = load_image( "tc1.bmp" );
wp = load_image( "lxd.bmp" );
mz = load_image( "kltk.bmp" );
//If there was a problem in loading the background
if( bg == NULL )
{
return false;
}
//If everything loaded fine
return true;
}
void clean_up()
{
//Free the surfaces
SDL_FreeSurface( bg );
//Quit SDL
SDL_Quit();
}
int main( int argc, char* args[] )
{
int ti=200;//e(R) 3/4 c 1/2 (R)e??ae??ao|
//Quit flag
bool quit = false;
//Initialize
if( init() == false )
{
return 1;
}
//Load the files
if( load_files() == false )
{
return 1;
}
SDL_FillRect(screen,0,SDL_MapRGB( screen->format,BGC.r,BGC.g,BGC.b )) ;
//Apply the background
apply_surface( -7,44, bg, screen );//a+-?ae??ae!?e??ae??a??a??ae ? 7 -44i 1/4 ?ae??a??a??ae ?e''a? 3/4 a,?e? 1/2 ae? 3/4 c?oa(R)?ae?'i 1/4 ?a?(R)ae?1a,o0 0ae? 3/4 c?o
SDL_SetAlpha( tm, SDL_SRCALPHA|SDL_RLEACCEL, ti );//a??e??ae??ae? 3/4 c?oa? 3/4 c??
apply_surface( 145, 170, yf, screen );//e!GBPae??a??a+-?ae??ae!?a??ae ?a,?a??a,?a,aa??ae ?c3>>i 1/4 ?a,?e??a??ae ?ae? a??e??ae??i 1/4 ?ae??a>>JPYe!GBPae??a??ae ?a,oa?oa?? (a??a? 3/4 x=-22 y=-123)
apply_surface( 102, 107, wp, screen );// (a??a? 3/4 x=-65 y=-186)ae??e''a? 3/4 a??ae ?a,o(a?oa??a 1/2 ?a??a??ae ? +(a 1/2 ?a??e''a? 3/4 a??a??ae ?-(a?oa??a??a??ae ?))ae-?a??a,oi 1/4 ?145+(-65-(-22))=102 170+(-186-(-123))=107
apply_surface( 176, 160, mz, screen );//(a??a? 3/4 x=9 y=-133)ae-?a??a??ae ?a,oi 1/4 ?145+(9-(-22))=176 170+(-133-(-123))=160
apply_surface( 82,76, tm, screen );//(-85 -217) 145+(-85-(-22))= 82 170+(-217-(-123))=76
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
//While the user hasn't quit
while( quit == false )
{
//While there's events to handle
while( SDL_PollEvent( &event ) )
{
//If a key was pressed
//If the user has Xed out the window
SDL_Delay(100);
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
}
}
//Free surfaces, fonts and sounds
//then quit SDL_mixer, SDL_ttf and SDL
clean_up();
return 0;
}
i got effect like this:
the resource file is BMP,like this
how get the effect like in the game?
all resource file is here http://fuwensoft.99k.org/pic/alpha.zip