Well, actuallt i learn better from first testing, then reading. It's a fact.
I played around with your link but didn't get it to work. You can see my whole main-function here:
Code:
int main( int argc, char* args[] )
{
//The pieces coordinates
int x = 200;
int y = 200;
//Left flag
bool left = false;
//Right flag
bool right = false;
//Quit flag
bool quit = false;
//Initialize
if( init() == false )
{
return 1;
}
//Load the files
if( load_files() == false )
{
return 1;
}
//Apply the background
apply_surface( 0, 0, background, screen );
//Apply the piece
apply_surface( 70, 178, piece, screen );
//While the user hasn't quit
while( quit == false )
{
//If there's an event to handle
while (SDL_PollEvent(&event))
{
if (event.type == SDL_KEYDOWN)
{
switch(event.key.keysym.sym)
{
case SDLK_LEFT:
left = true;
break;
case SDLK_RIGHT:
right = true;
break;
case SDLK_ESCAPE:
quit = true;
break;
} }
if (event.type == SDL_KEYUP)
{
switch(event.key.keysym.sym)
{
case SDLK_LEFT:
left = false;
break;
case SDLK_RIGHT:
right = false;
break;
}
}
//Check if the right is pressed
while (right == true)
{
x = x + 10;
SDL_FillRect( screen, NULL, NULL );
apply_surface( 0, 0, background, screen );
piece = load_image( "piece-right.png" );
apply_surface( x, y, piece, screen );
}
//Check if the left is pressed
while (left == true)
{
x = x - 10;
SDL_FillRect( screen, NULL, NULL );
apply_surface( 0, 0, background, screen );
piece = load_image( "piece-left.png" );
apply_surface( x, y, piece, screen );
}
}
//If the user has Xed out the window
if( event.type == SDL_QUIT )
{
//Quit the program
quit = true;
}
//Update the screen
if( SDL_Flip( screen ) == -1 )
{
return 1;
}
}
//Clean up
clean_up();
return 0;
}