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 

Collision Detection

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



Joined: 04 Jul 2006
Posts: 3

PostPosted: Tue Jul 04, 2006 11:34 pm    Post subject: Collision Detection Reply with quote

Well I started to program a very easy version of breakout (no extra's or other things, just break out the blocks). I have a idea how to do the "physiks" and the collision detection. But then I recognized that I have to check every block's coordinates and now I wonder how to solve the problem more easy.

A friend of mine has nearly the same problem. He wants to make a vertical shooter, but doesn't want to check the coordinates of each objec by him self....

btw. I looked at the source of the breakout clone which can be downloadet on luaplayer.org, but it was very confusing (because most of the variable names are not in english)

Please excuse my bad english, but I'm german ;D
Back to top
View user's profile Send private message
Flashware



Joined: 04 Jul 2006
Posts: 3

PostPosted: Tue Jul 04, 2006 11:39 pm    Post subject: Re: Collision Detection Reply with quote

damn I wantet to edit my last post and came on the quote button.... sorry
Back to top
View user's profile Send private message
SSpeare



Joined: 23 May 2006
Posts: 63

PostPosted: Sat Jul 08, 2006 1:39 am    Post subject: Reply with quote

You do have to check every block's coordinates. That is the only way to do it. If you had 10,000 blocks you would probably need an additional data structure to filter the blocks spatially, but that shouldn't be necessary here.

If you have an array of blocks that are all the same size (I assume):

Code:
blockWidth = 20
blockHeight = 10
blocks = {}
table.insert(blocks, {x:10,y:20})
table.insert(blocks, {x:30,y:20})
table.insert(blocks, {x:10,y:30})


Then you just write a function to test a block:

Code:
function hitBlock(x,y,block)
  if x >= block.x and x <= block.x+blockWidth and
      y >= block.y and y <= block.y+blockHeight then
    return true
  else
    return false
  end
end


Then test every block. Something like:

Code:
local blockCount = #blocks
for i=1,blockCount do
  if (hitBlock(blocks[i])) then
     -- process it
  end
end
Back to top
View user's profile Send private message Visit poster's website
Flashware



Joined: 04 Jul 2006
Posts: 3

PostPosted: Wed Jul 12, 2006 3:04 pm    Post subject: Reply with quote

thank you very much. I think I explaned it wrong to you, but you understood what I meened ;).
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