I'm a newbie in programing
I've got this problem after I added timer on to the my program.
I can't figure out what goes wrong.
I just want to chekc if the timer can run or not.

#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#pragma comment(lib, "SDL_image.lib")

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>

//Screen attributes
const int SCREEN_WIDTH = 480;
const int SCREEN_HEIGHT = 640;
const int SCREEN_BPP = 32;

//The frames per second
const int FRAMES_PER_SECOND = 24;

//The dimenstions of the background
const int BG_WIDTH = 480;
const int BG_HEIGHT = 640;

//The length of moving area of Tony
//const int move_area_width = 423; /* 480-two block sides */

//The dimenstions of ppl
const int PPL_WIDTH = 86 ;
const int PPL_HEIGHT = 133;

//The dimenstions of Tony
const int TONY_WIDTH =  141;
const int TONY_HEIGHT = 140;

const int TONY_POS_X[3] = {28, 170, 310};
int curr_index = 0;
int tonyPosX = TONY_POS_X[curr_index];
int tonyPosY = 500;


//The surfaces
SDL_Surface *screen = NULL;
SDL_Surface *bg = NULL;
SDL_Surface *tony = NULL;
SDL_Surface *tonyClear = NULL;
//SDL_Surface *prettyGirl = NULL;
//SDK_Surface *uglyGirl = NULL;
//SDL_Surface *block = NULL;

//The event structure
SDL_Event event;

//The areas of the sprite sheet (2 frames only)
//SDL_Rect clips_hit[ 2 ];

class Tony
{
    private:
    //Its animation status
    int status;

    //The x coordinate
    int offset;

    public:
    //Initializes the variables
    Tony();

    //Handles input
    //void handle_events();

    //Shows the stick figure
    void show();    
};

Tony::Tony()
{
 //Initialize movement variables
    offset = 0;

    void handle_events();
}


//load image
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_RLEACCEL | SDL_SRCCOLORKEY, SDL_MapRGB( optimizedImage->format, 0, 0xFF, 0xFF ) );
        }
    }

    //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;    
    }

    //Set the window caption
    SDL_WM_SetCaption( "TonyGoGoGo", NULL );

    //If everything initialized fine
    return true;
}

bool load_files()
{
    //Load the image
    bg = load_image( "bg.png" );
    tony = IMG_Load( "tony.png" );
    tonyClear = IMG_Load( "tonyClear.png" );
    //prettyGirl = IMG_Load( "prettyGirl.png" );
    //uglyGirl = IMG_Load( "uglyGirl.png" );
    //block = IMG_Load( "block.png" );


    //If there was an error in loading the image
    if( (bg == NULL) || (tony == NULL) )
    {
        return false;    
    }

    //If everything loaded fine
    return true;    
}

void clean_up()
{
    //Free the image
    SDL_FreeSurface( bg );

    //Quit SDL
    SDL_Quit();    
}

int main(int argc, char* argv[])
{
    bool quit = false;

     if( init() == false )
    {
        return 1;    
    }

    Uint32 start = 0;
    Uint32 end;
    bool running = true;

    //Load the files
    if( load_files() == false )
    {
        return 1;    
    }

    apply_surface( 0, 0, bg, screen );

    //Update the screen
    if( SDL_Flip( screen ) == -1 )
    {
        return 1;    
    }

    do
    {
        start = SDL_GetTicks();

        //While the user hasn't quit
        while( quit == false )
        {
            //While there's an event to handle
            while( SDL_PollEvent( &event ) )
            {
                //If the user has Xed out the window
                if( event.type == SDL_QUIT )
                {
                    //Quit the program
                    quit = true;
                }
                else if (event.type == SDL_KEYDOWN)
                {
                    // Check individual key
                    SDLKey key = event.key.keysym.sym;

                    switch(key)
                    {
                    case SDLK_LEFT: 
                        apply_surface( 28, 500, tonyClear, screen);
                        curr_index = 0; 
                        apply_surface( TONY_POS_X[curr_index], tonyPosY, tony, screen );  
                        SDL_Flip( screen );
                        break;
                    case SDLK_DOWN: 
                        apply_surface( 28, 500, tonyClear, screen);
                        curr_index = 1; 
                        apply_surface( TONY_POS_X[curr_index], tonyPosY, tony, screen );
                        SDL_Flip( screen );
                        break;
                    case SDLK_RIGHT:
                        apply_surface( 28, 500, tonyClear, screen);
                        curr_index = 2; 
                        apply_surface( TONY_POS_X[curr_index], tonyPosY, tony, screen );
                        SDL_Flip( screen );
                        break;
                    default:
                        break;
                    }               
                }   
            }
        }
        end = SDL_GetTicks();
        if ( end == 6000)
        {
            quit = true;
        }
        //Free the surface and quit SDL
        clean_up();

        return 0;
    }
}
This article has been dead for over six months. Start a new discussion instead.