Game programming

Moderators: None (Apply to moderate this forum)
Number of threads: 2070
Number of posts: 5361

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Edit Report
Collision Detection Posted by Liquid Snake on 9 Apr 2000 at 8:30 AM
Hi!<br>
<br>
I need help with collision detection in VB using Direct3D. Tutorials or samples would be great.


Edit Report
Re: Collision Detection Posted by Sagat on 9 Apr 2000 at 11:50 AM
Hi!<br>
<br>
I need help with collision detection in VB using Direct3D. Tutorials or samples would be great.<br>
<br>
I don't know VB, but here is a C/C++ function<br>
that detects collision. You can easily convert.<br>
<br>
/* Return 1/0 (TRUE, FALSE) if two rectangular<br>
objects collide. */<br>
<br>
int Collide(int X, int Y, int W, int H,<br>
int _X, int _Y, int _W, int _H)<br>
{<br>
return (X + W > _X && X < _X + _W &&<br>
Y + H > _Y && Y < _Y + _H);<br>
}<br>
<br>
Example:<br>
<br>
// If any visible enemys and player collide<br>
<br>
for (i = 0; i < NumEnemys; i++)<br>
if (Enemys[i].Visible)<br>
if (Collide(Player.X, Player.Y, Player.W, Player.H, Enemys[i].X, Enemys[i].Y, Enemys[i].W,<br>
Enemys[i].H))<br>
Player.Life -= Enemys[i].Power;<br>
<br>
if (Player.Life < 0)<br>
{<br>
Player.Lives--;<br>
Player.Dead = TRUE;<br>
}<br>
<br>
if (Player.Lives < 0)<br>
if (!Continue())<br>
Reset();





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.