Thread: Help with Allegro

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209

    Help with Allegro

    I'm using this Allegro tutorial, but it's becoming over simplified as it touches on more advanced topics. At the point where I am, the tutorial is trying to explain how to do animations using buffering or page flipping or whatever, and is trying to combine it with the timer stuff they didn't really explain well in the last lesson. I have lots of questions on the code that the tutorial produces, so here is the code:

    Code:
    #include <allegro.h>
    
    //long speed_counter = 0;
    
    //void increment_speed_counter()
    //{
        //speed_counter++;
    //} END_OF_FUNCTION(increment_speed_counter);
    
    int main(int argc, char* argv[])
    {
        allegro_init();
        install_keyboard();
        //install_timer();
        
        //LOCK_VARIABLE(speed_counter);
        //LOCK_FUNCTION(increment_speed_counter);
        //install_int_ex(increment_speed_counter, BPS_TO_TIMER(350));
        
        set_color_depth(16);
        set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0);
        
        BITMAP* frame_one = load_bitmap("C:\\Documents and Settings\\Owner\\My Documents\\John's Pictures\\Su-27A.bmp", NULL);
        BITMAP* frame_two = load_bitmap("C:\\Documents and Settings\\Owner\\My Documents\\John's Pictures\\Su-27B.bmp", NULL);
        BITMAP* frame_three = load_bitmap("C:\\Documents and Settings\\Owner\\My Documents\\John's Pictures\\Su-27C.bmp", NULL);
        
        BITMAP* buffer;
        buffer = create_bitmap(640, 480);
        
        int my_pic_x = 0;
        int my_pic_y = 0;
        int frame_counter = 0;
        
        while(!key[KEY_ESC])
        {
            //while(speed_counter > 0)
            //{
                if(key[KEY_RIGHT])
                {
                    my_pic_x++;
                }
                else if(key[KEY_LEFT])
                {
                    my_pic_x--;
                }
                else if(key[KEY_UP])
                {
                    my_pic_y--;
                }
                else if(key[KEY_DOWN])
                {
                    my_pic_y++;
                }
                //speed_counter--;
                frame_counter++;
                
                if(frame_counter > 240)
                {
                    frame_counter = 0;
                }
            //}
            
            if(frame_counter < 60)
            {
                draw_sprite(buffer, frame_one, my_pic_x, my_pic_y);
            }
            else if(frame_counter >= 60 && frame_counter < 120)
            {
                draw_sprite(buffer, frame_two, my_pic_x, my_pic_y);
            }
            else
            {
                draw_sprite(buffer, frame_three, my_pic_x, my_pic_y);
            }
            
            blit(buffer, screen, 0, 0, 0, 0, 640, 480);
            clear_bitmap(buffer);
            release_screen();
        }
        
        destroy_bitmap(frame_one);
        destroy_bitmap(frame_two);
        destroy_bitmap(frame_three);
        destroy_bitmap(buffer);
        
        return 0;
    } END_OF_MAIN()
    Okay, the first, and most important question involves the stuff highlighted in blue (and commented out). The program seems to run the same with or without this stuff dealing with timers. Due to the lack of detail in the previous tutorial which covers this stuff, I'm kind of lost as to what exactly the purpose of the commented out code is. However, from what I understand, the variable speed_counter is being incremented the entire program. If this is true, how is it possible that it can ever be decremented and therefore be lower than 0 for the test condition of that commented out while loop? If someone could elaborate about what good this code does for the program and what its exact function is, that would be great. All of that is dealing with the commented out code.

    Next question. The part of the blue highlighted code that is also bolded has me confused as well. I don't understand how the name of a function can be passed to a function. However, I'm thinking that this is a function pointer because I read somewhere that the name of a function represents its address. Is this correct? Also, I removed that piece of code (END_OF_FUNCTION(); ) and it had no effect on the program (of course I did this when the rest was uncommented). Why is this? This happens 2 other times in the code in two other commented out sections.

    Another thing that is bugging me is what would type BITMAP signify if it wasn't declared as a pointer? The tutorial said that type BITMAP is a pointer so why does it require the * in the declaration?

    Note the red highlighted 'things'. I understand that these represent key presses, but what are they? Arrays? Structures? Their syntax has got me stumped.

    The rest of the program I pretty much understand if you leave the commented parts out. Muchas gracias to anyone who can help. I really appreciate it.
    Last edited by homeyg; 03-31-2005 at 09:15 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Allegro in C for a newb
    By Ideius in forum C Programming
    Replies: 5
    Last Post: 12-29-2005, 04:36 PM
  2. Game Programming FAQ
    By TechWins in forum Game Programming
    Replies: 5
    Last Post: 09-29-2004, 02:00 AM
  3. double buffering for allegro
    By Leeman_s in forum C++ Programming
    Replies: 6
    Last Post: 09-12-2002, 02:45 PM
  4. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM
  5. Allegro programming in a window
    By Person Man in forum Windows Programming
    Replies: 0
    Last Post: 11-16-2001, 03:23 PM