Original Post
void DrawScene()
{
sun.clearBG();
Swords.clearBG();
sun.updateBG();
Swords.updateBG();
sun.draw();
Swords.draw();
SDL_Flip(screen);
}
SDL_Surface * ImageLoad(char *file)
{
SDL_Surface *temp1, *temp2;
temp1 = SDL_LoadBMP(file);
temp2 = SDL_DisplayFormat(temp1);
SDL_FreeSurface(temp1);
return temp2;
}
int InitImages()
{
back = ImageLoad("back.bmp");
image = ImageLoad("map1.bmp");
return 0;
}
//---------------------------------------------
void DrawBG(SDL_Surface *bg)
{
//Slock(screen);
SDL_FillRect(screen, NULL, 0);
DrawIMG(bg, 0, 0);
}
//---------------------------------------------
int main(int argc, char *argv[])
{
Uint8* keys;
my_timer_id = SDL_AddTimer((33/10)*10, my_callbackfunc, my_callback_param);
if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER) <0 )
{
printf("Unable to init SDL: %s\n", SDL_GetError());
return 1;
}
atexit(SDL_Quit);
if(Mix_OpenAudio(44100, AUDIO_S16SYS, 2, 2048) < 0)
{
printf("Warning: Couldn't set 44100 Hz 16-bit audio\n - Reason: %s\n", SDL_GetError());
}
screen=SDL_SetVideoMode(SCREENWIDTH,SCREENHEIGHT,32,SDL_SWSURFACE|SDL_FULLSCREEN|SDL_HWPALETTE);
if ( screen == NULL )
{
printf("Unable to set 640x480 video: %s\n", SDL_GetError());
exit(1);
}
//load the music
music = Mix_LoadMUS("data/sound/(sblu)moon6.xm");
//play the music
if(!Mix_PlayingMusic())
{
// then start playing it.
Mix_PlayMusic(music, 0);
}
Swordsbase.init("data/testC/down");
sunbase.init("data/sun");
sun.init(&sunbase,screen);
sun.set(480,50);
sun.setSpeed(1);
Swords.init(&Swordsbase,screen);
Swords.set(150,300);
Swords.setSpeed(2);
SDL_ShowCursor(0);
font = initFont("data/font");
InitImages();
//DrawBG(back);
while (game_state!=GAME_EXIT)
{
SDL_Event event;
while ( SDL_PollEvent(&event) )
{
if ( event.type == SDL_QUIT )
{ game_state=GAME_EXIT;}
if ( event.type == SDL_KEYDOWN )
{
if ( event.key.keysym.sym == SDLK_ESCAPE ) { game_state=GAME_EXIT; }
}
}
keys = SDL_GetKeyState(NULL);
if ( keys[SDLK_UP] ) { Swords.yadd(-1); }
if ( keys[SDLK_DOWN] ) { Swords.yadd(1); }
if ( keys[SDLK_LEFT] ) { Swords.xadd(-1); }
if ( keys[SDLK_RIGHT] ) { Swords.xadd(1); }
if ( keys[SDLK_s] )
{
if(game_state!=GAME_RUN||game_state!=GAME_STARTING)
{
SDL_FillRect(screen,0,0);
sun.clearBG();
Swords.clearBG();
game_state = GAME_STARTING;
}
//SDL_FillRect(screen,0,0);
//DrawIMG(image, 0, 0);
//SDL_Flip(screen);
}
if(game_state == GAME_INIT)
DrawBG(back);
if(game_state == GAME_STARTING)
{
SDL_FillRect(screen, NULL, 0);
DrawBG(image);
//SDL_Flip(screen);
//game_state++;
}
DrawScene();
}
return 0;
}

