Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local widget = require( "widget" )
- local grupo = display.newGroup()
- local hit = 0
- local bar = 0
- local grupo2 = display.newGroup()
- local hit2 = 0
- local bar2 = 0
- options = {
- x=display.contentCenterX,
- y=display.contentCenterY + display.contentCenterY / 2 + 50,
- label="Restart",
- fontSize=50,
- width=500
- }
- local barra = display.newRect( display.contentCenterX/2, display.contentCenterY + display.contentCenterY/2, 100, 500 )
- barra:setFillColor( 0.5,0.5,0.5 )
- barra.anchorX = 0.5
- barra.anchorY = 1
- local fillBarra = display.newRect( barra.x, barra.y, 100, 0 )
- fillBarra:setFillColor( 0,0,1 )
- fillBarra.anchorX = 0.5
- fillBarra.anchorY = 1
- grupo:insert( barra )
- grupo:insert( fillBarra )
- local barra2 = display.newRect( display.contentCenterX + display.contentCenterX / 2, display.contentCenterY + display.contentCenterY/2, 100, 500 )
- barra2:setFillColor( 0.5,0.5,0.5 )
- barra2.anchorX = 0.5
- barra2.anchorY = 1
- local fillBarra2 = display.newRect( barra2.x, barra2.y, 100, 0 )
- fillBarra2:setFillColor( 1,0,0 )
- fillBarra2.anchorX = 0.5
- fillBarra2.anchorY = 1
- grupo2:insert( barra2 )
- grupo2:insert( fillBarra2 )
- function addHit( hit )
- bar = bar + hit
- if bar >= 100 then
- print( "1 morreu" )
- bar = 100
- timer.pause( tempo1 )
- timer.pause( tempo2 )
- Runtime:removeEventListener("touch",bater)
- Runtime:removeEventListener("touch",bater2)
- options.label = "2 Ganhou"
- btn = widget.newButton( options )
- local function restart( event )
- bar = 0
- bar2 = 0
- print( bar2 )
- timer.resume( tempo1 )
- timer.resume( tempo2 )
- Runtime:addEventListener("touch",bater)
- Runtime:addEventListener("touch",bater2)
- btn:removeEventListener( "tap", restart )
- display.remove( btn )
- btn = nil
- end
- btn:addEventListener( "tap", restart)
- end
- transition.to( fillBarra, {height=barra.height / 100 * bar, time = 100} )
- end
- function addHit2( hit2 )
- bar2 = bar2 + hit2
- if bar2 >= 100 then
- print( "2 morreu" )
- bar2 = 100
- timer.pause( tempo1 )
- timer.pause( tempo2 )
- Runtime:removeEventListener("touch",bater)
- Runtime:removeEventListener("touch",bater2)
- options.label = "1 Ganhou"
- btn = widget.newButton( options )
- local function restart( event )
- bar = 0
- bar2 = 0
- timer.resume( tempo1 )
- timer.resume( tempo2 )
- Runtime:addEventListener("touch",bater)
- Runtime:addEventListener("touch",bater2)
- btn:removeEventListener( "tap", restart )
- display.remove( btn )
- btn = nil
- end
- btn:addEventListener( "tap", restart)
- end
- transition.to( fillBarra2, {height=barra2.height / 100 * bar2, time = 100} )
- end
- function bater( event )
- if event.phase == "ended" then
- if event.y < display.contentCenterY and event.x < display.contentCenterX then
- addHit( 10 )
- elseif event.y > display.contentCenterY and event.x < display.contentCenterX then
- addHit( -10 )
- addHit2( 10 )
- end
- end
- end
- function bater2( event )
- if event.phase == "ended" then
- if event.y < display.contentCenterY and event.x > display.contentCenterX then
- addHit2( 10 )
- elseif event.y > display.contentCenterY and event.x > display.contentCenterX then
- addHit2( -10 )
- addHit (10)
- end
- end
- end
- Runtime:addEventListener( "touch", bater )
- Runtime:addEventListener( "touch", bater2 )
- function subirBarra( event )
- addHit(1)
- end
- function subirBarra2( event )
- addHit2(1)
- end
- tempo1 = timer.performWithDelay( 100, subirBarra , -1 )
- tempo2 = timer.performWithDelay( 100, subirBarra2 , -1 )
- --------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement