Advertisement
Guest User

flagpole_exit

a guest
Nov 3rd, 2015
380
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.73 KB | None | 0 0
  1. --======================
  2. -- FLagpole Exit API
  3. --======================
  4.  
  5. local flagpole_exit = {}
  6.  
  7. -- Constants
  8. local POLE_POSITION = {} --top of flagpole
  9. local POLE_SECTION = -1
  10. local FLAG_SONG = ""
  11. local SLIDE_LENGTH = -1
  12. local FANFARE_LENGTH = -1
  13. local EXIT_SPEED = -1.0
  14.  
  15. -- Flags
  16. local normal = false
  17. local slide = false
  18. local ending = false
  19. local warpOut = false
  20.  
  21. -- Main Function
  22. function run()
  23.     if normal and
  24.     (player.x >= POLE_POSITION[1] - 32) and
  25.     (player.y >= POLE_POSITION[2]) and
  26.     (player.section == POLE_SECTION - 1) then
  27.         normal = false
  28.         slide = true
  29.        
  30.         Misc.npcToCoins() --end level enemy kill
  31.        
  32.         player.speedX = 0 --halt player
  33.         player.speedY = 0
  34.        
  35.         Audio.SeizeStream(POLE_SECTION - 1)
  36.         Audio.MusicOpen(FLAG_SONG)
  37.         Audio.MusicPlay()
  38.     end
  39.    
  40.     -- Hold slide state until fanfare, then open pole and start ending
  41.     if slide then
  42.         player.speedY = 4
  43.         SLIDE_LENGTH = SLIDE_LENGTH - 1
  44.     end
  45.     if slide and SLIDE_LENGTH == 0 then
  46.         slide = false
  47.         ending = true
  48.        
  49.         local yFlag = Layer.get("Flag")
  50.         local nFlag = Layer.get("NoFlag")
  51.         yFlag:toggle(true)
  52.         nFlag:toggle(true)
  53.     end
  54.    
  55.     -- Walk right until fanfare complete, then wait for warp
  56.     if ending then
  57.         player.speedX = EXIT_SPEED
  58.         FANFARE_LENGTH = FANFARE_LENGTH - 1
  59.     end
  60.     if ending and FANFARE_LENGTH == 0 then
  61.         ending = false
  62.         warpOut = true
  63.         Audio.MusicStop()
  64.     end
  65. end
  66.  
  67. -- Control Locks
  68. function slideLock()
  69.     player.upKeyPressing = false
  70.     player.downKeyPressing = true
  71.     player.leftKeyPressing = false
  72.     player.rightKeyPressing = true
  73.     player.jumpKeyPressing = false
  74.     player.altJumpKeyPressing = false
  75.     player.runKeyPressing = false
  76.     player.altRunKeyPressing = false
  77.     player.pauseKeyPressing = false
  78. end
  79.  
  80. function endingLock()
  81.     player.upKeyPressing = false
  82.     player.downKeyPressing = false
  83.     player.leftKeyPressing = false
  84.     player.rightKeyPressing = true
  85.     player.jumpKeyPressing = false
  86.     player.altJumpKeyPressing = false
  87.     player.runKeyPressing = false
  88.     player.altRunKeyPressing = false
  89.     player.pauseKeyPressing = false
  90. end
  91.  
  92. function locks()
  93.     if slide then slideLock()
  94.     elseif ending then endingLock()
  95.     elseif warpOut then player.upKeyPressing = true --warp through exit door
  96.     end
  97. end
  98.  
  99. --register functions
  100. function flagpole_exit.onInitAPI()
  101.     registerEvent(flagpole_exit, "onLoop", "run")
  102.     registerEvent(flagpole_exit, "onInputUpdate", "locks")
  103. end
  104.  
  105. --constructor
  106. function flagpole_exit.init(polePosition,poleSection,flagSong,slideLength,fanfareLength,exitSpeed)
  107.     POLE_POSITION = polePosition
  108.     POLE_SECTION = poleSection or 1
  109.     FLAG_SONG = flagSong
  110.     SLIDE_LENGTH = slideLength or 90
  111.     FANFARE_LENGTH = fanfareLength or 420
  112.     EXIT_SPEED = exitSpeed or 0.32
  113.     normal = true
  114. end
  115.  
  116. return flagpole_exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement