When the bucket drops, I need it to disappear. Help me implement that into my code please.
--\> Physics
local physics = require("physics")
physics.start()
physics.setGravity( 0, 1) -- .01 m/s\*s in the positive x direction
physics.setScale(200) -- 200 pixels per meter
--local sky = display.newImage("bg2.png")
local ground = display.newImage("ground.png", true)
ground.y = display.contentHeight - ground.contentHeight/2
physics.addBody( ground, "static", { friction = 1.0, bounce = 0, density = 1.0 })
--Constants for the level
\_H = display.contentHeight;
\_W = display.contentWidth;
mRand = math.random;
o = 0;
time\_remain = 10;
time\_up = false;
total\_buckets = 3;
ready = false;
local display\_txt = display.newText("Wait", 0, 0, native.systemFont, 16\*2);
display\_txt.xScale = 1; display\_txt.yScale = 1;
display\_txt:setReferencePoint(display.BottomLeftReferencePoint);
display\_txt.x = 20; display\_txt.y = \_H-20;
local countdowntxt = display.newText(time\_remain, 0, 0, native.systemFont, 16\*2);
countdowntxt.xScale = 1; countdowntxt.yScale = 1;
countdowntxt:setReferencePoint(display.BottomRightReferencePoint);
countdowntxt.x = \_W-20; countdowntxt.y = \_H-20;
local function winLose(condition)
if(condition == "win") then
display\_txt.text = "WIN!";
elseif(condition == "fail") then
display\_txt.text = "FAIL!";
end
end
local function trackBuckets(obj)
obj:removeSelf();
o = o-1;
if(time\_up ~= true) then
--If all the orbs are removed from the display
if(o == 0) then
timer.cancel(gametmr);
winLose("win");
end
end
end
local function countDown(e)
if(time\_remain == 10) then
ready = true;
display\_txt.text = "Go!";
end
time\_remain = time\_remain - 1;
countdowntxt.text = time\_remain;
if(time\_remain == 0) then
time\_up = true;
if(o ~= 0) then
display\_txt.text = "FAIL!";
ready = false;
end
end
end
local function spawnBucket()
local bucket = display.newImageRect("redpaintbucket.png", 72, 88);
bucket:setReferencePoint(display.CenterReferencePoint);
bucket.x = mRand(50, \_W-50); bucket.y = mRand(-20, \_H-870);
physics.addBody(bucket, {density=0.1, friction=0.1, bounce=0.1, radius = 9})
function bucket:touch(e)
if(ready == true) then
if(time\_up ~= true) then
if(e.phase == "ended") then
--Play the Popping sound if it was there
trackBuckets(self);
end
end
end
return true;
end
--Increment o for every bucket created
o = o+1;
bucket:addEventListener("touch", bucket);
--If all buckets created, start the timer
if(o == total\_buckets) then
gametmr = timer.performWithDelay(1000, countDown, 10);
else
ready = false;
end
end
tmr = timer.performWithDelay(20, spawnBucket, total\_buckets);
Thanks a ton.
Also, if you wanna help out more (greatly appreciate it), when the objects hit the bottom ground, make it a fail (winLose) condition.
Please tell me how to do all of this. And don’t say like, “oh make a collision test” or something like that. Because that’s jibberish to me. Write it out, and tell me where to put it please. Thanks a ton. I’m a newb. [import]uid: 19768 topic_id: 6530 reply_id: 306530[/import]