Collision detection

Started by
1 comment, last by evolutional 19 years, 8 months ago
I am trying to make a 2d side scroller but the graphics are such that the tiles used for blocking some are complete 32 * 32 and the graphics occupy the whole tile are but some occupy just on half or more but not complete. How do I check collision dectection. Please help
Advertisement
I'm not really in the place to put my thoughts down, but this should get you what you need. It's often just a matter of knowing the terminology.

Searching these forums for the same (and just collision detection) will get you plenty of detailed responses.

Also, this may come in handy, if you're doing any bullet ricochets etc.

Lastly, the articles on this site, specifically the Collision Detection ones should help you out.
If a plant cannot live according to its nature, it dies; so a man.
Nice and easy if you're dealing with rectangles. Test each corner point of one rectangle against the destination.

Here's the basic collision detection code from jsInvaders. It only reports if the two collision boxes overlap, further tests such as per pixel tests can be done after this to fine tune the collision.

// Simple test to see if collision box of WeaponFire (wf) intersects with collision box of alien// bl = bottom left, tl = top left, tr = top right, tl = top leftvMin.x = alien->collisionbox.bl.x;vMin.y = alien->collisionbox.bl.y;vMax.x = alien->collisionbox.tr.x;vMax.y = alien->collisionbox.tr.y;//compare collisionsif (( wf->collisionbox.tr.x >= vMin.x ) && ( wf->collisionbox.tr.x <= vMax.x ) ){	// matches in the x	if (( wf->collisionbox.br.y >= vMin.y ) && ( wf->collisionbox.br.y <= vMax.y ) )	{		  /// A COLLISION HAS HAPPENED					}}

This topic is closed to new replies.

Advertisement