score can't be displayed at game over transition..can't go back to menu..help pleasseeee..

[lua]

local composer = require( “composer” )

local scene = composer.newScene()

local physics = require(“physics”)

local widget = require “widget”

physics.start()

rand = math.random( 20 )

local slap_sound = audio.loadSound(“Sound/slap2.mp3”)

local ow = audio.loadSound(“Sound/ow.mp3”)

local buttonSound = audio.loadSound(“Sound/sound2.mp3”)

local background

local back

local count={total1=0,total=0,touch=0,life=3}

local total

local time_remain = 5

local mossie

local bee

local shade

local gameOverScreen

local winScreen

local countdown

local life

local pauseBtn

local resumeBtn

local gametmr


– All code outside of the listener functions will only be executed ONCE

– unless “composer.removeScene()” is called.


local function goHome( event )

    if ( event.phase == “ended” ) then

        composer.gotoScene (“menu”)

    end

end

local gameOver = function()

–composer.removeScene(“easy”)

physics.pause()

–audio.play(gameOverSound)

background = display.newImageRect(“Images/bg.jpg”, display.contentWidth, display.contentHeight)

background.anchorX = 0

    background.anchorY = 0

    background.x, background.y = 0, 0

gameOverScreen = display.newImage(“Images/gameover.png”,400,300)

gameOverScreen.x = 160

gameOverScreen.y = 240

gameOverScreen.alpha = 0

transition.to(gameOverScreen,{time=500,alpha=1})

–total.isVisible = true

total.text="Score : "…count.touch

total.x = 160

total.y = 400

–total:setTextColor(000000)

botwall.isVisible = false

mossie.isVisible = false

bee.isVisible = false

life.isVisible = false

countdown.isVisible = false

pauseBtn.isVisible = false

resumeBtn.isVisible = false

local home=display.newText(“Home”,display.contentWidth * 0.5, 20, “Arial”, 26)

home:addEventListener(“touch”, goHome)

 end

local function countDown(e)

time_remain = time_remain-1

countdown.text = time_remain

if time_remain == 0 then

 gameOver()

end

end

local pauseGame = function(e)

if(e.phase==“ended”) then

audio.play(buttonSound)

physics.pause()

timer.pause(gametmr)

pauseBtn.isVisible = false

resumeBtn.isVisible = true

return true

end

end

local resumeGame = function(e)

if(e.phase==“ended”) then

audio.play(buttonSound)

physics.start()

timer.resume(gametmr)

pauseBtn.isVisible = true

resumeBtn.isVisible = false

return true

end

end

local collisionListener=function(self,event)

if(event.phase==“began”)then

if(event.other.type==“mossie”)then

audio.play(ow)

count.life=count.life-1

if(count.life==0) then

gameOver()

end

event.other:removeSelf()

event.other=nil

else

event.other:removeSelf()

event.other=nil

end

end

end

function onTouch(mossie)

audio.play(slap_sound)

count.touch=count.touch+1

total.text="Score : "…count.touch

mossie.target:removeSelf()

end

function killIt(e)

if(e.phase == “ended”) then

gameOver()

end

end

local bottomWall = function()

botwall=display.newImage(“Images/tangan.png”)

botwall.x = 160

botwall.y = 500

botwall:setFillColor(22,125,185,255)

botwall.type=“botwall”

botwall.collision=collisionListener

physics.addBody(botwall,“static”,{ density=100.0, friction=0.0, bounce=0.0} )

botwall:addEventListener(“collision”,botwall)

end

local function newMossie(event)    

total.text="Score : "…count.touch

life.text="Life : "…count.life

mossie = display.newImage(“Images/biasa.png”) 

mossie.x = 60 + math.random( 160 )

mossie.y = -100

mossie.type=“mossie”

mossie:setFillColor(255,0,0)

physics.addBody( mossie, { density=0.3, friction=0.2, bounce=0.5} )

mossie.name = “mossie”

mossie:addEventListener(“touch”,onTouch)

end 

local function newBee(event)

bee = display.newImage(“Images/lebah.png”)

bee.x = 60 + math.random( 160 )

bee.y = -100

bee.type=“other”

physics.addBody( bee, { density=1.4, friction=0.3, bounce=0.2} )

bee:addEventListener(“touch”,killIt)

end

– local forward references should go here


– “scene:create()”

function scene:create( event )

   local sceneGroup = self.view

   background = display.newImageRect( “Images/bg.jpg”, display.contentWidth, display.contentHeight )

   background.anchorX = 0

   background.anchorY = 0

   background.x, background.y = 0, 0

   

   total=display.newText(“Score : 0”,display.contentWidth * 0.5, 20, “Arial”, 26)

   total:setTextColor(000000)

   countdown=display.newText(time_remain ,display.contentWidth * 0.9, 20, “Arial”, 26)

   countdown:setTextColor(000000)

   

   life = display.newText("Life : 3 " ,display.contentWidth * 0.5, 50, “Arial”, 26)

   life:setTextColor(000000)

   

   pauseBtn = display.newImage(“Images/pause.png”)

   pauseBtn.x = display.contentWidth * 0.1

   pauseBtn.y = display.contentHeight - 450

   resumeBtn = display.newImage(“Images/playb.png”) 

   resumeBtn.x = display.contentWidth * 0.1

   resumeBtn.y = display.contentHeight - 450

   botwall=display.newImage(“Images/tangan.png”)

   botwall.x = 160

   botwall.y = 500

   botwall:setFillColor(22,125,185,255)

   botwall.type=“botwall”

   botwall.collision=collisionListener

   physics.addBody(botwall,“static”,{ density=100.0, friction=0.0, bounce=0.0} )

   

   

   sceneGroup:insert(background)

   sceneGroup:insert(total)

   sceneGroup:insert(countdown)

   sceneGroup:insert(life)

   sceneGroup:insert(pauseBtn)

   sceneGroup:insert(resumeBtn)

   sceneGroup:insert(botwall)

   

   

   resumeBtn.isVisible = false

  

  

   – Initialize the scene here.

   – Example: add display objects to “sceneGroup”, add touch listeners, etc.

end

– “scene:show()”

function scene:show( event )

   local sceneGroup = self.view

   local phase = event.phase

   

   

   

   if ( phase == “will” ) then

   

      – Called when the scene is still off screen (but is about to come on screen).

   elseif ( phase == “did” ) then

    pauseBtn:addEventListener(“touch”, pauseGame)

   resumeBtn:addEventListener(“touch”, resumeGame)

   botwall:addEventListener(“collision”,botwall)

   

   dropMossie = timer.performWithDelay( 2000 , newMossie, -1 )

   dropBee = timer.performWithDelay( 1800 , newBee, -1)

   gametmr = timer.performWithDelay(1000, countDown, -1)

   

      – Called when the scene is now on screen.

      – Insert code here to make the scene come alive.

      – Example: start timers, begin animation, play audio, etc.

   end

end

– “scene:hide()”

function scene:hide( event )

   local sceneGroup = self.view

   local phase = event.phase

   

   

   if ( phase == “will” ) then

physics.stop()

   

pauseBtn:removeEventListener(“touch”, pauseGame)

   resumeBtn:removeEventListener(“touch”, resumeGame)

   botwall:removeEventListener(“collision”,botwall)

   bee:removeEventListener(“touch”,killIt)

   mossie:removeEventListener(“touch”,onTouch)

timer.cancel(gametmr)

  

      – Called when the scene is on screen (but is about to go off screen).

      – Insert code here to “pause” the scene.

      – Example: stop timers, stop animation, stop audio, etc.

   elseif ( phase == “did” ) then

      – Called immediately after scene goes off screen.

   end

end

– “scene:destroy()”

function scene:destroy( event )

   local sceneGroup = self.view

   

   – Called prior to the removal of scene’s view (“sceneGroup”).

   – Insert code here to clean up the scene.

   – Example: remove display objects, save state, etc.

end


– Listener setup

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene

[lua]