| View previous topic :: View next topic |
| Author |
Message |
DiabloTerrorGF
Joined: 15 Jul 2005 Posts: 64
|
Posted: Wed Sep 07, 2005 5:24 am Post subject: Diablo's simple hit detection(more advanced one coming) |
|
|
This code tells you if the center of the first object is anywhere inside the bounds of the second object(return true).
Obj1X is the starting X, Obj1XM is the is the width of the rectangle/square and so on for the others.
| Code: |
function bulletCollide(Obj1X, Obj1Y, Obj1MX, Obj1MY, Obj2X, Obj2Y, Obj2MX, Obj2MY)
Obj1MidX=Obj1X+(Obj1MX/2)
Obj1MidY=Obj1Y+(Obj1MY/2)
Obj2MaxX=Obj2X+Obj2MX
Obj2MaxY=Obj2Y+Obj2MY
if Obj1MidX<Obj2MaxX+1 and Obj1MidX>Obj2X-1 and Obj1MidY<Obj2MaxY+1 and Obj1MidY>Obj2Y-1 then
return true
end
return false
end
|
I have a better one but not with me, it tells you if two rectangles/squares over-lap eachother(you can actually easily figure it out with the above code...)
I guess this is for anyone who is just lazy and doesn't want to figure it out themself. |
|
| Back to top |
|
 |
Dark Killer
Joined: 25 Jan 2005 Posts: 32
|
Posted: Wed Sep 07, 2005 5:58 am Post subject: |
|
|
| You should submit this to be included in the Lput lib. |
|
| Back to top |
|
 |
DiabloTerrorGF
Joined: 15 Jul 2005 Posts: 64
|
Posted: Fri Sep 16, 2005 8:49 am Post subject: |
|
|
| Dark Killer wrote: | | You should submit this to be included in the Lput lib. |
I know nothing of LUA/C++ really, I just convert my Java code that I make into something that looks LUA'able and it usually works. Gotta imagine I was freaking out over what blitting was, when I first started :)
I guess I need to go get my notes for my real rectangle and rectangle hit detection... |
|
| Back to top |
|
 |
|