Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Collision Detection

Hi!



I need help with collision detection in VB using Direct3D. Tutorials or samples would be great.


Comments

  • Hi!



    I need help with collision detection in VB using Direct3D. Tutorials or samples would be great.



    I don't know VB, but here is a C/C++ function

    that detects collision. You can easily convert.



    /* Return 1/0 (TRUE, FALSE) if two rectangular

    objects collide. */



    int Collide(int X, int Y, int W, int H,

    int _X, int _Y, int _W, int _H)

    {

    return (X + W > _X && X < _X + _W &&

    Y + H > _Y && Y < _Y + _H);

    }



    Example:



    // If any visible enemys and player collide



    for (i = 0; i < NumEnemys; i++)

    if (Enemys[i].Visible)

    if (Collide(Player.X, Player.Y, Player.W, Player.H, Enemys[i].X, Enemys[i].Y, Enemys[i].W,

    Enemys[i].H))

    Player.Life -= Enemys[i].Power;



    if (Player.Life < 0)

    {

    Player.Lives--;

    Player.Dead = TRUE;

    }



    if (Player.Lives < 0)

    if (!Continue())

    Reset();


Sign In or Register to comment.