If it helps anyone help me, here is my mangled code so far, it doesn’t work but is going sort of in the right direction:
[lua]-- NEW make platforms ---------------------------------------------------------------
local platforms = {}
for i = 1, 10 do
platforms[i] = display.newImageRect( “platform.png”, 75, 15)
platforms[i].x = math.random(-250, 650)
platforms[i].y = math.random(180, 380)
platforms[i].isVisible = true
platforms[i].name = “platform”
platforms[i].IsGround = true
physics.addBody( platforms[i], “static”, { density=1, friction=0.3, bounce=0.2 } )
this2:insert(platforms[i])
end
stopCheck = false
function hitTestObjects(obj1, obj2)
local left = obj1.contentBounds.xMin <= obj2.contentBounds.xMin and obj1.contentBounds.xMax >= obj2.contentBounds.xMin
local right = obj1.contentBounds.xMin >= obj2.contentBounds.xMin and obj1.contentBounds.xMin <= obj2.contentBounds.xMax
local up = obj1.contentBounds.yMin <= obj2.contentBounds.yMin and obj1.contentBounds.yMax >= obj2.contentBounds.yMin
local down = obj1.contentBounds.yMin >= obj2.contentBounds.yMin and obj1.contentBounds.yMin <= obj2.contentBounds.yMax
return (left or right) and (up or down)
end
local function checkPlatforms()
for i = 1, 10 do
local firstPlatform = platforms[i]
for j=1,#platforms do
local secondPlatform = platforms[j]
if stopCheck == false then
if hitTestObjects(firstPlatform, secondPlatform) == true then
–firstPlatform.x = math.random(-250, 650)
–firstPlatform.y = math.random(180, 380)
firstPlatform:removeSelf()
print(“moved one”)
checkPlatforms()
else
stopCheck = true
Runtime:removeEventListener( “enterFrame”, checkPlatforms )
end
end
end
end
end
if stopCheck == false then
Runtime:addEventListener( “enterFrame”, checkPlatforms )
else
Runtime:removeEventListener( “enterFrame”, checkPlatforms )
end[/lua] [import]uid: 33866 topic_id: 8038 reply_id: 28630[/import]