1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| #include "SDL.h"
#include "SDL_image.h"
#include "tools.h"
int main(int argc, char *argv[])
{
int pidx = 0 ;
SDL_Surface *screen ;
enum walk { justice1 , justice2 , justice3 , justice4
, justice5 , justice6 , justice_No };
SDL_Surface *anim[justice_No];
SDL_Rect animRect ;
animRect.x = 160 ;
animRect.y = 160 ;
atexit(SDL_Quit);
if( SDL_Init(SDL_INIT_VIDEO) < 0 ) exit(1);
SDL_WM_SetCaption("SDL Window", NULL);
screen = SDL_SetVideoMode( 400 , 300 , 32 , SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_ANYFORMAT);
// Use the new add image loader function to load GIF , JPG , PNG image file.
// Here shows two equivalent ways to load a image file that has a white
// background (RGB=255,255,255)
anim[0] = ImgLoader("./anim/justice1.gif",1,255,255,255,0);
anim[1] = ImgLoader("./anim/justice2.gif",1,255,255,255,0);
anim[2] = ImgLoader("./anim/justice3.gif",1,255,255,255,0);
anim[3] = ImgLoader("./anim/justice4.gif",1,255,255,255,0);
anim[4] = ImgLoader("./anim/justice5.gif",1,255,255,255,0);
anim[5] = ImgLoader("./anim/justice6.gif",1,255,255,255,0);
for(int tick=0 ; tick<1000 ; tick++ ) {
SDL_FillRect(screen , NULL , 0x221122);
SDL_BlitSurface( anim[pidx] , NULL , screen , &animRect );
SDL_Flip(screen);
SDL_Delay(20); // Delay 20 msec
pidx++;
if(pidx >= justice_No) pidx = 0;
}; // for(int tick=0 ; tick<1000 ; tick++ ) { END
return 0;
} |