SDL in c++: never close program?

HI! I'm new in SDL, and I was starting to make easy game.
I have picture ozadje.bmp (blackbround), and picture urh.bmp (character), and picture urh2.bmp (charachter when fights). If you pres down, picture urh will go down, and so on. If you press space, then picture will fights.
But when I runs the program, blacground and character not mowing for 10 second, then program closed.
YES! THIS IS BECAUSE SDL_Delay( 10000 ); what must I write instead of this, that program will runing like I describet?

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  #include "SDL/SDL.h"
#include <string>
#include <iostream>
const int SCREEN_WIDTH = 800;
const int SCREEN_HEIGHT = 500;
const int SCREEN_BPP = 32;
SDL_Surface *message = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;
SDL_Surface *load_image( std::string filename ) 
{
    //Temporary storage for the image that's loaded
    SDL_Surface* loadedImage = NULL;
    
    //The optimized image that will be used
    SDL_Surface* optimizedImage = NULL;
    loadedImage = SDL_LoadBMP( filename.c_str() );
    //If nothing went wrong in loading the image
    if( loadedImage != NULL )
    {
        //Create an optimized image
        optimizedImage = SDL_DisplayFormat( loadedImage );
        
        //Free the old image
        SDL_FreeSurface( loadedImage );
    }
     //Return the optimized image
    return optimizedImage;
}
void apply_surface( int x, int y, SDL_Surface* source, SDL_Surface* destination )
{
    //Make a temporary rectangle to hold the offsets
    SDL_Rect offset;
    
    //Give the offsets to the rectangle
    offset.x = x;
    offset.y = y;
    SDL_BlitSurface( source, NULL, destination, &offset );
}
int main( int argc, char* args[] )
{
    //Initialize all SDL subsystems
    if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return 1;    
    }
     //Set up the screen
    screen = SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_SWSURFACE );
    if( screen == NULL )
    {
        return 1;    
    }
    int x (250);
    int y (250);
    SDL_Event event;
     SDL_WM_SetCaption( "NABIJ ZOKIJA! RAZBIJA ZOKIJA! PREBIJ ZOKIJA!", NULL );
     message = load_image( "urh.bmp" );
    background = load_image( "OZADJE.bmp" );
    apply_surface( 320, 0, background, screen );
    apply_surface( 0, 240, background, screen );
    apply_surface( 320, 240, background, screen );
    apply_surface( x, y, message, screen );
    if( SDL_Flip( screen ) == -1 )
    {
        return 1;    
    }
    SDL_Delay( 10000 );
    while( SDL_PollEvent( &event ) ){
        switch( event.type ){
            /* Look for a keypress */
            case SDL_KEYDOWN:
                /* Check the SDLKey values and move change the coords */
                switch( event.key.keysym.sym ){
                    case SDLK_LEFT:
                         x - 1;
                        break;
                    case SDLK_RIGHT:
                        x +  1;
                        break;
                    case SDLK_UP:
                        y - 1;
                        break;
                    case SDLK_DOWN:
                        y + 1;
                    case  SDLK_SPACE:
                          message = load_image( "urh2.bmp" );
                        break;
                    default:
                        break;
                }
            }
                         
    //Free the surfaces
    SDL_FreeSurface( message );
    SDL_FreeSurface( background );
    
    //Quit SDL
    SDL_Quit();
    
    //Return
    return 0;
}
}
Topic archived. No new replies allowed.