Allegro help-o

This is a discussion on Allegro help-o within the Game Programming forums, part of the General Programming Boards category; Does anybody know of any methods of quickly displaying two bitmaps at one time. I know that technically it's not ...

  1. #46
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Does anybody know of any methods of quickly displaying two bitmaps at one time. I know that technically it's not possible but... Such as if you were in a plane and you were firing at something so bullets appear as if are being shot of the plane. But what if you want to quickly shoot twice. I can't seem to find a way that is able to display all of the bullets flying at once. I have an algorithm that is able to do it okay at best, but it's not good enough.

    Here is what I'm doing:

    //display the beginning animation of the bullets coming out of the plane

    //continue to display the bullets until it reaches a certain point

    //if a certain variable is triggered then display animation 3

    //if a certain variable is triggered then display animation 2

    //if the shoot key (space bar) is pressed during the display of shooting bullets then animation 1 is triggered...animation 1 can not be triggered if variable 2 or 3 are triggered...hence this means that it can only display 2 bullet display at once (Sorry it's hard to explain)

    //animation 1 = the beginning display of the bullets for the 2nd shooting

    //animation 2 = the repetitive display of bullets being shot until the 2nd bullets reach the 1st bullets y coordinates

    //animation 3 = the repetitive display of bullets until the bullets reach a certain point

    //so the first round of bullets go off then once the second round go off the first round stop until the second round reach the height of the first round of bullets...once the first round of bullets reaches that certain point then the second round of bullets finish off reaching to that certain point

    that technique does not look pretty at all. would it best if i just created bitmaps that would represent all of these situations? but that would mean i would have to create a ton of bitmaps. should i create more animations to where it doesn't appear as if much lag is happening when the bullet movements are switching back and forth. is their a better way that i'm not aware of? i don't think there are multithreading capabilities in allegro are there? any ideas anybody?

    sorry, vicious, for kind of stealing your thread and your ideas...well somewhat.

    EDIT: Thanks Josh for the info. And, Vicious, it doesn't look good at all when I do it...not sure why?

    EDIT 2: Would page flipping be something that could help resolve that problem?
    Last edited by TechWins; 06-08-2002 at 02:44 AM.

  2. #47
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    page flipping makes an extremely wierd effect when I try it....

    anyway, i made some baddys and made them bounce side to side... now for lasers

    Code:
    #include <allegro.h>
    
    
    int counter;
    int x = 300, y = 425, left = 0, right = 0, go = 0, fire = 0;
    int bx = 100, cx = 150, dx = 200, ex = 250, fx = 300, gx = 350, hx = 400, ix = 450, jx = 500;
    
    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 *baddy = load_bitmap( "Baddy.bmp", NULL );
       BITMAP *baddy2 = load_bitmap( "Baddy.bmp", NULL );
       BITMAP *baddy3 = load_bitmap( "Baddy.bmp", NULL );
       BITMAP *baddy4 = load_bitmap( "Baddy.bmp", NULL );
       BITMAP *baddy5 = load_bitmap( "Baddy.bmp", NULL );
       BITMAP *baddy6 = load_bitmap( "Baddy.bmp", NULL );
       BITMAP *baddy7 = load_bitmap( "Baddy.bmp", NULL );
       BITMAP *baddy8 = load_bitmap( "Baddy.bmp", NULL );
       BITMAP *baddy9 = load_bitmap( "Baddy.bmp", NULL );
       BITMAP *laser = load_bitmap( "laser.bmp", NULL );
       BITMAP *buffer = create_bitmap( 640, 480 );
    
       while ( !key[KEY_ESC] ) 
       { 
            while (counter > 0) { 
               if (left)  x-=10;
               if (right) x+=10;
               counter--; 
            } 
            if ( x < 600 && key[KEY_RIGHT])
                right = 1; 
            else 
                right = 0; 
            if ( x > 0 && key[KEY_LEFT])
                left = 1; 
            else 
                left = 0;
    
            clear_bitmap( buffer);
            draw_sprite ( buffer, ship, x, 425 );
            draw_sprite ( buffer, baddy, bx, 20 );
            draw_sprite ( buffer, baddy2, cx, 20 );
            draw_sprite ( buffer, baddy3, dx, 20 );
            draw_sprite ( buffer, baddy4, ex, 20 );
            draw_sprite ( buffer, baddy5, fx, 20 );
            draw_sprite ( buffer, baddy6, gx, 20 );
            draw_sprite ( buffer, baddy7, hx, 20 );
            draw_sprite ( buffer, baddy8, ix, 20 );
            draw_sprite ( buffer, baddy9, jx, 20 );
            vsync();
            blit( buffer, screen, 0, 0, 0, 0, 640, 480);
    
                  if ( bx > 10 && go == 0){
    
                     bx--;
                     cx--;
                     dx--;
                     ex--;
                     fx--;
                     gx--;
                     hx--;
                     ix--;
                     jx--;
    
                  }
    
                  else if ( jx <  600 ){
                     go = 1;
                     bx++;
                     cx++;
                     dx++;
                     ex++;
                     fx++;
                     gx++;
                     hx++;
                     ix++;
                     jx++;
                  }
    
                  else if ( jx = 600 ){
                       go = 0;
                  }
    
    
       } 
    
    
    
    
    
       destroy_bitmap(buffer);
       destroy_bitmap(ship);
       destroy_bitmap(baddy);
       destroy_bitmap(baddy2);
       destroy_bitmap(baddy3);
       destroy_bitmap(baddy4);
       destroy_bitmap(baddy5);
       destroy_bitmap(baddy6);
       destroy_bitmap(baddy7);
       destroy_bitmap(baddy8);
       destroy_bitmap(baddy9);
       destroy_bitmap(laser);
       allegro_exit();
       return 0;
    }
    END_OF_MAIN();
    i know there is a better way to do it than loading seperate bitmaps.... it was just the only way I knew how

    edit: this code is flicker free :P
    Last edited by Vicious; 06-08-2002 at 02:05 PM.
    What is C++?

  3. #48
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    oh... i know that code is really messy but im just getting the basic ideas down before i separate everything...

    and besides i have only been programming for a few months so dont expect a miracle from me
    What is C++?

  4. #49
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    What is the weird effect?

  5. #50
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    My code will compile, but it gives an illegal operation, any idea why? Here is the code:

    Code:
    #include <allegro.h>
    
      void setup();
      void shutdown();
    
      BITMAP *background = load_bitmap("background.bmp", NULL);
      BITMAP *plane      = load_bitmap("plane.bmp", NULL);
    
    int main()
    {
      setup();
    
      blit(background, screen, 0, 0, 0, 0, 640, 480);
      draw_sprite(screen, plane, 150, 150);
    
      while(!key[KEY_ESC])
        ;
    
      shutdown();
      return 0;
    }
    END_OF_MAIN();
    
    void setup()
    {
      allegro_init();
      install_keyboard();
    
      set_color_depth(32);
      set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
    }
    
    void shutdown()
    {
      destroy_bitmap(background);
      destroy_bitmap(plane);
    
      allegro_exit();
    }

  6. #51
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    I commented out all the lines having to do with background and plane, and it worked. So it is something wrong with them...

    [edit]
    Sorry for three post in a row. If I comment out all the lines, except the two that load plane.bmp and background.bmp I still get an illegal operation. Background.bmp is 640x480, maybe it is too big...
    [/edit]

    [edit]
    Any time I try to do anything with creating or loading a bitmap I get an error. Even if I comment out all the stuff with plane and background, if I just use create_bitmap() I get an illegal operation. Maybe it is because I have allegro_init() in setup() instead of main()??
    [/edit]

    [edit]
    Ignore all that, I got it working. I was calling a function outside of main. Some people at allegro.cc helped me, that is a nice site.
    [/edit]
    Last edited by JoshG; 06-08-2002 at 03:46 PM.

  7. #52
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Well, I'm probably going to make a couple posts in a row so I can give you a quick comment Josh.

    do this instead:

    Code:
      BITMAP *background;
      BITMAP *plane;
    
    int main()
     {
       background = load_bitmap("background.bmp", NULL);
       plane = load_bitmap("plane.bmp", NULL);
     }
    You have to load the bitmaps inside of a function. I had the same problem earlier so don't feel bad.

    Btw, here is a link to some good posts by JustinW:

    http://www.cprogramming.com/cboard/s...&threadid=7735


    EDIT: well, n/m. You edited your post while I was posting mine.

  8. #53
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    i know there is a better way to do it than loading seperate bitmaps.... it was just the only way I knew how
    You could make an array of "baddies".

    I want to know how you can load different bitmaps out of the same bitmap. Kind of like how the commercial games are done. Right now it's not all that important, though.

    Could somebody explain blit to me? I've read a ton of things on it, and I still don't understand it? I don't understand how to use it, I don't understand when to use it, and I don't understand why to use it.

  9. #54
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    blit means copy. You have a bitmap called screen. You load a bitmap called background or plane. How do you display background or plane? You copy it to the screen, or blit. Here is the function prototype:

    Code:
    void blit(BITMAP *source, BITMAP *dest, int source_x, int source_y, int dest_x, int dest_y, int width, int height);
    P.S. I just wrote a demo of moving a plane around in some clouds, it does not flicker, and I do not have to use a timer or any tricks to get the input working. PM me if you want me to post the source.

  10. #55
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    Thanks for the offer, but I already have source that can do that. So far my program can move a plane around, shoot bullets, while it's shooting bullets the plane can still move around, and if the plane shoots again the old bullets' animation is destroyed and the new one is created (I got rid of the fake animation sequence I was using to allow double shooting). Right now I'm trying to create a real animation sequence of multiple shootings.

    About blit: I know what the source_x and source_y are for, but what are the dests for?

    Does anybody else notice that when you push one of the arrow keys really hard sometimes the bitmap flies off of the screen, even though, you set restrictions against it from doing so?

    P.S. Actually, Josh, I will take you up on that offer. That way I can see if what I'm doing is a good method or not. If you want me to send you my source, too, I'll be happy to do so.

  11. #56
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    I will post the source in a minute, how can your game do all that, but you did not understand blit? The destinations are where on the bitmap you are copying it to it appears. That does not make too much sense, lets say you are copying bitmap1 to screen, the destinations are the coordinates that bitmap1 will appear on screen.

  12. #57
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    check your pms.

  13. #58
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    ahh.... when i try to compile this it says that SS.exe had a problem and brings up the send or not to send box.



    Code:
    #include <allegro.h>
    
    int counter;
    int left = 0, right = 0;
    BITMAP *buffer = create_bitmap( 640, 480 );
    
    class player
    {
       public:
           int x, y;
           BITMAP* ship;
    
           player(): x(300), y(425) { ship = load_bitmap ( "ship.bmp", NULL ); }
          ~player() { destroy_bitmap(ship); }
    
           void  getmove()
           {
               if ( x < 600 && key[KEY_LEFT] )
               {
                  left = 1;
               }
    
               else
               {
                  left = 0;
               }
    
               if ( x > 0 && key[KEY_RIGHT] )
               {
                  right = 1;
               }
    
               else
               {
                  right = 0;
               }
            }
    
            void draw(BITMAP* b)
            {
                draw_sprite ( b, ship, x, 425 );
            }
    };
    
    void update_counter()
    {
         counter++;
    }END_OF_FUNCTION(update_counter);
    
    int main()
    {
       allegro_init();
       install_keyboard();
       set_color_depth(32);
       set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 640, 480, 0, 0);
    
       LOCK_VARIABLE(counter);
       LOCK_FUNCTION(update_counter);
       install_int_ex( update_counter, BPS_TO_TIMER(60));
    
       player player1;
    
       do{
           while ( counter > 0 )
           {
               player1.getmove();
    
               if ( left = 1 ) player1.x -= 10;
               if ( right = 1 ) player1.x += 10;
    
               counter--;
           }
    
           clear(buffer);
           player1.draw(buffer);
    
       }
       while ( !key[KEY_ESC] );
    
       allegro_exit();
       return 0;
    }
    END_OF_MAIN();
    What is C++?

  14. #59
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Same problem I had, you put:

    BITMAP *buffer = create_bitmap( 640, 480 );

    You can not call the function create_bitmap from outside of main().

    Change it to BITMAP *buffer = NULL;

    Then somewhere in main() put buffer = create_bitmap(640, 48);

    I do mine in a setup() function

  15. #60
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    it will compile but it says the same error message when i run thje exe...
    Last edited by Vicious; 06-08-2002 at 07:26 PM.
    What is C++?

Page 4 of 8 FirstFirst 12345678 LastLast
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, 03:00 AM
  3. double buffering for allegro
    By Leeman_s in forum C++ Programming
    Replies: 6
    Last Post: 09-12-2002, 03:45 PM
  4. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-21-2002, 12:35 AM
  5. Allegro programming in a window
    By Person Man in forum Windows Programming
    Replies: 0
    Last Post: 11-16-2001, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21