SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --Create n random parachuters |
| 1 | + | |
| 2 | local randX = math.random(100, 200) | |
| 3 | if copter.x ~= nil then | |
| 4 | if tonumber(copter.x) > 50 and tonumber(copter.x) < 470 then | |
| 5 | if copter.isAlive then | |
| 6 | local paraChuter = display.newSprite( getSheet( obj.paraChuter.paraGlide), getSequenceData.paraData ) | |
| 7 | paraChuter.x = copter.x-10 | |
| 8 | paraChuter.y = copter.y+5 | |
| 9 | paraChuter:play() | |
| 10 | paraChuter.name = "paraChuter" | |
| 11 | physics.addBody(paraChuter, "dynamic", physicsData:get("paraglider"))
| |
| 12 | paraChuter.isFixedRotation = true | |
| 13 | paraChuter.linearDamping = 5 | |
| 14 | end | |
| 15 | end | |
| 16 | end | |
| 17 | end | |
| 18 | ||
| 19 | local function onLocalPreCollision( event ) | |
| 20 | - | --Precollision |
| 20 | + | if not event.target.Skipped or event.target.Skipped == event.other then |
| 21 | event.contact.isEnabled = false | |
| 22 | - | if (not event.target.Skipped or event.target.Skipped == event.other) and event.other.myName == "platform1" then |
| 22 | + | event.target.Skipped = event.other |
| 23 | - | event.contact.isEnabled = false |
| 23 | + | end |
| 24 | - | event.target.Skipped = event.other |
| 24 | + | |
| 25 | ||
| 26 | function onCollision(self, event) | |
| 27 | ||
| 28 | - | --If bullet hits the parachuter |
| 28 | + | |
| 29 | if event.phase == "began" and (self.name == "bullet" and event.other.name == "paraChuter") then | |
| 30 | ||
| 31 | event.other:setSequence( "paraGlideHs" ) | |
| 32 | event.other.name = "paraGlideHs" | |
| 33 | ||
| 34 | - | event.other:setSequence( "paraDead" ) |
| 34 | + | |
| 35 | - | event.other.name = "paraDead" |
| 35 | + | |
| 36 | event.other.isFixedRotation = true | |
| 37 | event.other.linearDamping = 5 | |
| 38 | ||
| 39 | event.other:play() | |
| 40 | ||
| 41 | display.remove(self) | |
| 42 | self = nil | |
| 43 | end | |
| 44 | end | |
| 45 | ||
| 46 | function setUpCatchPlatform() | |
| 47 | ||
| 48 | local platform = display.newRect( 0, 0, display.contentWidth * 4, 0) | |
| 49 | - | --First platform (platform1) |
| 49 | + | |
| 50 | platform.x = (display.contentWidth / 2) | |
| 51 | platform.y = (display.contentHeight / 2) + 40 | |
| 52 | physics.addBody(platform, "static", collisionTable.firstParaPlatformProp) | |
| 53 | ||
| 54 | platform.collision = onCatchPlatformCollision | |
| 55 | platform:addEventListener( "collision", platform ) | |
| 56 | end | |
| 57 | ||
| 58 | function setUpCatchPlatform2() | |
| 59 | local platform2 = display.newRect( 0, 0, display.contentWidth * 4, 0) | |
| 60 | platform2.myName = "platform2" | |
| 61 | platform2.x = (display.contentWidth / 2) | |
| 62 | - | --Second platform (platform2) |
| 62 | + | |
| 63 | physics.addBody(platform2, "static", collisionTable.secondParaPlatformProp) | |
| 64 | ||
| 65 | platform2.collision = onCatchPlatformCollision2 | |
| 66 | platform2:addEventListener( "collision", platform2 ) | |
| 67 | end | |
| 68 | ||
| 69 | function onCatchPlatformCollision(self, event) | |
| 70 | if event.phase == "began" and event.other.name == "paraChuter" then | |
| 71 | ||
| 72 | if event.other ~= nil then | |
| 73 | event.other:setSequence( "paraLand" ) | |
| 74 | - | --Change the sequence gliding to landing |
| 74 | + | |
| 75 | ||
| 76 | local doCollision = function() | |
| 77 | physics.removeBody(event.other) | |
| 78 | physics.addBody(event.other, "dynamic", physicsData:get("paralander"))
| |
| 79 | event.other:play() | |
| 80 | end | |
| 81 | local collisionTimer = timer.performWithDelay( 1, doCollision, 1 ) | |
| 82 | - | event.other:addEventListener( "preCollision", onLocalPreCollision ) |
| 82 | + | |
| 83 | - | event.other:play() |
| 83 | + | |
| 84 | end | |
| 85 | end |