The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

## checking for hit?

This is a discussion on checking for hit? within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; how do i make it so it checks to see if say enemy hits player? like: if enemyx==playerx and enemyy==playery ...

 Tweet
1. ## checking for hit?

how do i make it so it checks to see if say enemy hits player?
like:

if enemyx==playerx and enemyy==playery then
enemyxmove = math.random(4)
enemyy = math.random(272)
enemyx = 450
lives = lives-1

that doesn't seem to work so is there some special way to say and or hittest or what?

2. well, there are plenty of collision detection engines out there, but mine is in C, so you wouldnt understand it, but i could translate it to LUA if you want?

3. Talk about a big ego...

Anyways, what you want is a collision detection function.

Code:
```function collision(x1, y1, w1, h1, x2, y2, w2, h2)
if (y2 >= y1 and y1 + h1 >= y2) or (y2 + h2 >= y1 and y1 + h1 >= y2 + h2) or (y1 >= y2 and y2 + h2 >= y1) or (y1 + h1 >= y2 and y2 + h2 >= y1 + h1) then
if x2 >= x1 and x1 + w1 >= x2 then
return true
elseif x2 + w2 >= x1 and x1 + w1 >= x2 + w2 then
return true
elseif x1 >= x2 and x2 + w2 >= x1 then
return true
elseif x1 + w1 >= x2 and x2 + w2 >= x1 + w1 then
return true
end
end

return false
end```
x1, y1, w1, h1 are the x coor, y coor, width and height of the first object and x2, y2, w2, h2 are the x coor, y coor, width and height of the second object. The function will return either true if their is a collision or false if their isn't.

Oh, and I certainly hope your collision detection "engine" isn't the one I provided for you, SG57. A box Barrier help...

4. well thanks although i figured out for now a semi hit test that seems to work ok for now=-) perhaps later on, i'll use this also i was wondering if you could do something like thos in lua:

if play==false then
if somehting then
play=true
end
end
if play==true then
if something then
do sometin
end
end

would that work or not?

5. k i figured out you could so new question:can you check to see what image is currently being displayed?

6. Originally Posted by slicer4ever
k i figured out you could so new question:can you check to see what image is currently being displayed?
Yes, very easily, but I put mine into a loop:

for(i=1; i>0; i++) {
screen:blit whatever
blitting w/e image = true
}

if blitting w/e image = true then
what ever you want here
end

My LUA is bad since starting a new language, so this is a combination of them sorry, but this will make a loop as long as 1 is greater than 0 and it is, so it goes up to ensure an infinitacy (?), and it will display the image thing for ever and make make a flag called 'blitting w/e image' become true. Then just call an if statement saying if blitting w/e image is true, then dom w.e.

My LUA is very bad since starting a new languaage.

7. yes i prgram in flash also it's hard to forget not to put _root. and that stuff o but flash felt so much easier...

8. arg it doesn't work, i'm trying to make my menu but that method does not work=-(

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 08:05 PM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY