Collision Detection - Programmers Heaven

Howdy, Stranger!

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

Categories

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.