Thread: allegro game problem

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    allegro game problem

    this code has driven me crazy
    most of it i have found at a tutorial site.
    its a spaceshooter game (yes the same as before)
    my problem is that i want the ship to "shoot" a laser beam
    when u press a certain key i almost solved that problem once
    but then it shot one beam then the game crashed
    but then i forgot even that

    btw it is an allegro game



    Code:
     
    
    
    
    
    #include <allegro.h> // You must include the Allegro Header file 
    
    
    
    int main(int argc, char *argv[]) 
    { 
    
    
    
    allegro_init(); // Initialize Allegro 
    install_keyboard(); // Initialize keyboard routines 
    
    
    
    set_color_depth(16); // Set the color depth 
    
    set_gfx_mode(GFX_AUTODETECT,640,480,0,0); //Change our graphics mode to 640x480 
    BITMAP*bild; 
    bild=load_bitmap("c:\\temp\\ship.bmp",0); 
    
    BITMAP *my_pic; //Declare a BITMAP called my_pic 
    my_pic = load_bitmap("c:\\temp\\rocket.bmp", NULL); // Load our picture 
    
    BITMAP *buffer; //Declare a BITMAP called buffer. 
    
    buffer = create_bitmap(640,480); //Create an empty bitmap. 
    
    while(!key[KEY_ESC])//If the user hits escape, quit the program 
    { 
    
    
    if(key[KEY_RIGHT])// If the user hits the right key, change the picture's X coordinate 
    { 
    my_pic_x ++;// Moving right so up the X coordinate by 1 
    } 
    if(key[KEY_LEFT])// Ditto' - only for left key 
    { 
    my_pic_x --;// Moving left, so lower the X coordinate by 1 
    } 
    if(key[KEY_UP])// If the user hits the up key, change the picture's Y coordinate 
    { for(int w=500;w>0 
    { 
    
    
    
    putpixel(buffer,my_pic_x,w+10,0); 
    putpixel(buffer,my_pic_x,w--,500); 
    
    } 
    if(key[KEY_DOWN])// Ditto' - only for down 
    { 
    my_pic_y ++;// Moving down, so up the Y coordinate by 1 
    } 
    
    
    acquire_screen();// Get the screen 
    draw_sprite(buffer, bild, my_pic_x, my_pic_y);//Draw the picture to the buffer 
    blit(buffer, screen, 0,0,0,0,640,480);//Draw the buffer to the screen 
    release_screen();// Release it 
    
    } 
    
    
    
    destroy_bitmap(bild);//Release the bitmap data 
    destroy_bitmap(buffer);//Release the bitmap data 
    
    
    return(0);// Exit with no errors 
    } 
    END_OF_MAIN();

  2. #2
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    What Allegro version are you using....and what was the tutorial using?

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    should not matter

  4. #4
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Actually, it does.....you can't compile a Visual C++ source into a C++ source, and you can't compile AT&T ASM code into a Intel ASM code.........it's like seeing air (during a warm day)

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    visual c++ IS c++
    i'm using dev for the moment and u can see all the headers i'm using

    so can u quit posting them b.s posts!

  6. #6
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Code:
    set_color_depth(16);
    Change this to
    Code:
    set_color_depth(256);
    if allowed.
    Code:
    buffer = create_bitmap(640,480);
    Set this to a smaller (or bigger) image size maybe.

  7. #7
    Unregistered
    Guest

    Re: allegro game problem

    Originally posted by pode


    { for(int w=500;w>0
    {



    putpixel(buffer,my_pic_x,w+10,0);
    putpixel(buffer,my_pic_x,w--,500);

    }
    if(key[KEY_DOWN])// Ditto' - only for down
    {
    my_pic_y ++;// Moving down, so up the Y coordinate by 1
    }


    acquire_screen();// Get the screen
    draw_sprite(buffer, bild, my_pic_x, my_pic_y);//Draw the picture to the buffer
    blit(buffer, screen, 0,0,0,0,640,480);//Draw the buffer to the screen
    release_screen();// Release it

    }

    [/code]
    did you mean to have all of this between the If (key[up]) braces or is my browser just seeing it that way, also if you code is as messy as it look in the post then try cleaning it and you will be able to tell whats wrong easier

  8. #8
    Registered User
    Join Date
    Apr 2002
    Posts
    129
    quantrizi, you dont appear to know how to use allegro so just shut up. pode, can you clean up your code a bit, it looks like ****. I dont know why its crashing but you must realize that you wont ever see the lazer beam, it goes through the enter loop drawing and erasing from a buffer but never drawing it to the actuall screen, when it does draw to the screen its already gone.
    flashdaddee.com rocks!!!

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    really, can u tell me the right way to draw?

  10. #10
    Pygmy Monkey ErionD's Avatar
    Join Date
    Feb 2002
    Posts
    408
    Code:
    { for(int w=500;w>0
    Shouldnt this be

    Code:
    { for(int w=500;w>0)

  11. #11
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    yes i had that included to but sometimes ) becomes a smiley
    and sometimes it dont show on this board!

  12. #12
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    Originally posted by muttski
    quantrizi, you dont appear to know how to use allegro so just shut up.
    Yes, your right.........and I ain't gotta shut up......how 'bout u take ur own advice

  13. #13
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    How about you take his advice? If you don't have something to add to a topic stay out of it. (5.27 posts per day), and most of them were as useful as your previous one.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. beach bar (sims type game)
    By DrKillPatient in forum Game Programming
    Replies: 1
    Last Post: 03-06-2006, 01:32 PM
  2. PC Game project requires c++ programmers
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 02-22-2006, 12:23 AM
  3. Game Engine Link Prob
    By swgh in forum Game Programming
    Replies: 2
    Last Post: 01-26-2006, 12:14 AM
  4. Allegro Game Programming
    By Robert_Ingleby in forum C Programming
    Replies: 3
    Last Post: 03-01-2002, 03:45 PM
  5. Random Number problem in number guessing game...
    By -leech- in forum Windows Programming
    Replies: 8
    Last Post: 01-15-2002, 05:00 PM