Diablo's simple hit detection(more advanced one coming)

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Diablo's simple hit detection(more advanced one coming)

Post by DiabloTerrorGF »

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: Select all

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.
Dark Killer
Posts: 32
Joined: Tue Jan 25, 2005 3:10 am

Post by Dark Killer »

You should submit this to be included in the Lput lib.
DiabloTerrorGF
Posts: 64
Joined: Fri Jul 15, 2005 11:44 pm

Post by DiabloTerrorGF »

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...
Post Reply