Thread: allegro spaceshooter prm!

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

    allegro spaceshooter prm!

    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])
    {
    my_pic_x --;
    }
    if(key[KEY_UP]) //here is the problem
    {


    for( int w=0;w<50;w--)
    {



    putpixel(buffer,my_pic_x+10,my_pic_y+10,0);
    putpixel(buffer,my_pic_x+10,my_pic_y--,50);

    showBuffer ();


    } }

    if(key[KEY_DOWN])// Ditto' - only for down
    {
    my_pic_y ++;// Moving down, so
    }
    /*

    my problem is this, when the user hits key UP there is suposed
    to be a blue beam coming from the "ship"
    that also happens BUT just once and then the program hookes up
    */

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    for(int w=0;w<50;w--)

    w is always less than 50, thus it is an infinite loop. (Actually, it would eventually overflow the integer and thus become greater than 50, but with screen refresh times, that could take several hours, so it's as good as locked up.)

    Perhaps:

    for(int w=0;w>-50;w--)

    would give you the effect you desire.

    Sounds like it is all coming along. Is it like Galaga?
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    thanks justin u've been very helpful
    but it wont work either
    i think u are right about the code but i think the problem is
    the key function because it seems like it only reeds the key hit once
    i think allegro has a nother function that can prevents this

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    OK, what exactly do is happening now? Or, rather, what do you want to happen? Does left and right still work the way you want it to? But not up and down? If so, then there must be a difference between the up and down vs left and right code that is producing the undesirable effect. What does showBuffer() look like?
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  5. #5
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    here is tge code


    *************************************

    #include <allegro.h>



    int main(int argc, char *argv[])
    {



    allegro_init();
    install_keyboard();



    set_color_depth(16);

    set_gfx_mode(GFX_AUTODETECT, 640,480,0,0);


    BITMAP *my_pic;
    my_pic = load_bitmap("c:\\g\\skepp.bmp", NULL);

    BITMAP *buffer;


    buffer = create_bitmap(640,480);
    void showBuffer ();
    {

    blit (buffer, screen, 0, 0, 0, 0, 640, 480);
    }


    while(!key[KEY_ESC])
    {

    if(key[KEY_RIGHT])
    {
    my_pic_x ++;
    }
    else if(key[KEY_LEFT])
    {
    my_pic_x --;
    }
    else if(key[KEY_UP])
    {
    for(int w=500;w>0;w)
    {

    putpixel(buffer,100,w+10,0);
    putpixel(buffer,100,w--,500);
    void showBuffer ();

    }



    }
    else if(key[KEY_DOWN])
    {
    my_pic_y ++;
    }


    acquire_screen();// Get the screen
    draw_sprite(buffer, my_pic, 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(my_pic);//Release the bitmap data
    destroy_bitmap(buffer);//Release the bitmap data


    return(0);// Exit with no errors
    }
    END_OF_MAIN();

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    OK, I see what's going on.

    The biggest problem is this:
    void showBuffer ();
    {

    blit (buffer, screen, 0, 0, 0, 0, 640, 480);
    }

    Does not declare a function because of the semicolon after the parenthasis. Remove it in order to define the function. You didn't get an error because this was defined within main(). Once you fix it, the compiler will complain, so move it up above main(). For simplicity's sake you might consider moving your variables (like buffer) above it even further.

    Once that is taken care of, you'll see a blue bullet go flying. However, it isn't lined up quite right... but that can be a later topic if you need help with it.
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    - i must have posted the wrong code
    i have written several codes for this sorry
    ****************************************
    Once that is taken care of, you'll see a blue bullet go flying. However, it isn't lined up quite right... but that can be a later topic if you need help with it.

    - i know but it will shoot once then it stops

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    i know but it will shoot once then it stops
    It sticks to the top of the screen (though you may continue shooting more if you like). Is that what you are trying to get rid of? There are two ways to do this. 1) Send the bullet flying past the edge of the screen. In this case, you need to stop the loop after your y value is sufficiently negative. 2) Remove the garbage. You are left with a piece of bullet there because although the tail is removed, the bullet itself never is. Directly after the loop, erase the whole projectile.

    One more note: Instead of having everything else pause while it travels across the screen, try incorporating the bullet loop with the full game loop so that the action continues (perhaps with the ability to shoot several bullets in a row, eventually).

    -Justin
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  9. #9
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    sorry justin that i didn't ask this earlier but how do yo mean

    ////
    Instead of having everything else pause while it travels across the screen, try incorporating the bullet loop with the full game loop so that the action continues (perhaps with the ability to shoot several bullets in a row, eventually).
    ////

  10. #10
    Bobish
    Guest
    Unless I'm just not following what your doing why do you have the buffer shown on every pass of the for loop instead of just once you are done drawing the shot. If you want the player to see the shot forming then you should do the fifty steps once per main loop and just do the drawing at the end of it.

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