function createPara(copter)
local randX = math.random(100, 200)
if copter.x ~= nil then
if tonumber(copter.x) > 50 and tonumber(copter.x) < 470 then
if copter.isAlive then
local paraChuter = display.newSprite( getSheet( obj.paraChuter.paraGlide), getSequenceData.paraData )
paraChuter.x = copter.x-10
paraChuter.y = copter.y+5
paraChuter:play()
paraChuter.name = "paraChuter"
physics.addBody(paraChuter, "dynamic", physicsData:get("paraglider"))
paraChuter.isFixedRotation = true
paraChuter.linearDamping = 5
end
end
end
end
local function onLocalPreCollision( event )
if not event.target.Skipped or event.target.Skipped == event.other then
event.contact.isEnabled = false
event.target.Skipped = event.other
end
end
function onCollision(self, event)
---- if bullet hits parachuter
if event.phase == "began" and (self.name == "bullet" and event.other.name == "paraChuter") then
event.other:setSequence( "paraGlideHs" )
event.other.name = "paraGlideHs"
event.other:addEventListener( "preCollision", onLocalPreCollision )
event.other.isFixedRotation = true
event.other.linearDamping = 5
event.other:play()
display.remove(self)
self = nil
end
end
function setUpCatchPlatform()
local platform = display.newRect( 0, 0, display.contentWidth * 4, 0)
platform.myName = "platform1"
platform.x = (display.contentWidth / 2)
platform.y = (display.contentHeight / 2) + 40
physics.addBody(platform, "static", collisionTable.firstParaPlatformProp)
platform.collision = onCatchPlatformCollision
platform:addEventListener( "collision", platform )
end
function setUpCatchPlatform2()
local platform2 = display.newRect( 0, 0, display.contentWidth * 4, 0)
platform2.myName = "platform2"
platform2.x = (display.contentWidth / 2)
platform2.y = (display.contentHeight / 2) + 150
physics.addBody(platform2, "static", collisionTable.secondParaPlatformProp)
platform2.collision = onCatchPlatformCollision2
platform2:addEventListener( "collision", platform2 )
end
function onCatchPlatformCollision(self, event)
if event.phase == "began" and event.other.name == "paraChuter" then
if event.other ~= nil then
event.other:setSequence( "paraLand" )
event.other.name = "paraLander"
local doCollision = function()
physics.removeBody(event.other)
physics.addBody(event.other, "dynamic", physicsData:get("paralander"))
event.other:play()
end
local collisionTimer = timer.performWithDelay( 1, doCollision, 1 )
end
end
end
Comments