After the collision how can i reload the game??
--Ball Game display.setStatusBar(display.HiddenStatusBar) -- Physics local physics = require('physics') physics.start() local W = display.contentWidth local H = display.contentHeight --[bg] --[Title View] local playBtn local titleView -- -- TextFields local scoreTF -- Instructins Message local ins -- Helicopter local helicopter -- Blocks local blocks = {} -- Alert local alertView -- Sounds --local bgMusic = audio.loadStream('POL-rocket-station-short.wav') --local explo = audio.loadSound('explo.wav') -- Variables local timerSrc local yPos = {H/2+100, H/2+200, H/2-200,H/2-100} local speed = 5 local speedTimer local up = false local impulse = -60 -- Functions local Main = {} local startButtonListeners = {} local showGameView = {} local gameListeners = {} local createBlock = {} local movePlayer = {} local increaseSpeed = {} local update = {} local alert = {} -- Main Function function Main() --titleBg = display.newImage('titleBg.png', W/2,H/2) playBtn = display.newText("Play",W/2,H/2,"arial", 100) titleView = display.newGroup( playBtn) startButtonListeners('add') end function startButtonListeners(action) if(action == 'add') then playBtn:addEventListener('tap', showGameView) else playBtn:removeEventListener('tap', showGameView) end end function showGameView:tap(e) transition.to(titleView, {time = 300, x = -titleView.height, onComplete = function() startButtonListeners('rmv') display.remove(titleView) titleView = nil end}) -- [Add GFX] -- Instructions Message ins = display.newText("Touch to go up!",W/2,H-100,"arial",50) transition.from(ins, {time = 200, alpha = 0.1, onComplete = function() timer.performWithDelay(2000, function() transition.to(ins, {time = 200, alpha = 0.1, onComplete = function() display.remove(ins) ins = nil end}) end) end}) -- TextFields scoreTF = display.newText('0', W/2, (W-W)+35, 'Marker Felt', 60) scoreTF:setTextColor(255, 255, 255) -- Helicopter helicopter = display.newCircle( 50, 152,20) helicopter:setFillColor( 100,0,0 ) physics.addBody(helicopter) -- Walls local top = display.newRect(W/2, 60, W, 5) top:setFillColor(0, 0, 100) local bottom = display.newRect(W/2, H-60, W, 5) bottom:setFillColor(0, 0, 100) -- Add physics physics.addBody(helicopter) physics.addBody(top, 'static') physics.addBody(bottom, 'static') blocks = display.newGroup() gameListeners('add') --audio.play(bgMusic, {loops = -1, channel = 1}) end function gameListeners(action) if(action == 'add') then Runtime:addEventListener('touch', movePlayer) Runtime:addEventListener('enterFrame', update) timerSrc = timer.performWithDelay(1300, createBlock, 0) speedTimer = timer.performWithDelay(15000, increaseSpeed, 5) helicopter:addEventListener('collision', onCollision) else Runtime:addEventListener('touch', movePlayer) Runtime:removeEventListener('enterFrame', update) timer.cancel(timerSrc) timerSrc = nil helicopter:removeEventListener('collision', onCollision) end end function createBlock() local b local rnd = math.floor(math.random() \* 4) + 1 b = display.newRect( display.contentWidth, yPos[math.floor(math.random() \* 3)+1],50,200) b.name = 'block' b:setFillColor( 0,0,100 ) -- Block physics physics.addBody(b, 'kinematic') b.isSensor = true blocks:insert(b) end function movePlayer(e) if(e.phase == 'began') then up = true end if(e.phase == 'ended') then up = false impulse = -60 end end function increaseSpeed() speed = speed + 2 print("speedUp") end function update(e) -- Move helicopter up if(up) then impulse = impulse - 3 helicopter:setLinearVelocity(0, impulse) end -- Move Blocks if(blocks ~= nil)then for i = 1, blocks.numChildren do blocks[i].x = blocks[i].x - speed end end -- Score scoreTF.text = tostring(tonumber(scoreTF.text) + 1) end function onCollision(e) display.remove(helicopter) alert() end function alert() local cont = display.newRect( W/2, H/2, 800, 600 ) cont:setFillColor( 100,0,0,0.5) local retrayBtn = display.newText("Retray",W/2,H/2,"Arial",100) gameListeners('rmv') alertView = display.newText("Game Over!",W/2,H/4,"arial",100) transition.from(alertView, {time = 300, xScale = 0.5, yScale = 0.5}) -- Wait 100 ms to stop physics timer.performWithDelay(1000, function() physics.stop() end, 1) end Main()