OK! This is my code (main.lua -> start.lua -> escenaPelota.lua -> start.lua -> …)
main.lua:
[lua]display.setStatusBar(display.HiddenStatusBar)
local composer = require (“composer”)
composer.gotoScene(“start”, {effect = “fade”, time = 500})[/lua]
start.lua:
[lua]-- Escena Start
–oculta la barra de arriba
display.setStatusBar(display.HiddenStatusBar)
local composer = require (“composer”)
local scene = composer.newScene()
local fondo
local pelotaGirando
local function cambiarEscena()
composer.gotoScene(“escenaPelota”, {effect = “slideLeft”, time = 1000})
end
local sonidoPelotaCayendo = audio.loadStream( “sonidoambienteCortado.ogg”)
audio.play(sonidoPelotaCayendo, { channel=2, loops=0})
audio.setVolume(1)
– create()
function scene:create( event )
local sceneGroup = self.view
– Code here runs when the scene is first created but has not yet appeared on screen
fondo = display.newImageRect( “Imagenes/fondoAro1.png”,320,480)
fondo.x = 160
fondo.y = 240
sceneGroup:insert(fondo)
end
– show()
function scene:show(event)
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == “did” ) then
pelotaGirando = display.newImageRect(“Imagenes/pelotaBasketIntroConLogo2.png”, 50,50)
pelotaGirando.x = 160
pelotaGirando.y = 290
transition.to( pelotaGirando, { xScale = 6.25, yScale = 6.25, rotation = 360 * 6, time = 2000} )
sceneGroup:insert(pelotaGirando)
pelotaGirando:addEventListener(“tap”,cambiarEscena)
end
end
– hide()
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Code here runs when the scene is on screen (but is about to go off screen)
elseif ( phase == “did” ) then
– Code here runs immediately after the scene goes entirely off screen
end
end
– destroy()
function scene:destroy( event )
local sceneGroup = self.view
– Code here runs prior to the removal of scene’s view
--composer.removeScene(“start”)
end
– Scene event function listeners
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene[/lua]
escenaPelota.lua:
[lua]-- Escena de Pelotas
–oculta la barra de arriba
display.setStatusBar(display.HiddenStatusBar)
local composer = require (“composer”)
local scene = composer.newScene()
local fisica
–fisica.setDrawMode(“hybrid”)
– Fondo –
local fondo
– Fondo –
– limites de la pantalla –
local piso
local techo
local paredIzq
local paredDer
– limites de la pantalla –
– Pelota Basket –
local pelotaB
– Pelota Basket –
– Pelotas Futbol –
local pelotaFutbol1
local pelotaFutbol2
local pelotaFutbol3
local pelotaFutbol4
local pelotaFutbol5
local pelotaFutbol6
local pelotaFutbol7
local pelotaFutbol8
local pelotaFutbol9
local pelotaFutbol10
– Pelotas Futbol –
– Aro –
local aro
– Aro –
– Barra vertical a la izquierda del aro –
local barraV
– Barra vertical a la izquierda del aro –
– Barra horizontal bajo el aro –
local barraH
– Barra horizontal bajo el aro –
– Barrita colision dentro del aro –
local barritaColision
– Barrita colision dentro del aro –
– Sonidos –
local sonidoDeFondo
– Sonidos –
local function sonidoPelotaFutbol()
media.playEventSound(“sonidopelota.wav”)
end
function moverPelotaBasket(event)
local pelota = event.target
pelota:applyLinearImpulse(0,-0.1,event.x,event.y)
end
local function moverPelotaFutbol(event)
local pelota2 = event.target
pelota2:applyLinearImpulse(0,-0.1,event.x,event.y)
end
local function sonidoPelotaBasket()
media.playEventSound(“sonidopelotabasket.ogg”)
end
local function sonidoEmbocaPelotaFutbolError()
media.playEventSound(“sonidoerrorpelotafutbol.ogg”)
end
local function sonidoEmbocaPelotaBasket()
media.playEventSound(“pelotaBencestada.ogg”)
end
local function cambiarEscena()
composer.removeScene(“escenaPelota”)
composer.gotoScene(“start”, {effect = “slideRight”, time = 1000})
end
local function borrarPelotaFutbol1()
if (pelotaFutbol1 ~= nil) then
pelotaFutbol1:addEventListener(“collision”,sonidoEmbocaPelotaFutbolError)
pelotaFutbol1:removeSelf()
end
end
local function borrarPelotaFutbol2()
if (pelotaFutbol2 ~= nil) then
pelotaFutbol2:addEventListener(“collision”,sonidoEmbocaPelotaFutbolError)
pelotaFutbol2:removeSelf()
end
end
local function borrarPelotaFutbol3()
if (pelotaFutbol3 ~= nil) then
pelotaFutbol3:addEventListener(“collision”,sonidoEmbocaPelotaFutbolError)
pelotaFutbol3:removeSelf()
end
end
local function borrarPelotaFutbol4()
if (pelotaFutbol4 ~= nil) then
pelotaFutbol4:addEventListener(“collision”,sonidoEmbocaPelotaFutbolError)
pelotaFutbol4:removeSelf()
end
end
local function borrarPelotaFutbol5()
if (pelotaFutbol5 ~= nil) then
pelotaFutbol5:addEventListener(“collision”,sonidoEmbocaPelotaFutbolError)
pelotaFutbol5:removeSelf()
end
end
local function borrarPelotaFutbol6()
if (pelotaFutbol6 ~= nil) then
pelotaFutbol6:addEventListener(“collision”,sonidoEmbocaPelotaFutbolError)
pelotaFutbol6:removeSelf()
end
end
local function borrarPelotaFutbol7()
if (pelotaFutbol7 ~= nil) then
pelotaFutbol7:addEventListener(“collision”,sonidoEmbocaPelotaFutbolError)
pelotaFutbol7:removeSelf()
end
end
local function borrarPelotaFutbol8()
if (pelotaFutbol8 ~= nil) then
pelotaFutbol18:addEventListener(“collision”,sonidoEmbocaPelotaFutbolError)
pelotaFutbol8:removeSelf()
end
end
local function borrarPelotaFutbol9()
if (pelotaFutbol9 ~= nil) then
pelotaFutbol9:addEventListener(“collision”,sonidoEmbocaPelotaFutbolError)
pelotaFutbol9:removeSelf()
end
end
local function borrarPelotaFutbol10()
if (pelotaFutbol10 ~= nil) then
pelotaFutbol10:addEventListener(“collision”,sonidoEmbocaPelotaFutbolError)
pelotaFutbol10:removeSelf()
end
end
local function finDelJuego()
pelotaB:addEventListener(“collision”,sonidoEmbocaPelotaBasket)
pelotaB:removeSelf()
--handleButtonEvent()
cambiarEscena()
end
local function onLocalCollision(self,event)
if (event.phase == “began” ) then
if (self.ID == “barrita”)
then if (event.other.ID == “pelota1”) then
borrarPelotaFutbol1()
end
if (event.other.ID == “pelota2”) then
borrarPelotaFutbol2()
end
if (event.other.ID == “pelota3”) then
borrarPelotaFutbol3()
end
if (event.other.ID == “pelota4”) then
borrarPelotaFutbol4()
end
if (event.other.ID == “pelota5”) then
borrarPelotaFutbol5()
end
if (event.other.ID == “pelota6”) then
borrarPelotaFutbol6()
end
if (event.other.ID == “pelota7”) then
borrarPelotaFutbol7()
end
if (event.other.ID == “pelota8”) then
borrarPelotaFutbol8()
end
if (event.other.ID == “pelota9”) then
borrarPelotaFutbol9()
end
if (event.other.ID == “pelota10”) then
borrarPelotaFutbol10()
end
if (event.other.ID == “pelotaB”) then
finDelJuego()
end
end
end
end
– FUNCIONES DE Escena-- create()
function scene:create( event )
local sceneGroup = self.view
– Code here runs when the scene is first created but has not yet appeared on screen
fisica = require(“physics”)
fisica.start()
fisica.setGravity(0,7)
--fisica.setDrawMode(“hybrid”)
fondo = display.newImageRect(“Imagenes/fondo3.jpg”,320,480)
fondo.x = 160
fondo.y = 240
piso = display.newRect(0,480,1000,0)
techo = display.newRect(0,0,1000,0)
paredIzq = display.newRect(0,0,0,1000)
paredDer = display.newRect(320,0,0,1000)
fisica.addBody(piso,“static”,{friction = 1.0})
fisica.addBody(techo,“static”,{friction = 1.0})
fisica.addBody(paredIzq,“static”,{friction = 1.0})
fisica.addBody(paredDer,“static”,{friction = 1.0})
pelotaB = display.newImageRect(“Imagenes/pelotabasket.png”,70,70)
pelotaB.x = 160
pelotaB.y = 300
fisica.addBody(pelotaB, {bounce = 0.5, radius = 35, friction = 1.0})
– Pelota Futbol 1 –
pelotaFutbol1 = display.newImageRect(“Imagenes/pelotafutbol.png”,60,60)
pelotaFutbol1.x = 30
pelotaFutbol1.y = 30
fisica.addBody(pelotaFutbol1, {radius = 30, friction = 0.1, bounce = 0.5})
– Pelota Futbol 1 –
– Pelota Futbol 2 –
pelotaFutbol2 = display.newImageRect(“Imagenes/pelotafutbol.png”,60,60)
pelotaFutbol2.x = 90
pelotaFutbol2.y = 30
fisica.addBody(pelotaFutbol2, {radius = 30, friction = 0.1, bounce = 0.5})
– Pelota Futbol 2 –
– Pelota Futbol 3 –
pelotaFutbol3 = display.newImageRect(“Imagenes/pelotafutbol.png”,60,60)
pelotaFutbol3.x = 30
pelotaFutbol3.y = 90
fisica.addBody(pelotaFutbol3, {radius = 30, friction = 0.1, bounce = 0.5})
– Pelota Futbol 3 –
– Pelota Futbol 4 –
pelotaFutbol4 = display.newImageRect(“Imagenes/pelotafutbol.png”,60,60)
pelotaFutbol4.x = 90
pelotaFutbol4.y = 90
fisica.addBody(pelotaFutbol4, {radius = 30, friction = 0.1, bounce = 0.5})
– Pelota Futbol 4 –
– Pelota Futbol 5 –
pelotaFutbol5 = display.newImageRect(“Imagenes/pelotafutbol.png”,60,60)
pelotaFutbol5.x = 30
pelotaFutbol5.y = 150
fisica.addBody(pelotaFutbol5, {radius = 30, friction = 0.1, bounce = 0.5})
– Pelota Futbol 5 –
– Pelota Futbol 6 –
pelotaFutbol6 = display.newImageRect(“Imagenes/pelotafutbol.png”,60,60)
pelotaFutbol6.x = 90
pelotaFutbol6.y = 150
fisica.addBody(pelotaFutbol6, {radius = 30, friction = 0.1, bounce = 0.5})
– Pelota Futbol 6 –
– Pelota Futbol 7 –
pelotaFutbol7 = display.newImageRect(“Imagenes/pelotafutbol.png”,60,60)
pelotaFutbol7.x = 30
pelotaFutbol7.y = 210
fisica.addBody(pelotaFutbol7, {radius = 30, friction = 0.1, bounce = 0.5})
– Pelota Futbol 7 –
– Pelota Futbol 8 –
pelotaFutbol8 = display.newImageRect(“Imagenes/pelotafutbol.png”,60,60)
pelotaFutbol8.x = 90
pelotaFutbol8.y = 210
fisica.addBody(pelotaFutbol8, {radius = 30, friction = 0.1, bounce = 0.5})
– Pelota Futbol 8 –
– Pelota Futbol 9 –
pelotaFutbol9 = display.newImageRect(“Imagenes/pelotafutbol.png”,60,60)
pelotaFutbol9.x = 30
pelotaFutbol9.y = 270
fisica.addBody(pelotaFutbol9, {radius = 30, friction = 0.1, bounce = 0.5})
– Pelota Futbol 9 –
– Pelota Futbol 10 –
pelotaFutbol10 = display.newImageRect(“Imagenes/pelotafutbol.png”,60,60)
pelotaFutbol10.x = 90
pelotaFutbol10.y = 270
fisica.addBody(pelotaFutbol10, {radius = 30, friction = 0.1, bounce = 0.5})
– Pelota Futbol 10 –
– Aro –
aro = display.newImageRect(“Imagenes/aro.png”,100,80)
aro.x = 270
aro.y = 160
– Aro –
– Barra vertical a la izquierda del aro –
barraV = display.newImageRect(“Imagenes/barraV.png”,2,80)
barraV.x = 220
barraV.y = 160
barraV.isVisible = false
fisica.addBody(barraV,“static”,{friction = 1.0})
– Barra vertical a la izquierda del aro –
– Barra horizontal bajo el aro –
barraH = display.newImageRect(“Imagenes/barraH.png”,80,2)
barraH.x = 260
barraH.y = 200
barraH.isVisible = false
fisica.addBody(barraH,“static”,{friction = 1.0})
– Barra horizontal bajo el aro –
– Barrita colision dentro del aro –
barritaColision = display.newImageRect(“Imagenes/barritacolision.png”,60,2)
barritaColision.x = 270
barritaColision.y = 190
barritaColision.isVisible = false
fisica.addBody(barritaColision,{friction = 1.0})
– Barrita colision dentro del aro –
sonidoDeFondo = audio.loadStream( “sonidoambiente.ogg”)
audio.play(sonidoDeFondo, { channel=1, loops=-1})
audio.setVolume(0.1)
barritaColision.ID = “barrita”
pelotaFutbol1.ID = “pelota1”
pelotaFutbol2.ID = “pelota2”
pelotaFutbol3.ID = “pelota3”
pelotaFutbol4.ID = “pelota4”
pelotaFutbol5.ID = “pelota5”
pelotaFutbol6.ID = “pelota6”
pelotaFutbol7.ID = “pelota7”
pelotaFutbol8.ID = “pelota8”
pelotaFutbol9.ID = “pelota9”
pelotaFutbol10.ID = “pelota10”
pelotaB.ID = “pelotaB”
end
– show()
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == “did” ) then
– Code here runs when the scene is entirely on screen
composer.removeScene(“start”)
pelotaB:addEventListener(“touch”,moverPelotaBasket)
pelotaFutbol1:addEventListener(“touch”,moverPelotaFutbol)
pelotaFutbol2:addEventListener(“touch”,moverPelotaFutbol)
pelotaFutbol3:addEventListener(“touch”,moverPelotaFutbol)
pelotaFutbol4:addEventListener(“touch”,moverPelotaFutbol)
pelotaFutbol5:addEventListener(“touch”,moverPelotaFutbol)
pelotaFutbol6:addEventListener(“touch”,moverPelotaFutbol)
pelotaFutbol7:addEventListener(“touch”,moverPelotaFutbol)
pelotaFutbol8:addEventListener(“touch”,moverPelotaFutbol)
pelotaFutbol9:addEventListener(“touch”,moverPelotaFutbol)
pelotaFutbol10:addEventListener(“touch”,moverPelotaFutbol)
pelotaFutbol1:addEventListener(“touch”,sonidoPelotaFutbol)
pelotaFutbol2:addEventListener(“touch”,sonidoPelotaFutbol)
pelotaFutbol3:addEventListener(“touch”,sonidoPelotaFutbol)
pelotaFutbol4:addEventListener(“touch”,sonidoPelotaFutbol)
pelotaFutbol5:addEventListener(“touch”,sonidoPelotaFutbol)
pelotaFutbol6:addEventListener(“touch”,sonidoPelotaFutbol)
pelotaFutbol7:addEventListener(“touch”,sonidoPelotaFutbol)
pelotaFutbol8:addEventListener(“touch”,sonidoPelotaFutbol)
pelotaFutbol9:addEventListener(“touch”,sonidoPelotaFutbol)
pelotaFutbol10:addEventListener(“touch”,sonidoPelotaFutbol)
pelotaB:addEventListener(“touch”,sonidoPelotaBasket)
barritaColision:addEventListener(“collision”,barritaColision)
barritaColision.collision = onLocalCollision
--pelotaGirando:addEventListener(“postCollision”,cambiarEscena)
--Runtime:addEventListener( “postCollision”, escenaAnterior )
end
end
– hide()
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Code here runs when the scene is on screen (but is about to go off screen)
elseif ( phase == “did” ) then
– Code here runs immediately after the scene goes entirely off screen
--pelotaB:removeEventListener(“touch”,moverPelotaBasket)
--pelotaFutbol1:removeEventListener(“touch”,moverPelotaFutbol)
--pelotaFutbol2:removeEventListener(“touch”,moverPelotaFutbol)
--pelotaFutbol3:removeEventListener(“touch”,moverPelotaFutbol)
--pelotaFutbol4:removeEventListener(“touch”,moverPelotaFutbol)
--pelotaFutbol5:removeEventListener(“touch”,moverPelotaFutbol)
--pelotaFutbol6:removeEventListener(“touch”,moverPelotaFutbol)
--pelotaFutbol7:removeEventListener(“touch”,moverPelotaFutbol)
--pelotaFutbol8:removeEventListener(“touch”,moverPelotaFutbol)
--pelotaFutbol9:removeEventListener(“touch”,moverPelotaFutbol)
--pelotaFutbol10:removeEventListener(“touch”,moverPelotaFutbol)
--pelotaFutbol1:removeEventListener(“touch”,sonidoPelotaFutbol)
--pelotaFutbol2:removeEventListener(“touch”,sonidoPelotaFutbol)
--pelotaFutbol3:removeEventListener(“touch”,sonidoPelotaFutbol)
--pelotaFutbol4:removeEventListener(“touch”,sonidoPelotaFutbol)
--pelotaFutbol5:removeEventListener(“touch”,sonidoPelotaFutbol)
--pelotaFutbol6:removeEventListener(“touch”,sonidoPelotaFutbol)
--pelotaFutbol7:removeEventListener(“touch”,sonidoPelotaFutbol)
--pelotaFutbol8:removeEventListener(“touch”,sonidoPelotaFutbol)
--pelotaFutbol9:removeEventListener(“touch”,sonidoPelotaFutbol)
--pelotaFutbol10:removeEventListener(“touch”,sonidoPelotaFutbol)
--pelotaB:removeEventListener(“touch”,sonidoPelotaBasket)
--barritaColision:removeEventListener(“collision”,barritaColision)
end
end
– destroy()
function scene:destroy( event )
local sceneGroup = self.view
– Code here runs prior to the removal of scene’s view
end
– Scene event function listeners
scene:addEventListener( “create”, scene )
scene:addEventListener( “show”, scene )
scene:addEventListener( “hide”, scene )
scene:addEventListener( “destroy”, scene )
return scene[/lua]