I have a game where I want the player to have a limited amount of time to make a move. I would want it to end every two seconds, and if the right action is done, I would want the timer to reset. How do I accomplish this? Here is the code I have thus far:
function timer1( event )
local timeClock = event.time
if imageFile == "bluebox.png" then
if timeClock <= 2 then
timer.cancel( event.source )
else
storyboard.gotoScene( "restartEasy" )
randomImage.alpha = 0
end
end
end
function endGame(event)
if imageFile == "redbox.png" then
randomImage.alpha = 0
mydata.score = mydata.score + 1
scoreText.text = mydata.score
button1.x = math.random( 55, 300)
button1.y = math.random( 55, 300)
button2.x = math.random( 55, 300)
button2.y = math.random( 55, 300)
imageFile = imageFiles[math.random(2)]
randomImage = display.newImage(imageFile, centerX, screenTop + 20)
timer.performWithDelay( 2000, timer1 )
else
storyboard.gotoScene( "restartEasy" )
randomImage.alpha = 0
end
end
function endGame2(event)
if imageFile == "bluebox.png" then
randomImage.alpha = 0
mydata.score = mydata.score + 1
scoreText.text = mydata.score
button1.x = math.random( 55, 300)
button1.y = math.random( 55, 300)
button2.x = math.random( 55, 300)
button2.y = math.random( 55, 300)
imageFile = imageFiles[math.random(2)]
randomImage = display.newImage(imageFile, centerX, screenTop + 20)
timer.performWithDelay( 2000, timer1 )
else
storyboard.gotoScene( "restartEasy" )
randomImage.alpha = 0
end
end
button1:addEventListener("tap", endGame)
button2:addEventListener("tap", endGame2)
end
Aucun commentaire:
Enregistrer un commentaire