anybody can help me to find the 2D collision detection in a easiest way / different ways of 2D collision detection.

I am using DirectX 9.0 SDK & VC2005 IDE

Thanks in advance.

calculate center's coordinate of the objects and if the distance between centers is less than (you decide) there is a collision.

This is something I used in a brickout game I made ill just post the collision code, now SPRITE is class SPRITE and within that is the x and y variables set public for the 2d sprite.

//Setting up rectangle collision between 2 sprites
int Collision(SPRITE sprite1, SPRITE sprite2)
{
    RECT rect1;
    rect1.left = sprite1.x+1;
    rect1.top = sprite1.y+1;
    rect1.right = sprite1.x + sprite1.width-1;
    rect1.bottom = sprite1.y + sprite1.height-1;

    RECT rect2;
    rect2.left = sprite2.x+1;
    rect2.top = sprite2.y+1;
    rect2.right = sprite2.x + sprite2.width-1;
    rect2.bottom = sprite2.y + sprite2.height-1;

    RECT dest;
    return IntersectRect(&dest, &rect1, &rect2);
}

now to call the collision between the two objects,

//see if ball hit the paddle
if (Collision(paddle, ball))
{
    ball.y += ball.movey;
    ball.movey *= -1;
    PlaySound(sound_hit);
}

Hopes that helps you out a little. Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.