Very confused please help!

Hey, i’m very new to this programming language and i have many problems i just cant get my head around.

For example, i’ve read many articles on the collision, but it still seems impossible. 

For testing i simply have a red box arriving from a random part from the top of the screen. The box will use “transition.to()” to the middle of the screen.

I want to make it so that when the red box collides with the black circle in the middle, score is increased by one, and another red box is sent as it was before.

Please help me with this little task it would be very beneficial for my knowledge.

----here is the code below for reference, feel free to input on what i need to do-- 

Thanks a ton!

display.setDefault("background", 255, 255, 255, 1) local circle = display.newCircle( display.contentWidth/2, display.contentHeight/2, 60 ) circle:setFillColor( 0) box = display.newRect(300,0,40,40) box:setFillColor(5,0,0) box.x = display.contentWidth\*math.random(0,3)/3 box.y = 0 transition.to( box, { alpha=2, time=800, y=display.contentHeight/2, transition=removeSelf, onComplete=removeSelf } ) transition.to( box, { alpha=2, time=800, x=display.contentWidth/2, transition=removeSelf, onComplete=removeSelf } )

Something like this, maybe:?

display.setDefault("background", 255, 255, 255, 1) local circle = display.newCircle( display.contentWidth/2, display.contentHeight/2, 60 ) circle:setFillColor( 0) box = display.newRect(300,0,40,40) box:setFillColor(5,0,0) box.x = display.contentWidth\*math.random(0,3)/3 box.y = 0 boxTransition = transition.to( box, { alpha=2, time=800, y=display.contentHeight/2, x=display.contentWidth/2, transition=removeSelf, onComplete=removeSelf } ) circle.r = circle.width/2 local function intersects(circle, rect) if circle ~= nil then local circleDistance\_x = math.abs(circle.x+circle.r - rect.x - rect.width/2) local circleDistance\_y = math.abs(circle.y+circle.r - rect.y - rect.height/2) if (circleDistance\_x \> (rect.width/2 + circle.r)) then return false end if (circleDistance\_y \> (rect.height/2 + circle.r)) then return false end if (circleDistance\_x \<= (rect.width/2)) then return true end if (circleDistance\_y \<= (rect.height/2)) then return true end cornerDistance\_sq = (circleDistance\_x - rect.width/2)^2 + (circleDistance\_y - rect.height/2)^2 return (cornerDistance\_sq \<= (circle.r^2)) else return false end end local function frameUpdate() if intersects(circle, box) then transition.cancel(boxTransition) box.x = math.random(360) box.y = math.random(40) boxTransition = transition.to( box, { alpha=2, time=800, y=display.contentHeight/2, x=display.contentWidth/2, transition=removeSelf, onComplete=removeSelf } ) end end Runtime:addEventListener( "enterFrame", frameUpdate )

I got the intersects function from here:

http://stackoverflow.com/questions/7142088/circle-rect-collision-detection-not-working-in-corona-sdk

Something like this, maybe:?

display.setDefault("background", 255, 255, 255, 1) local circle = display.newCircle( display.contentWidth/2, display.contentHeight/2, 60 ) circle:setFillColor( 0) box = display.newRect(300,0,40,40) box:setFillColor(5,0,0) box.x = display.contentWidth\*math.random(0,3)/3 box.y = 0 boxTransition = transition.to( box, { alpha=2, time=800, y=display.contentHeight/2, x=display.contentWidth/2, transition=removeSelf, onComplete=removeSelf } ) circle.r = circle.width/2 local function intersects(circle, rect) if circle ~= nil then local circleDistance\_x = math.abs(circle.x+circle.r - rect.x - rect.width/2) local circleDistance\_y = math.abs(circle.y+circle.r - rect.y - rect.height/2) if (circleDistance\_x \> (rect.width/2 + circle.r)) then return false end if (circleDistance\_y \> (rect.height/2 + circle.r)) then return false end if (circleDistance\_x \<= (rect.width/2)) then return true end if (circleDistance\_y \<= (rect.height/2)) then return true end cornerDistance\_sq = (circleDistance\_x - rect.width/2)^2 + (circleDistance\_y - rect.height/2)^2 return (cornerDistance\_sq \<= (circle.r^2)) else return false end end local function frameUpdate() if intersects(circle, box) then transition.cancel(boxTransition) box.x = math.random(360) box.y = math.random(40) boxTransition = transition.to( box, { alpha=2, time=800, y=display.contentHeight/2, x=display.contentWidth/2, transition=removeSelf, onComplete=removeSelf } ) end end Runtime:addEventListener( "enterFrame", frameUpdate )

I got the intersects function from here:

http://stackoverflow.com/questions/7142088/circle-rect-collision-detection-not-working-in-corona-sdk