[lua]centerX = display.contentCenterX
centerY = display.contentCenterY
local mRandom = math.random
local ground = display.newRect ( 10, 10, 320, 10)
ground.x = centerX
ground.y = centerY - -180
physics.addBody ( ground, “static”, {friction = 0.3, bounce = 0.1} )
function newBox ()
rand = mRandom ( 3 )
if ( rand < 2 ) then
a = display.newRect ( 10, 10, 50, 50)
a.x = centerX
a.y = centerY - 100
a:setFillColor(155,0,0)
physics.addBody ( a, " static", {density = 0.1, friction = 3, bounce = 0} )
else if
( rand < 3 ) then
b = display.newRect ( 10, 10, 50, 50)
b.x = centerX
b.y = centerY - 100
b:setFillColor(155,155,0)
physics.addBody ( b, " static", {density = 0.1, friction = 3, bounce = 0} )
else if
( rand < 4 ) then
c = display.newRect ( 10, 10, 50, 50)
c.x = centerX
c.y = centerY - 100
c:setFillColor(0,155,0)
physics.addBody ( c, " static", {density = 0.1, friction = 3, bounce = 0} )
end
end
end
end
timer.performWithDelay ( 300, newBox, 3)
local Rbtn = display.newRect( 150, 450, 30, 30 )
Rbtn.x = display.contentCenterX - 130
Rbtn:setFillColor(155,0,0)
local Ybtn = display.newRect( 160, 450, 30, 30 )
Ybtn.x = display.contentCenterX
Ybtn:setFillColor(155,155,0)
local Gbtn = display.newRect( 220, 450, 30, 30 )
Gbtn.x = display.contentCenterX - -130
Gbtn:setFillColor(0,155,0)
function touchRedbtn ( event )
if event.phase == “began” then
display.remove (a)
a = nil
onComplete = newBox()
return true
end
end
function touchYellowbtn ( event )
if event.phase == “began” then
display.remove ( B)
b = nil
onComplete = newBox()
return true
end
end
function touchGreenbtn ( event )
if event.phase == “began” then
display.remove ©
c = nil
onComplete = newBox()
return true
end
end
Rbtn:addEventListener (“touch”, touchRedbtn)
Ybtn:addEventListener (“touch”, touchYellowbtn)
Gbtn:addEventListener (“touch”, touchGreenbtn)
[/lua]
when i press the red / green / yellow button, it randomly remove 1 of them in the screen,
my question is --> How to set to remove the most bottom box and not affecting all other boxes that on top of the box