joelwe

Untitled

Mar 19th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.20 KB | None | 0 0
  1. function onLocalPreCollision( event )
  2.     --Some code
  3.    elseif (not event.target.Skipped or event.target.Skipped == event.other) and event.other.myName == "sensor" then
  4.         if event.contact ~= nil then
  5.             event.contact.isEnabled = false
  6.             event.target.Skipped = event.other
  7.             if event.target.name == "copter" then
  8.                    timer.performWithDelay(1000, function(event) startParas(event.target) end, 1, false)
  9.              end
  10.         end
  11.    end
  12. end
  13.  
  14. function setUpSensor()
  15.     local attacher = display.newRect( 0, 0, 0, 20)
  16.     attacher.myName = "attacher"
  17.     attacher.x = display.contentWidth -15
  18.     attacher.y = 0
  19.     physics.addBody(attacher, "static")
  20.    
  21.     local sensor = display.newRect( 0, 0, 1, display.contentHeight - 50)
  22.     sensor.myName = "sensor"
  23.     sensor.x = display.contentWidth -15
  24.     sensor.y = display.contentHeight / 2
  25.     physics.addBody(sensor, "dynamic", collisionTable.sensorProp)
  26.    
  27.     myJoint = physics.newJoint( "distance", attacher, sensor, attacher.x, attacher.y, sensor.x,sensor.y )
  28. end
  29.  
  30. function createEnemy()
  31.     --...Some code...
  32.     enemy.name = enemyName
  33.     enemy:addEventListener( "preCollision", onLocalPreCollision )
  34.     --...Some more code...
  35. end
  36.  
  37. function startParas(copter)
  38.  
  39.   local paraNum = math.random(1, 5)
  40.     if paraNum > 0 then
  41.         timer.performWithDelay(150, function(event) createPara(copter) end, paraNum, false)
  42.     end
  43. end
  44.  
  45. function createPara(copter)
  46.     if copter.x ~= nil then
  47.         --Check to see if the copter is in the scene before the parachuter jumps
  48.         if tonumber(copter.x) > 50 and tonumber(copter.x) < 470 then
  49.             if copter.isAlive then
  50.                 local paraChuter = getSprite( spriteData.paraChuterData )
  51.                 paraChuter.name = getSpriteName( spriteData.paraChuterData )
  52.                 paraChuter.x = copter.x-10
  53.                 paraChuter.y = copter.y+5
  54.                 physics.addBody(paraChuter, "dynamic", physicsData:get("paraglider"))
  55.                 paraChuter:play()
  56.                 paraChuter.isFixedRotation = true
  57.                 paraChuter.linearDamping = 5
  58.             end
  59.         end                            
  60.     end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment