Advertisement
joelwe

parachuter

Mar 15th, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.98 KB | None | 0 0
  1. --Create n random parachuters
  2. function createPara(copter)
  3.     local randX = math.random(100, 200)
  4.     if copter.x ~= nil then
  5.         if tonumber(copter.x) > 50 and tonumber(copter.x) < 470 then
  6.             if copter.isAlive then
  7.                 local paraChuter = display.newSprite( getSheet( obj.paraChuter.paraGlide), getSequenceData.paraData )
  8.                 paraChuter.x = copter.x-10
  9.                 paraChuter.y = copter.y+5
  10.                 paraChuter:play()
  11.                 paraChuter.name = "paraChuter"
  12.                 physics.addBody(paraChuter, "dynamic", physicsData:get("paraglider"))
  13.                 paraChuter.isFixedRotation = true
  14.                 paraChuter.linearDamping = 5
  15.             end
  16.         end                            
  17.     end
  18. end
  19.  
  20. --Precollision
  21. local function onLocalPreCollision( event )
  22.     if (not event.target.Skipped or event.target.Skipped == event.other) and event.other.myName == "platform1" then
  23.         event.contact.isEnabled = false
  24.         event.target.Skipped = event.other
  25.     end
  26. end
  27.  
  28. --If bullet hits the parachuter
  29. function onCollision(self, event)
  30.    
  31.     ---- if bullet hits parachuter
  32.     if event.phase == "began" and (self.name == "bullet" and event.other.name == "paraChuter") then
  33.        
  34.         event.other:setSequence( "paraDead" )
  35.         event.other.name = "paraDead"
  36.  
  37.         event.other:addEventListener( "preCollision", onLocalPreCollision )
  38.  
  39.         event.other.isFixedRotation = true
  40.         event.other.linearDamping = 5
  41.        
  42.         event.other:play()
  43.        
  44.         display.remove(self)
  45.         self = nil
  46.      end
  47. end
  48.  
  49. --First platform (platform1)
  50. function setUpCatchPlatform()
  51.  
  52.     local platform = display.newRect( 0, 0, display.contentWidth * 4, 0)
  53.     platform.myName = "platform1"
  54.     platform.x =  (display.contentWidth / 2)
  55.     platform.y = (display.contentHeight / 2) + 40
  56.     physics.addBody(platform, "static", collisionTable.firstParaPlatformProp)
  57.  
  58.     platform.collision = onCatchPlatformCollision
  59.     platform:addEventListener( "collision", platform )
  60. end
  61.  
  62. --Second platform (platform2)
  63. function setUpCatchPlatform2()
  64.     local platform2 = display.newRect( 0, 0, display.contentWidth * 4, 0)
  65.     platform2.myName = "platform2"
  66.     platform2.x =  (display.contentWidth / 2)
  67.     platform2.y = (display.contentHeight / 2) + 150
  68.     physics.addBody(platform2, "static", collisionTable.secondParaPlatformProp)
  69.  
  70.     platform2.collision = onCatchPlatformCollision2
  71.     platform2:addEventListener( "collision", platform2 )
  72. end
  73.  
  74. --Change the sequence gliding to landing
  75. function onCatchPlatformCollision(self, event)
  76.     if event.phase == "began" and event.other.name == "paraChuter" then
  77.        
  78.         if event.other ~= nil then
  79.             event.other:setSequence( "paraLand" )
  80.             event.other.name = "paraLander"
  81.            
  82.             event.other:addEventListener( "preCollision", onLocalPreCollision )
  83.             event.other:play()
  84.         end
  85.    
  86.     end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement