[lua]
local composer = require( “composer” )
local scene = composer.newScene()
display.setStatusBar(display.HiddenStatusBar)
_W = display.contentWidth
_H = display.contentHeight
require(“physics”)
physics.start()
physics.setDrawMode(“normal”)
physics.setGravity( 0,140)
local timeSprite = 800
local velocita = 1
local playerHasJumped = 0
local gameIsPaused = 0
local replayBTN, playBTN, menuBTN, jumpBTN, instance1, instance2
–move background
local function muoviSfondo()
bg1.x = bg1.x-velocita
bg2.x = bg2.x-velocita
if(bg1.x<-712)then
bg1.x = bg2.x+1423
end
if(bg2.x<-712)then
bg2.x = bg1.x+1423
end
end
–pausa
local function pause(event)
if(event.phase == “began” and gameIsPaused == 0) then
velocita = 0
physics.pause()
instance1:pause()
instance2:pause()
replayBTN.alpha = 1
playBTN.alpha = 1
menuBTN.alpha = 1
gameIsPaused = 1
jumpBTN.alpha = 0
end
end
–resume
local function resume()
velocita = 1
physics.start()
instance1:play()
instance2:play()
velocita = 1
replayBTN.alpha = 0
playBTN.alpha = 0
menuBTN.alpha = 0
gameIsPaused = 0
jumpBTN.alpha = 0.01
end
–replay
local function replay()
playBTN.alpha = 0
replayBTN.alpha = 0
menuBTN.alpha = 0
physics.pause()
composer.gotoScene(“game”)
end
–menu
local function gotoMenu()
playBTN.alpha = 0
replayBTN.alpha = 0
menuBTN.alpha = 0
composer.gotoScene(“menu”)
end
–salto
local function up(event)
if(event.phase == “began” and playerHasJumped == 0) then
instance1:setLinearVelocity(0, -1700)
instance1:pause()
playerHasJumped = 1
elseif(event.phase == “began” and playerHasJumped == 1) then
instance1:setLinearVelocity(0, -1000)
playerHasJumped = 2
end
end
–collisioni
local function onCollision( event )
if ( event.phase == “began” ) then
playerHasJumped = 0
instance1:play()
elseif ( event.phase == “ended” ) then
end
end
– “scene:create()”
function scene:create( event )
local sceneGroup = self.view
jumpBTN = display.newImage(“immagini/jump.png”); jumpBTN.x = _W/2-900; jumpBTN.y = _H/2; jumpBTN.alpha = 0.01
pauseBTN = display.newImage(“immagini/pauseBTN.png”); pauseBTN.x = _W/2+660; pauseBTN.y = _H/2-360; pauseBTN.xScale = 0.2; pauseBTN.yScale = 0.2
replayBTN = display.newImage(“immagini/replayBTN.png”); replayBTN.x = _W/2+200; replayBTN.y = _H/2; replayBTN.xScale = 0.07; replayBTN.yScale = 0.07; replayBTN.alpha = 0
playBTN = display.newImage(“immagini/playBtn.png”); playBTN.x = _W/2; playBTN.y = _H/2; playBTN.xScale = 1; playBTN.yScale = 1; playBTN.alpha = 0
menuBTN = display.newImage(“immagini/menuBtn.png”); menuBTN.x = _W/2-200; menuBTN.y = _H/2; menuBTN.xScale = 0.2; menuBTN.yScale = 0.2; menuBTN.alpha = 0
--background
local bg1 = display.newImage(“immagini/bg1.png”); bg1.x = _W/2; bg1.y = _H/2
local bg2 = display.newImage(“immagini/bg2.png”); bg2.x = _W/2+1423; bg2.y = _H/2
local rect = display.newRect(_W/2,_H-40,_W,100)
rect:setFillColor(255,0,0)
rect.myName = “rect”
physics.addBody( rect, “static”, { friction=0.5, bounce=0 } )
local sheet1 = graphics.newImageSheet( “immagini/sprite.png”, { width=135, height=259, numFrames=14 } )
instance1 = display.newSprite( sheet1, { name=“cat”, start=1, count=14, time=550 } )
instance1.x = _W/2-400
instance1.y = _H/2+180
instance1.myName = “instance1”
instance1:play()
physics.addBody( instance1, “dynamic”, { friction=0.5, bounce=0 } )
local sheet2 = graphics.newImageSheet( “immagini/profDonna.png”, { width=149, height=320, numFrames=8 } )
instance2 = display.newSprite( sheet2, { name=“profDonna”, start=1, count=8, time=800 } )
instance2.x = _W/2
instance2.y = _H/2+150
instance2.myName = “instance2”
instance2:play()
physics.addBody( instance2, “dynamic”, { friction=0.5, bounce=0 } )
sceneGroup:insert(bg1)
sceneGroup:insert(bg2)
sceneGroup:insert(rect)
sceneGroup:insert(instance1)
sceneGroup:insert(instance2)
sceneGroup:insert(jumpBTN)
sceneGroup:insert(pauseBTN)
sceneGroup:insert(replayBTN)
sceneGroup:insert(playBTN)
sceneGroup:insert(menuBTN)
Runtime:addEventListener(“enterFrame”, muoviSfondo)
pauseBTN:addEventListener(“touch”, pause)
playBTN:addEventListener(“touch”, resume)
replayBTN:addEventListener(“touch”, replay)
menuBTN:addEventListener(“touch”, gotoMenu)
jumpBTN:addEventListener(“touch”,up)
Runtime:addEventListener( “collision”, onCollision )
end
– “scene:show()”
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
bg1.x = _W/2; bg1.y = _H/2
bg2.x = _W/2+1423; bg2.y = _H/2
instance1:play()
instance2:play()
physics.start()
velocita = 1
Runtime:addEventListener(“enterFrame”, muoviSfondo)
instance1.x = _W/2-400; instance1.y = _H/2+180
gameIsPaused = 0
playerHasJumped = 0
end
end
– “scene:hide()”
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
elseif ( phase == “did” ) then
physics.stop()
end
end
– “scene:destroy()”
function scene:destroy( event )
local sceneGroup = self.view
end
– Listener setup
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene
[/lua]
Or something like that…
Rob