Thread: Allegro help-o

  1. #16
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    Vicious didn't u get the code i send u about doublebuffering?

    i got a problem i remember u have to include some file your
    project in order to make allegro work but now i have forgotten what that file is can someone please check that for me

    btw i use DEV-C++

  2. #17
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200

    odd..

    i tried this and it didt go as fast.... but i t flickers like crap

    Code:
    #include <allegro.h>
    
    int x = 300, i;
    
    int main()
    {
       allegro_init();
       install_keyboard();
    
    
       set_color_depth(32);
       set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
    
       BITMAP *ship = load_bitmap( "Ship.bmp", NULL );
       draw_sprite ( screen, ship, x, 400 );
    
    
       while ( !key[KEY_ESC] ){
    
             clear(screen);
             if ( x > 50 && key[KEY_LEFT]) x--;
             if ( x < 540 && key[KEY_RIGHT]) x++;
             draw_sprite ( screen, ship, x, 400 );
       }
    
    
    
    
       destroy_bitmap(ship);
       allegro_exit();
       return 0;
    }
    END_OF_MAIN();
    that clear(screen) func slowed it down....

    its still fast but not insane. Any ideas?

    Josh?

    What is C++?

  3. #18
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    I just decided to give Allegro a try, too, and holy crap is it easy. Not to mention that it is ummm hmmm awesome!

  4. #19
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Well if it is soo easy... what is wrongwith my program :P
    What is C++?

  5. #20
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Take out the clear screen function and it won't flicker anymore. In the loop it is continously clearing and redrawing the bmp to the screen. Take out the clear screen and then all it is doing is drawing the bmp to the screen so you can't see a difference.

  6. #21
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Well if it is soo easy... what is wrongwith my program
    Well, it's easy in the sense that all the functions are "english like". Basically I can understand all of the syntax without even really learning it yet. See what I mean?

    Btw, I wrote the taking out the clear screen function post before I saw your very last post.

  7. #22
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    i know....

    im working on a timer function right now...
    What is C++?

  8. #23
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Right now I'm using your code and having the mouse move the bmp. This is so much cooler than console programming. The docs for allegro are very useful, and make no need for tutorials (for the most part).

  9. #24
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    YAY, it works... now to make it clear it self....

    Code:
    #include <allegro.h>
    
    
    int counter;
    int x = 300, left = 0, right = 0;
    
    void update_counter()
    {
         counter++;
    }
    END_OF_FUNCTION(update_counter);
    
    int main()
    {
       allegro_init();
       install_keyboard();
    
       LOCK_VARIABLE(counter);
       LOCK_FUNCTION(update_counter);
       install_int_ex( update_counter, BPS_TO_TIMER(60));
    
       set_color_depth(32);
       set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
    
       BITMAP *ship = load_bitmap( "Ship.bmp", NULL );
    
    
       while ( !key[KEY_ESC] ) 
       { 
            while (counter > 0) { 
               if (left)  x-=5;
               if (right) x+=5;
               counter--; 
            } 
            if (key[KEY_RIGHT]) 
                right = 1; 
            else 
                right = 0; 
            if (key[KEY_LEFT]) 
                left = 1; 
            else 
                left = 0; 
            draw_sprite ( screen, ship, x, 300 ); 
       } 
    
    
    
    
    
    
       destroy_bitmap(ship);
       allegro_exit();
       return 0;
    }
    END_OF_MAIN();
    What is C++?

  10. #25
    Registered User red_baron's Avatar
    Join Date
    May 2002
    Posts
    274

    Thumbs up

    the way you guys are talking about this you're really making me wanna try it out, i'm gonna download it soon then i'll change my game so it runs with REAL graphics lol
    ¿Red Baron?

    "Imagination is more important than knowledge"
    -Albert Einstein (1879-1955)

    Check out my games!

    [code] /* dont forget code tags! */ [/code]

  11. #26
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I think ill have to use double-buffering or page flipping...

    any ideas?
    What is C++?

  12. #27
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    well....

    Code:
    #include <allegro.h>
    
    
    int counter;
    int x = 300, left = 0, right = 0;
    
    void update_counter()
    {
         counter++;
    }
    END_OF_FUNCTION(update_counter);
    
    int main()
    {
       allegro_init();
       install_keyboard();
    
       LOCK_VARIABLE(counter);
       LOCK_FUNCTION(update_counter);
       install_int_ex( update_counter, BPS_TO_TIMER(60));
    
       set_color_depth(32);
       set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
    
       BITMAP *ship = load_bitmap( "Ship.bmp", NULL );
       BITMAP *buffer = create_bitmap( 640, 480 );
    
    
       while ( !key[KEY_ESC] ) 
       { 
            while (counter > 0) { 
               if (left)  x-=5;
               if (right) x+=5;
               counter--; 
            } 
            if ( x < 540 && key[KEY_RIGHT])
                right = 1; 
            else 
                right = 0; 
            if ( x > 50 && key[KEY_LEFT])
                left = 1; 
            else 
                left = 0; 
    
            draw_sprite ( screen, ship, x, 400 );
            clear_bitmap( buffer);  // Clear the buffer 
            blit( buffer, ship, 0, 0, x, 400, ship->w, ship->h);  // Blit the ship to the buffer
            blit( buffer, screen, 0, 0, 0, 0, 640, 480);  // Blit the buffer to the screen
    
    
    
       } 
    
    
    
    
    
       destroy_bitmap(buffer);
       destroy_bitmap(ship);
       allegro_exit();
       return 0;
    }
    END_OF_MAIN();
    it works.... with some minor blinking that is...
    Last edited by Vicious; 06-06-2002 at 08:25 PM.
    What is C++?

  13. #28
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    I got an idea to get rid of that flicker. What kind of background are you going to use? If it is solid black, then create a bitmap the same size as your ship, make it solid black. Before you draw the coordinates of the new ship, draw the black bitmap at the coordinates of the old ship. That way it deletes the old one, without redrawing the whole screen (which makes it flicker).

  14. #29
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    i was gonna use a star field back ground but i might leave it black...
    What is C++?

  15. #30
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    know what....

    If someone wants to try this for me (im away from my computer right now).

    put vsync(); right b4 i blit the buffer to the screen....
    What is C++?

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