forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

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

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
DiabloTerrorGF



Joined: 15 Jul 2005
Posts: 64

PostPosted: Wed Sep 07, 2005 5:24 am    Post subject: Diablo's simple hit detection(more advanced one coming) Reply with quote

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
View user's profile Send private message
Dark Killer



Joined: 25 Jan 2005
Posts: 32

PostPosted: Wed Sep 07, 2005 5:58 am    Post subject: Reply with quote

You should submit this to be included in the Lput lib.
Back to top
View user's profile Send private message AIM Address
DiabloTerrorGF



Joined: 15 Jul 2005
Posts: 64

PostPosted: Fri Sep 16, 2005 8:49 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group