Skip to content

Instantly share code, notes, and snippets.

@addieljuarez
Last active August 29, 2015 14:19
Show Gist options
  • Save addieljuarez/7eb824a81e688e54d3ce to your computer and use it in GitHub Desktop.
Save addieljuarez/7eb824a81e688e54d3ce to your computer and use it in GitHub Desktop.
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- Your code here
local physics = require('physics')
physics.start()
physics.setScale( 50 )
local game = display.newGroup( )
local circulo = display.newImage( 'gfx/exorcist.png' )
circulo.x = 250
game:insert( circulo )
local piso = display.newRect( 0, 650, 2048, 3)
game:insert( piso )
physics.addBody( circulo, 'dynamic', {friction=0.5, bounce=0.3, density = 1.0} )
physics.addBody( piso, 'static', {friction=0.5, bounce=0.3, density = 1.0})
for i=0,3 do
for j=0,1 do
local x = 600 + (120 *j)
local y = 50 +i * 160
local cuadros = display.newImage( 'gfx/block1.png')
cuadros.x = x
cuadros.y = y + 80
physics.addBody( cuadros, 'dynamic', {friction=0.5, bounce=0.3, density = 1.0} )
game:insert( cuadros )
if j<1 then
local cuadro2 = display.newImage( 'gfx/block1.png')
cuadro2.rotation = 90
cuadro2.x = x + 60
cuadro2.y = y
physics.addBody( cuadro2,'dynamic', {friction=0.5, bounce=0.3, density = 1.0} )
game:insert( cuadro2 )
end
end
end
function circuloTouch(event)
if event.phase == 'began' then
display.getCurrentStage( ):setFocus( circulo )
elseif event.phase == 'ended' then
circulo:applyLinearImpulse( event.xStart - event.x, event.yStart - event.y , circulo.x, circulo.y )
display.getCurrentStage( ):setFocus(nil)
end
end
circulo:addEventListener( 'touch', circuloTouch )
function loop()
game.x = 250 - circulo.x
end
Runtime:addEventListener( 'enterFrame', loop )
-- -----------------------------------------------------------------------------------------
-- --
-- -- main.lua
-- --
-- -----------------------------------------------------------------------------------------
-- -- Your code here
local physics = require('physics')
physics.start()
physics.setScale(50)
local game = display.newGroup()
local circulo = display.newImage('gfx/exorcist.png' ) --,200, 300) --display.newCircle( 200, 300, 40 )
circulo.x = 100
physics.addBody( circulo, 'dynamic', {friction=0.5, bounce=0.3, density=1, radius = 40} )
game:insert( circulo)
local piso = display.newRect(0, 700, 2048, 3 )
physics.addBody( piso, 'static', {friction=0.5, bounce=0, density=1, isSensor = false} )
game:insert( piso)
for i=0, 3 do
-- for j=0,1 do
for j=0, 1 do
local x = 600 + (120 * j)
-- x = 600
local y = 100 + i * 160
local pared = display.newImage('gfx/block1.png')
pared.x = x
pared.y = y + 80
physics.addBody( pared, 'dynamic', {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})
game:insert(pared)
if j < 1 then
local pared = display.newImage('gfx/block1.png')
pared.rotation = 90
pared.x = x + 60
pared.y = y
physics.addBody( pared, 'dynamic', {density = 1.0, friction = 0.3, bounce = 0.2, isSensor = false})
game:insert(pared)
end
end
end
function touchCirculo(event)
if event.phase == 'began' then
display.getCurrentStage( ):setFocus( circulo );
-- else (condition) then
elseif event.phase == 'ended' then
circulo:applyLinearImpulse( event.xStart - event.x , event.yStart - event.y , circulo.x, circulo.y )
display.getCurrentStage( ):setFocus(nil)
end
end
circulo:addEventListener( 'touch', touchCirculo )
function loop(e)
game.x = 200 - circulo.x
end
Runtime:addEventListener( 'enterFrame', loop )
-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------
-- Your code here
local physics = require('physics')
physics.start()
local circulo = display.newCircle( 250, 200, 40 )
local piso = display.newRect( 0, 600, 2048, 3)
physics.addBody( circulo, 'dynamic', {friction=0.5, bounce=0.3, density = 1.0} )
physics.addBody( piso, 'static', {friction=0.5, bounce=0.3, density = 1.0})
for i=0,7 do
local cuadros = display.newRect( 700, 450 + i*30, 70, 30 )
physics.addBody( cuadros, 'dynamic', {friction=0.5, bounce=0.3, density = 1.0} )
end
function circuloTouch(event)
if event.phase == 'began' then
display.getCurrentStage( ):setFocus( circulo )
elseif event.phase == 'ended' then
circulo:applyLinearImpulse( event.xStart - event.x, event.yStart - event.y , circulo.x, circulo.y )
display.getCurrentStage( ):setFocus(nil)
end
end
circulo:addEventListener( 'touch', circuloTouch )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment