Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onLocalPreCollision( event )
- --Some code
- elseif (not event.target.Skipped or event.target.Skipped == event.other) and event.other.myName == "sensor" then
- if event.contact ~= nil then
- event.contact.isEnabled = false
- event.target.Skipped = event.other
- if event.target.name == "copter" then
- timer.performWithDelay(1000, function(event) startParas(event.target) end, 1, false)
- end
- end
- end
- end
- function setUpSensor()
- local attacher = display.newRect( 0, 0, 0, 20)
- attacher.myName = "attacher"
- attacher.x = display.contentWidth -15
- attacher.y = 0
- physics.addBody(attacher, "static")
- local sensor = display.newRect( 0, 0, 1, display.contentHeight - 50)
- sensor.myName = "sensor"
- sensor.x = display.contentWidth -15
- sensor.y = display.contentHeight / 2
- physics.addBody(sensor, "dynamic", collisionTable.sensorProp)
- myJoint = physics.newJoint( "distance", attacher, sensor, attacher.x, attacher.y, sensor.x,sensor.y )
- end
- function createEnemy()
- --...Some code...
- enemy.name = enemyName
- enemy:addEventListener( "preCollision", onLocalPreCollision )
- --...Some more code...
- end
- function startParas(copter)
- local paraNum = math.random(1, 5)
- if paraNum > 0 then
- timer.performWithDelay(150, function(event) createPara(copter) end, paraNum, false)
- end
- end
- function createPara(copter)
- if copter.x ~= nil then
- --Check to see if the copter is in the scene before the parachuter jumps
- if tonumber(copter.x) > 50 and tonumber(copter.x) < 470 then
- if copter.isAlive then
- local paraChuter = getSprite( spriteData.paraChuterData )
- paraChuter.name = getSpriteName( spriteData.paraChuterData )
- paraChuter.x = copter.x-10
- paraChuter.y = copter.y+5
- physics.addBody(paraChuter, "dynamic", physicsData:get("paraglider"))
- paraChuter:play()
- paraChuter.isFixedRotation = true
- paraChuter.linearDamping = 5
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment