i dont know if i get it… i will show you my code and i will say to you what i dont to do in my game… my game will be of catch itens that will drop from heaven for do that you will need to use acelerometer to move a cauldron side to side to get them
sorry but i cant hide the code and i think you need look all to undersand what I wanted to say
[code]
function new()
local gameGroup = display.newGroup()
local hudGroup = display.newGroup()
– MODULE-SPECIFIC VARIABLES
local background = “bg.png”
– EXTERNAL MODULES / LIBRARIES
local tempo = require (“tempo”)
local movieclip = require( “movieclip” )
local physics = require “physics”
local ui = require(“ui”)
local score = require (“score”)
require “sprite”
local backgroundFilename1 = “bg.png”
local luaImage = “moon.png”
local clouds1
local clouds2
local clouds3
local clouds4
local gameIsActive = true
local TheTimer
local greenpoof
local poofTween
local hero
_G.cloudMoveSpeed = 0.5
_G.tempoSlowAtivado = false
local podeSlow = true
local caldeiraoMenor = false
local caldeiraoMaior = true
local desenhaCenario = function()
– --[[
– SPRITE –
local herosheet = sprite.newSpriteSheet(“person.png”, 32, 36)
– Our sprite sheet
– 32 is the width of each “box”, this is the image width divided by the number of images across
– 36 is the height of each “box”, this is the image height divided by the number of images down
local heroset = sprite.newSpriteSet (herosheet, 1, 12)
sprite.add (heroset, “heroleft”, 10, 3, 10, 0)
sprite.add (heroset, “heroright”, 4, 3, 300, 0)
sprite.add (heroset, “heroup”, 1, 3, 300, 0)
sprite.add (heroset, “herodown”, 7, 3, 300, 0)
– The sprite set uses images 1 to 12 (all of them)
– “heroup” starts at image 1 and includes 3 frames. (In this case 1, 2, 3.)
– The “300” indicates .3 seconds per frame, the “0” indicates it will repeat until we stop it.
local hero = sprite.newSprite (heroset)
hero.x = 160
hero.y = 200
– We insert out hero sprite
hero:prepare(“herodown”)
– We prepare the sprite
]]–
local motiony = 0
– local function onAccelerate( event )
motiony = event.yGravity * -60
end
– if gameIsActive then
Runtime:addEventListener (“accelerometer”, onAccelerate)
end
– local function movecaldeirao (event)
if gameIsActive then
caldeirao.x = caldeirao.x + motiony
– hero:prepare(“heroleft”)
– hero:play(“heroleft”)
end
end
– if gameIsActive then
Runtime:addEventListener(“enterFrame”, movecaldeirao)
end
– BACKGROUND
local background = display.newImageRect( backgroundFilename1, 480, 320 )
background:setReferencePoint( display.CenterLeftReferencePoint )
background.x = 0; background.y = 160
gameGroup:insert( background )
if caldeiraoMenor == false and caldeiraoMaior == false then
caldeirao = display.newImage ( “caldeirao.png”, 248, 86 )
caldeirao.x = 260; caldeirao.y = 280
caldeirao.type = “cauldron”
end
if caldeiraoMenor == true and caldeiraoMaior == false then
caldeirao = display.newImage ( “caldeirao.png”, 100,86 )
caldeirao.x = 260; caldeirao.y = 280
end
if caldeiraoMenor == false and caldeiraoMaior == true then
caldeirao = display.newImage ( “caldeirao.png”, 360,86 )
caldeirao.x = 260; caldeirao.y = 280
end
– LUA
local lua = display.newImageRect ( luaImage, 82, 84 )
lua.x = 250; lua.y = 70
gameGroup:insert ( lua )
– TREES
local treesLeft = display.newImageRect( “arvore_esquerda.png”, 334, 320 )
treesLeft.x = 150; treesLeft.y = 160
local treesRight = display.newImageRect( “arvore_direita.png”, 334, 320 )
treesRight.x = 400; treesRight.y = 160
gameGroup:insert( treesLeft )
gameGroup:insert( treesRight )
– CLOUDS
clouds1 = display.newImageRect( “clouds-left.png”, 480, 320 )
clouds1.x = 240; clouds1.y = 160
clouds2 = display.newImageRect( “clouds-right.png”, 480, 320 )
clouds2.x = 720; clouds2.y = 160
clouds3 = display.newImageRect( “clouds-left.png”, 480, 320 )
clouds3.x = 1200; clouds3.y = 160
clouds4 = display.newImageRect( “clouds-right.png”, 480, 320 )
clouds4.x = 1680; clouds4.y = 160
gameGroup:insert( clouds1 )
gameGroup:insert( clouds2 )
gameGroup:insert( clouds3 )
gameGroup:insert( clouds4 )
– TUMBAS
local tumba1 = display.newImageRect ( “tumba1.png”, 60, 60 )
tumba1.x = 50; tumba1.y = 278
local tumba2 = display.newImageRect ( “tumba2.png”, 80, 80 )
tumba2.x = 140; tumba2.y = 270
local tumba3 = display.newImageRect ( “tumba1.png”, 60, 60 )
tumba3.x = 210; tumba3.y = 278
local tumba4 = display.newImageRect ( “anjo.png”, 100, 90 )
tumba4.x = 300; tumba4.y = 290
local tumba5 = display.newImageRect ( “tumba1.png”, 60, 60 )
tumba5.x = 380; tumba5.y = 278
local tumba6 = display.newImageRect ( “tumba2.png”, 80, 80 )
tumba6.x = 446; tumba6.y = 270
gameGroup:insert( tumba1 )
gameGroup:insert( tumba2 )
gameGroup:insert( tumba3 )
gameGroup:insert( tumba4 )
gameGroup:insert( tumba5 )
gameGroup:insert( tumba6 )
– CHAO
local chao = display.newImageRect ( “grama.png”, 480, 26 )
chao.x = 240; chao.y = 307
gameGroup:insert( chao )
– CHAO FIXO
local groundShape = { -500, 4, 500, 4, 5000,30, -5000,30 }
physics.addBody( chao, “static”, { density=1.0, bounce=0, friction=38.5, shape=groundShape } )
– DRAW CAULDRON
gameGroup:insert( caldeirao )
if caldeiraoMenor == false and caldeiraoMaior == false then
local caldeiraoShape = { -20,-1, 20,-1, 20,1, -20,1 }
physics.addBody( caldeirao, “static”, { density=1.0, bounce=0, friction=38.5, shape=caldeiraoShape } )
end
if caldeiraoMenor and caldeiraoMaior == false then
local caldeiraoShape = { -10,-1, 10,-1, 10,1, -10,1 }
physics.addBody( caldeirao, “static”, { density=1.0, bounce=0, friction=38.5, shape=caldeiraoShape } )
end
if caldeiraoMenor == false and caldeiraoMaior == true then
local caldeiraoShape = { -500,-1, 500,-1, 500,1, -500,1 }
physics.addBody( caldeirao, “static”, { density=1.0, bounce=0, friction=38.5, shape=caldeiraoShape } )
end
– TEMPO
– local desenhaTempo = function ()
local border = 5
local tempoInfo = tempo.getInfo()
tempo.init({
x = 310,
y = 0}
)
end
desenhaTempo()
– hudGroup:insert( Tempoo )
if _G.easy then
tempo.setTempo(60)
end
if _G.normal then
tempo.setTempo(60)
end
if _G.hard then
tempo.setTempo(60)
end
if _G.hardest then
tempo.setTempo(60)
end
– local function addtoit (event)
if tempo.getTempo() >= 1 then
tempo.setTempo (tempo.getTempo()-1)
end
if tempo.getTempo() == 0 then
gameIsActive = false
timer.cancel ( timer1 )
timer.cancel ( E_bomb1Spawner )
physics.pause()
print ( gameIsActive )
if not shadeRect then
shadeRect = display.newRect( 0, 0, 480, 320 )
shadeRect:setFillColor( 0, 0, 0, 255 )
gameGroup:insert( shadeRect )
end
shadeRect.alpha = 0.8
local gameOverDisplay = display.newImageRect( “score_total.png”, 390, 300 )
gameOverDisplay.x = 240; gameOverDisplay.y = 150
local continueText = display.newText( score.getScore(), 240, 18, “Helvetica”, 36 )
continueText:setTextColor( 249, 203, 64, 255 )
continueText.x = 250; continueText.y = 215
local MenuBtn
local onMenuBtnTouch = function( event )
if event.phase == “release” and MenuBtn.isActive then
audio.play( tapSound )
–audio.stop( backgroundSound )
–audio.dispose( backgroundSound ); backgroundSound = nil
tempo.init({
x = 3100,
y = 0}
)
score.init({
x = 3100,
y = 0}
)
MenuBtn.isActive = false
director:changeScene( “loadmainmenu” )
end
end
MenuBtn = ui.newButton{
defaultSrc = “menubtn.png”,
defaultX = 60,
defaultY = 60,
overSrc = “menubtn-over.png”,
overX = 60,
overY = 60,
onEvent = onMenuBtnTouch,
id = “MenuBtn”,
text = “”,
font = “Helvetica”,
textColor = { 255, 255, 255, 255 },
size = 16,
emboss = false
}
MenuBtn.x = 30; MenuBtn.y = 290
MenuBtn.isVisible = false
– gameGroup:insert( MenuBtn )
timer.performWithDelay( 200, function() MenuBtn.isVisible = true; end, 1 )
hudGroup:insert( gameOverDisplay )
hudGroup:insert( continueText )
hudGroup:insert( MenuBtn )
end
end
– if gameIsActive and _G.easy then
timer1 = timer.performWithDelay(1000,addtoit,0)
end
– if gameIsActive and _G.normal then
timer1 = timer.performWithDelay(800,addtoit,0)
end
– if gameIsActive and _G.hard then
timer1 = timer.performWithDelay(500,addtoit,0)
end
– if gameIsActive and _G.hardest then
timer1 = timer.performWithDelay(100,addtoit,0)
end
local border = 5
local scoreInfo = score.getInfo()
score.init({
x = -10,
y = -2}
)
score.setScore(0)
end
------------------- FIM DA FUNCAO DESENHA CENARIO -------------------
– local gameLoop = function()
if gameIsActive then
– MOVE CLOUDS SLOWLY
clouds1.x = clouds1.x - _G.cloudMoveSpeed
clouds2.x = clouds2.x - _G.cloudMoveSpeed
clouds3.x = clouds3.x - _G.cloudMoveSpeed
clouds4.x = clouds4.x - _G.cloudMoveSpeed
if clouds1.x <= -240 then
clouds1.x = 1680
end
if clouds2.x <= -240 then
clouds2.x = 1680
end
if clouds3.x <= -240 then
clouds3.x = 1680
end
if clouds4.x <= -240 then
clouds4.x = 1680
end
– END CLOUD MOVEMENT
end
end
local aaa = function ()
greenPoof = display.newImageRect( “bola.png”, 30, 30 )
greenPoof.alpha = 1.0
greenPoof.isVisible = false
– Insert objects into main group
gameGroup:insert( greenPoof )
end
– local SlowScreen = function ()
local tempoSlow
if not Slow then
Slow = display.newRect( 0, 0, 480, 320 )
Slow:setFillColor( 0, 0, 255, 255 )
gameGroup:insert( Slow )
end
Slow.alpha = 0.1
_G.cloudMoveSpeed = 0.1
physics.setGravity( 0, 5 )
podeSlow = false
_G.tempoSlowAtivado = true
–[[
if gameIsActive and _G.hardest and _G.tempoSlowAtivado == true then
E_bomb1Spawner = timer.performWithDelay(4000, E_bomb1Spawn, -1);
end
]]–
local SlowDel = function ()
if Slow then
Slow:removeSelf()
Slow = nil
end
if _G.hardest then
physics.setGravity( 0, 60 )
end
_G.tempoSlowAtivado = false
podeSlow = true
end
tempoSlow = timer.performWithDelay(5000,SlowDel,1)
end
local onImage1Collision = function ( self, event )
– print ( “bomba2” )
if( event.target.type == “bomba” and event.other.type == “cauldron” ) then
score.setScore (score.getScore()+5)
print ( “bomba” )
end
if podeSlow then
slowScreen = timer.performWithDelay(10,SlowScreen,1)
end
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage2Collision = function ( self )
– score.setScore (score.getScore()+15)
tempo.setTempo (tempo.getTempo()+15)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage3Collision = function ( self )
– score.setScore (score.getScore()+10)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage4Collision = function ( self )
– score.setScore (score.getScore()+20)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage5Collision = function ( self )
– score.setScore (score.getScore()+10)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage6Collision = function ( self )
– score.setScore (score.getScore()+25)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage7Collision = function ( self )
– score.setScore (score.getScore()+5)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage8Collision = function ( self )
– score.setScore (score.getScore()+20)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage9Collision = function ( self )
– score.setScore (score.getScore()+50)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage10Collision = function ( self )
– score.setScore (score.getScore()+15)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage11Collision = function ( self )
if caldeiraoMaior then
caldeiraoMaior = false
end
caldeiraoMenor = true
– score.setScore (score.getScore()+25)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
– local onImage12Collision = function ( self )
– score.setScore (score.getScore()+60)
– Poof code below –
if poofTween then transition.cancel( poofTween ); end
greenPoof.x = self.x; greenPoof.y = self.y
greenPoof.alpha = 0
greenPoof.isVisible = true
local fadePoof = function()
transition.to( greenPoof, { time=100, alpha=0 } )
end
poofTween = transition.to( greenPoof, { time=100, alpha=1.0, onComplete=fadePoof } )
self.parent:remove( self )
self = nil
end
local imagens = {}
imagens[1] = “vela.png”
imagens[2] = “vara.png”
imagens[3] = “potion.png”
imagens[4] = “potion2.png”
imagens[5] = “pena.png”
imagens[6] = “morcego.png”
imagens[7] = “gato.png”
imagens[8] = “chapeu.png”
imagens[9] = “aranha.png”
imagens[10] = “abobora.png”
imagens[11] = “caveira.png”
imagens[12] = “caveira2.png”
local ItensRandom = function()
local _H = display.contentHeight;
local _W = display.contentWidth;
function E_hit(bomb)
bomb:removeSelf();
end
function E_bomb1Spawn()
local E_bomb1
local index = math.random( 1, #imagens )
E_bomb1 = display.newImage ( imagens[index] )
E_bomb1.x = math.random( 20, 460 )
E_bomb1.y = math.random( -120, -10 )
E_bomb1.xScale = 1
E_bomb1.yScale = 1
E_bomb1.type = “bomba”
physics.addBody( E_bomb1, “dynamic”, { density=1, bounce=0, friction=0.5 } )
if index == 1 then E_bomb1.postCollision = onImage1Collision end
if index == 2 then E_bomb1.postCollision = onImage2Collision end
if index == 3 then E_bomb1.postCollision = onImage3Collision end
if index == 4 then E_bomb1.postCollision = onImage4Collision end
if index == 5 then E_bomb1.postCollision = onImage5Collision end
if index == 6 then E_bomb1.postCollision = onImage6Collision end
if index == 7 then E_bomb1.postCollision = onImage7Collision end
if index == 8 then E_bomb1.postCollision = onImage8Collision end
if index == 9 then E_bomb1.postCollision = onImage9Collision end
if index == 10 then E_bomb1.postCollision = onImage10Collision end
if index == 11 then E_bomb1.postCollision = onImage11Collision end
if index == 12 then E_bomb1.postCollision = onImage12Collision end
hudGroup:insert( E_bomb1 )
E_bomb1:addEventListener( “postCollision”, E_bomb1 )
end
if gameIsActive then
E_bomb1Spawn()
end
–SpawnTimer
– if gameIsActive and _G.easy and _G.tempoSlowAtivado == false then
E_bomb1Spawner = timer.performWithDelay(2000, E_bomb1Spawn, -1);
end
– if gameIsActive and _G.normal and _G.tempoSlowAtivado == false then
E_bomb1Spawner = timer.performWithDelay(1000, E_bomb1Spawn, -1);
end
– if gameIsActive and _G.hard and _G.tempoSlowAtivado == false then
E_bomb1Spawner = timer.performWithDelay(500, E_bomb1Spawn, -1);
end
– if gameIsActive and _G.hardest and _G.tempoSlowAtivado == false then
E_bomb1Spawner = timer.performWithDelay(100, E_bomb1Spawn, -1);
end
– local reorderLayers = function()
hudGroup:toFront()
end
reorderLayers()
end
physics.start()
physics.setDrawMode( “normal” ) – set to “debug” or “hybrid” to see collision boundaries
– if _G.easy then
physics.setGravity( 0, 5 ) --> 0, 9.8 = Earth-like gravity
end
– if _G.normal then
physics.setGravity( 0, 10 ) --> 0, 9.8 = Earth-like gravity
end
– if _G.hard then
physics.setGravity( 0, 30 ) --> 0, 9.8 = Earth-like gravity
end
– if _G.hardest then
physics.setGravity( 0, 60 ) --> 0, 9.8 = Earth-like gravity
end
desenhaCenario()
ItensRandom()
aaa()
Runtime:addEventListener( “enterFrame”, gameLoop )
– unloadMe = function()
– STOP PHYSICS ENGINE
physics.stop()
– REMOVE EVENT LISTENERS
Runtime:removeEventListener( “enterFrame”, gameLoop )
for i = hudGroup.numChildren,1,-1 do
local child = hudGroup[i]
child.parent:remove( child )
child = nil
end
–[[
– Stop any transitions
if ghostTween then transition.cancel( ghostTween ); end
if poofTween then transition.cancel( poofTween ); end
if swipeTween then transition.cancel( swipeTween ); end
– Stop any timers
if restartTimer then timer.cancel( restartTimer ); end
if continueTimer then timer.cancel( continueTimer ); end
]]–
end
– MUST return a display.newGroup()
return gameGroup
end
[/code] [import]uid: 23063 topic_id: 9992 reply_id: 36478[/import]