Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2014
    Location
    Pennsylvania
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Allegro Sprite Collison (Please Help!)

    I've been working on making a small game in C++, and I just do not understand sprite collision at all. I've looked up tutorials for days and I can not seem to find a single good tutorial. Can someone please explain sprite collision to me step by step? Here is the code so far.

    #include <allegro.h>
    #include <ctime>
    #include <cstdlib>


    volatile long timer = 0;

    void increment_timer()
    {
    timer++;
    }
    END_OF_FUNCTION(increment_timer);

    volatile long timer2 = 0;

    void increment_timer2()
    {
    timer2++;
    }
    END_OF_FUNCTION(increment_timer);



    int main(int argc, char *argv[])
    {
    allegro_init();
    install_keyboard();
    install_timer();
    install_int_ex(increment_timer, BPS_TO_TIMER(60));
    install_int_ex(increment_timer, BPS_TO_TIMER(60));
    set_color_depth(16);
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, 1280, 700, 0, 0);






    BITMAP *pic = NULL;
    pic = load_bitmap("sprite1.bmp", NULL);

    BITMAP *enemy = NULL;
    enemy = load_bitmap("sprite1.bmp", NULL);

    BITMAP *buffer = NULL;
    buffer = create_bitmap(1280,700);

    BITMAP *title = NULL;
    title = load_bitmap("title.bmp", NULL);

    FONT *font1 = load_font("font1.pcx", NULL, NULL);



    int pic_x = 0;
    int pic_y = 0;
    int enemy_x = 100;
    int enemy_y = 100;
    int moveSpeed = 5;


    while(!key[KEY_SPACE])
    {
    timer = 0;
    blit(title, screen, 0,0,0,0,1280,700);
    }


    while(!key[KEY_ESC])
    {


    if(timer >= 0)
    {
    textout_ex(buffer, font1, "3", 640, 500, makecol(255,255,0), -1);
    }
    if(timer >= 50)
    {
    clear_bitmap(buffer);
    textout_ex(buffer, font1, "2", 640, 500, makecol(255,255,0), -1);
    }
    if(timer >= 100)
    {
    clear_bitmap(buffer);
    textout_ex(buffer, font1, "1", 640, 500, makecol(255,255,0), -1);
    }
    if(timer >= 150)
    {
    clear_bitmap(buffer);
    textout_ex(buffer, font1, "Go!", 640, 500, makecol(255,255,0), -1);
    }
    if(timer >= 200)
    {
    clear_bitmap(buffer);



    if(timer2 <= 100)
    {
    enemy_x -= moveSpeed;
    }
    if(timer2 >= 100)
    {
    enemy_x += moveSpeed;
    }
    if(timer2 >= 200)
    {
    timer2 = 0;
    }

    timer2++;


    if(key[KEY_RIGHT])
    {
    pic_x += moveSpeed;
    }
    if(key[KEY_LEFT])
    {
    pic_x -= moveSpeed;
    }
    if(key[KEY_UP])
    {
    pic_y -= moveSpeed;
    }
    if(key[KEY_DOWN])
    {
    pic_y += moveSpeed;
    }

    }






    draw_sprite(buffer, pic, pic_x, pic_y);
    draw_sprite(buffer, enemy, enemy_x, enemy_y);
    blit(buffer, screen, 0,0,0,0,1280,700);
    clear_bitmap(buffer);
    }



    readkey();
    destroy_bitmap(pic);
    destroy_bitmap(buffer);
    return 0;
    }
    END_OF_MAIN()


    All I am trying to do is make it so that when pic collides with enemy then the loop will end. How can I do that? Please help.

  • #2
    New to the CF scene
    Join Date
    May 2014
    Location
    Pennsylvania
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I found a solution... Thanks for your help. :/


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •