–pre-stats
display.setStatusBar(display.HiddenStatusBar)
local licensing = require( “licensing” )
licensing.init( “google” )
local ads = require( “ads” )
–physics
local physics = require(‘physics’)
physics.start()
--gravity
physics.setGravity(0, 1.8)
–background
local bg = display.newImage(“background.jpg”)
bg.x = 300
bg.y = 520
–objects
--player:
local ball = display.newImage(“ball.png”)
ball.x = 300
ball.y = 500
physics.addBody(ball, “dynamic”, {bounce = 0,5})
--obstacles:
local bad = display.newImage(“bad.png”)
bad.x = 0
bad.y = 900
physics.addBody(bad, “static”)
local bad2 = display.newImage(“bad.png”)
bad2.x = 0
bad2.y = 200
physics.addBody(bad2, “static”)
local bad3 = display.newImage(“bad.png”)
bad3.x = 650
bad3.y = 100
physics.addBody(bad3, “static”)
local bad4 = display.newImage(“bad.png”)
bad4.x = 650
bad4.y = 700
physics.addBody(bad4, “static”)
–events
function touchScreen(event)
if event.phase == “began” then
transition.to(ball, {time=1000, x=event.x, y=event.y})
end
end
Runtime:addEventListener(“touch”, touchScreen)
function movebad()
transition.to(bad,{time=2000, x=math.random(-100,900), y=math.random(80,880), onComplete=movebad})
transition.to(bad2,{time=2000, x=math.random(-100,900), y=math.random(80,880)})
transition.to(bad3,{time=2000, x=math.random(-100,900), y=math.random(80,880)})
transition.to(bad4,{time=2000, x=math.random(-100,900), y=math.random(80,880)})
end
movebad()
function onColision(event)
if ( event.phase == “began” ) then
ball:removeSelf()
end
end
Runtime:addEventListener(“collision”, onCollision)
function create(event)
if
ball:removeSelf() then
local ball2 = display.newImage(“ball.png”)
ball2.x = 0
ball2.y = 900
ball2.yScale = 0,4
ball2.xScale = 0,4
physics.addBody(ball2, “dynamic”)
end
end
Runtime:addEventListener(“collision”, create)
function touchScreen2(event)
if event.phase == “began” then
transition.to(ball2, {time=200, x=event.x, y=event.y})
end
end
Runtime:addEventListener(“touch”, touchScreen2)