Allegro Game library

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Firecore
    New Member
    • Jul 2007
    • 114

    Allegro Game library

    Anyone here familiar with the allegro game library?

    I have some code that does not work:

    Code:
    //This is a small test for allegro
    
    #include <allegro.h>
    
    #define WHITE makecol(255, 255, 255)
    BITMAP *img;
    char filename[50] = "D:\\clown.bmp";
    int x, y;
    char buffer[255];
    
    int main()
    {
    	allegro_init();
    	install_keyboard();
    	install_mouse();
    	set_gfx_mode(GFX_AUTODETECT_FULLSCREEN, 800, 600, 0, 0);
    	textout_ex(screen, font, "This is a test", 0, 0, WHITE, 0);
    	
    	uszprintf(buffer, sizeof(buffer), "Resolution is = %dx%d", SCREEN_W, SCREEN_H);
    
    	//load the sprite
    	img = load_bitmap(filename, NULL);
    
    
    //	set_mouse_sprite(img);
    //	show_mouse(img);
    //
    	textout_ex(screen, font, buffer, 0, 24, WHITE, 0); 
    	
    	//declare pos of sprite
    	x = SCREEN_W / 2 - 1;
    	y = SCREEN_H / 2 - 1;
    
    
    
    
    	//main loop
    	while(!key[KEY_ESC])
    	{
    		draw_sprite(screen, img, x, y);//note that the x and y as pos
    
    		//check for arrow key
    		if(key[KEY_D])
    		{
    			if(x > SCREEN_W)
    			{
    				x = SCREEN_W - 1;
    				
    				uszprintf(buffer, sizeof(buffer), "The x = %d, and the y = %d", x, y);
    
    				textout_ex(screen, font, buffer, 200, 157, WHITE, 0);
    				textout_ex(screen, font, "Tried 2 leave window", 200, 150, WHITE, 0);
    			}
    
    			x = x + 1;
    		}
    	}
    	
    	destroy_bitmap(img);
    	
    	allegro_exit();
    
    	return 0;
    }
    END_OF_MAIN()
    Basically, what im trying to do here is to have a 32 x 32 bitmap and put it on the screen and move it when the user presses the 'D' button.
  • Firecore
    New Member
    • Jul 2007
    • 114

    #2
    anyone?
    I really need 2 finish my game

    Comment

    • Savage
      Recognized Expert Top Contributor
      • Feb 2007
      • 1759

      #3
      Originally posted by Firecore
      anyone?
      I really need 2 finish my game
      I'm not familiar, but can you tell me what the problem is?Perhaps we will be able to figure it out.

      Is the problem that it doesn't move the image?

      Savage

      Comment

      • Studlyami
        Recognized Expert Contributor
        • Sep 2007
        • 464

        #4
        Yeah its a great library, but I havn't used it in a while. I'm not seeing any obvious errors. What problems are you having? All my allegro code is at home so i can't compare it when do you need this done by?

        Comment

        • Firecore
          New Member
          • Jul 2007
          • 114

          #5
          Originally posted by Studlyami
          Yeah its a great library, but I havn't used it in a while. I'm not seeing any obvious errors. What problems are you having? All my allegro code is at home so i can't compare it when do you need this done by?
          What happens is that when I press 'D', instead of going only 1 pixel to the right, it goes straight off the screen at an x of 791 or something like that.

          Comment

          • Firecore
            New Member
            • Jul 2007
            • 114

            #6
            Also, when I press d, it makes a trail of the image.

            Comment

            • Studlyami
              Recognized Expert Contributor
              • Sep 2007
              • 464

              #7
              The trail is because you never erased the old image. You could just put a black square over it, but i remember there being a function that erases the bitmap. Ill have to check that when i get home tonight. After you capture the 'D' you need to put something up that delays the reading of the key press.

              After you fix those minor problems the bitmap is going to flicker, you will need to look up double buffering or again i can give you small code sample after i get home from work.

              Another suggestion that i should make is


              if(x > SCREEN_W)
              x = SCREEN_W - 1;

              i would change to see if you can move X if so move it if not do nothing

              if ((X + bitmap_width)<S CREEN_W)
              x++; //move X position
              else
              //do nothing

              Comment

              • Firecore
                New Member
                • Jul 2007
                • 114

                #8
                i see.
                When u find out, can u tell me what the function is to erase the sprite?

                Comment

                • Studlyami
                  Recognized Expert Contributor
                  • Sep 2007
                  • 464

                  #9
                  Yeah ill put it up after i get home from work.

                  Comment

                  • Studlyami
                    Recognized Expert Contributor
                    • Sep 2007
                    • 464

                    #10
                    I was wrong there isn't an erase sprite function for the screen. The easy way (for what you are trying to do) is to just erase the bitmap by using the rect fill function. then redrawing the bitmap using the new location. Later when you learn double buffering and using background images you will see how to keep your background.

                    Comment

                    • Firecore
                      New Member
                      • Jul 2007
                      • 114

                      #11
                      Originally posted by Studlyami
                      I was wrong there isn't an erase sprite function for the screen. The easy way (for what you are trying to do) is to just erase the bitmap by using the rect fill function. then redrawing the bitmap using the new location. Later when you learn double buffering and using background images you will see how to keep your background.
                      I see. I just found a book on Allegro actually.
                      It took a bit of searching.
                      Its really good. The name is Game Programming all in one, third edition by Jonathan S. Harbour.

                      The next chapter after the one I am reading is all about double buffering.

                      Comment

                      Working...