I did something like that that… Here is my line of code Peachy
[lua]local hitCount = 0
function SadFaceCount()
hitCount = hitCount + 1
if hitCount <= 5 then
local strike = display.newImageRect(“strike.png”, 65, 65)
junkGroup:insert(strike)
local offsetFraction = hitCount + 1/6
strike.x = 80 * offsetFraction
strike.y = 60
else
local sadFaceEndFunction
sadFaceEndFunction = function(event) explode(junk, sadFaceEndFunction); end
junk:addEventListener(“touch”, sadFaceEndFunction)
end
end
function explode(junk, listener)
junk:removeEventListener(“touch”, listener)
– The junk should not move while exploding
junk.bodyType = “kinematic”
junk:setLinearVelocity(0, 0)
junk.angularVelocity = 0
– Shake the stage
local stage = display.getCurrentStage()
local moveRightFunction
local moveLeftFunction
local rightTrans
local leftTrans
local shakeTime = 50
local shakeRange = {min = 1, max = 25}
moveRightFunction = function(event) rightTrans = transition.to(stage, {x = math.random(shakeRange.min,shakeRange.max), y = math.random(shakeRange.min, shakeRange.max), time = shakeTime, onComplete=moveLeftFunction}); end
moveLeftFunction = function(event) leftTrans = transition.to(stage, {x = math.random(shakeRange.min,shakeRange.max) * -1, y = math.random(shakeRange.min,shakeRange.max) * -1, time = shakeTime, onComplete=moveRightFunction}); end
moveRightFunction()
local linesGroup = display.newGroup()
– Generate a bunch of lines to simulate an explosion
local drawLine = function(event)
local line = display.newLine(junk.x, junk.y, display.contentWidth * 2, display.contentHeight * 2)
line.rotation = math.random(1,360)
line.width = math.random(15, 25)
linesGroup:insert(line)
end
local lineTimer = timer.performWithDelay(100, drawLine, 0)
– Function that is called after the pre explosion
local exploded = function(event)
audio.play(explosion)
blankOutScreen(junk, linesGroup);
timer.cancel(lineTimer)
stage.x = 0
stage.y = 0
transition.cancel(leftTrans)
transition.cancel(rightTrans)
end
– Play the preExplosion sound first followed by the end explosion
audio.play(preExplosion, {onComplete = exploded})
timer.cancel(fruitTimer)
timer.cancel(junkTimer)
end
function blankOutScreen(junk, linesGroup)
local gameOver = displayGameOver()
gameOver.alpha = 0 – Will reveal the game over screen after the explosion
– Create an explosion animation
local circle = display.newCircle( junk.x, junk.y, 5 )
local circleGrowthTime = 300
local dissolveDuration = 1000
local dissolve = function(event) transition.to(circle, {alpha = 0, time = dissolveDuration, delay = 0, onComplete=function(event) gameOver.alpha = 1 end}); gameOver.alpha = 1 end
circle.alpha = 0
transition.to(circle, {time=circleGrowthTime, alpha = 1, width = display.contentWidth * 3, height = display.contentWidth * 3, onComplete = dissolve})
– Vibrate the phone
system.vibrate()
junk:removeSelf()
linesGroup:removeSelf()
end[/lua] [import]uid: 51459 topic_id: 11732 reply_id: 43022[/import]