Allegro help-o

This is a discussion on Allegro help-o within the Game Programming forums, part of the General Programming Boards category; I plan on using this thread to recieve help for many different problems in allegro. I will ask 1 by ...

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

    Talking Allegro help-o

    I plan on using this thread to recieve help for many different problems in allegro. I will ask 1 by 1.

    Prob Num 1:

    Can I get an example ( with comments) of a program that will take your Sprite.bmp and put it on screen?
    What is C++?

  2. #2
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Did that sprite code I sent you work?

  3. #3
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    look at your PM
    What is C++?

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Thanks Josh for helpin me there.

    Now

    Num 2:

    Code:
    #include <allegro.h>
    
    int x = 300, quit = 0;
    
    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 );
    
    
       while ( !quit )
       {
           if ( keypressed() ){
             if ( key[KEY_LEFT] ) x--;
             else if ( key[KEY_ESC] ) quit = 1;
           }
           draw_sprite ( screen, ship, x, 400 );
       }
    
    
       destroy_bitmap(ship);
       allegro_exit();
       return 0;
    }
    END_OF_MAIN();
    How can I make the ship move, and not leave a trail?
    Also why does it move so freakin fast?
    Last edited by Vicious; 06-05-2002 at 10:12 PM.
    What is C++?

  5. #5
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    You have to use dirty rectangles (i think) or clear the screen. Clearing the screen would be slow, and cause alot of flicker. I will try to code an example of how to move a sprite with no flicker in a little bit.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    i know almost nothing about allegro, but from expereince in other apis, your ship is leaving a trail because youre not erasing it. you can expecet the stupid box in front of you to know when to clear something.

  7. #7
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    I might be able ( with josh's help ) to find a function for this.

    But my problem is if i barely tap LEFT it flys of the flippin' screen!

    Here is what I think is happening:

    It detects the LEFT key and makes x++, but when it loops back, it continues to x++.
    What is C++?

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    either that, or youre not checking the key every time you loop. try printing to a file or something what you get as input on every loop. also, arent there delay functions in allegro(for slowing down the movement of the ship)?

  9. #9
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    After you get the input and change the coordinates, try something simple like for(int j = 0; j < 400; j++) ;

  10. #10
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    nope, makes no difference what so ever
    What is C++?

  11. #11
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    I was looking in the Allegro docs and found this:

    void set_keyboard_rate(int delay, int repeat);

    Try setting it before your loop. Set is after install_keyboard();.

    Mess around with the parameters till it works right.

  12. #12
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    i was 1 or 2 steps ahead of you. I tried

    set_keyboard_rate(0, 0)

    that is supposed to disable it but it didnt work

    im gonna try 1, 1 now

    edit: nope
    What is C++?

  13. #13
    Registered User JoshG's Avatar
    Join Date
    Mar 2002
    Posts
    326
    Hmm, I do not know, but this may fix it, after you change the coordinates and redraw the sprite put clear_keybuf();

  14. #14
    Registered User
    Join Date
    Feb 2002
    Posts
    26
    i just finished a game in allegro and this i what i did to conrol game speed. you update the screen and keyboard input every loop, but you only change the objects position after so much time. heres an ex.

    Code:
    #include <time.h>
    
    clock_t time1,time2;
    
    int main()
    time1 = clock();
    	while (key[KEY_ESC==0])) 
    	{
    		clear(screen);
    		keyboard_input
    		update_screen
    
    		time2 = clock();
    		if (time2-time1>100) //makes this # bigger to slow down
    		{
                                           move object
                                           time1 = clock();
    		}	  
    	}
    	return;

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

    And i really didnt want to go this route...

    I dont want flicker in my game

    What is C++?

Page 1 of 8 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