Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --======================
- -- Flagpole Exit API
- --======================
- local flagpole_exit = {}
- -- Constants
- local POLE_POSITION = {} --top of flagpole
- local POLE_SECTION = -1
- local FLAG_SONG = ""
- local SLIDE_LENGTH = -1
- local FANFARE_LENGTH = -1
- local EXIT_SPEED = -1.0
- -- Flags
- local normal = false
- local slide = false
- local ending = false
- local warpOut = false
- -- Main Function
- function flagpole_exit.run()
- if normal and
- (player.x >= POLE_POSITION[1] - 32) and
- (player.y >= POLE_POSITION[2]) and
- (player.section == POLE_SECTION - 1) then
- normal = false
- slide = true
- Misc.npcToCoins() --end level enemy kill
- player.speedX = 0 --halt player
- player.speedY = 0
- Audio.SeizeStream(POLE_SECTION - 1)
- Audio.MusicOpen(FLAG_SONG)
- Audio.MusicPlay()
- end
- -- Hold slide state until fanfare, then open pole and start ending
- if slide then
- player.speedY = 4
- SLIDE_LENGTH = SLIDE_LENGTH - 1
- end
- if slide and SLIDE_LENGTH == 0 then
- slide = false
- ending = true
- local yFlag = Layer.get("Flag")
- local nFlag = Layer.get("NoFlag")
- yFlag:toggle(true)
- nFlag:toggle(true)
- end
- -- Walk right until fanfare complete, then wait for warp
- if ending then
- player.speedX = EXIT_SPEED
- FANFARE_LENGTH = FANFARE_LENGTH - 1
- end
- if ending and FANFARE_LENGTH == 0 then
- ending = false
- warpOut = true
- Audio.MusicStop()
- end
- end
- -- Control Locks
- local function slideLock()
- player.upKeyPressing = false
- player.downKeyPressing = true
- player.leftKeyPressing = false
- player.rightKeyPressing = true
- player.jumpKeyPressing = false
- player.altJumpKeyPressing = false
- player.runKeyPressing = false
- player.altRunKeyPressing = false
- player.pauseKeyPressing = false
- end
- local function endingLock()
- player.upKeyPressing = false
- player.downKeyPressing = false
- player.leftKeyPressing = false
- player.rightKeyPressing = true
- player.jumpKeyPressing = false
- player.altJumpKeyPressing = false
- player.runKeyPressing = false
- player.altRunKeyPressing = false
- player.pauseKeyPressing = false
- end
- function flagpole_exit.locks()
- if slide then slideLock()
- elseif ending then endingLock()
- elseif warpOut then player.upKeyPressing = true --warp through exit door
- end
- end
- --register functions
- function flagpole_exit.onInitAPI()
- registerEvent(flagpole_exit, "onLoop", "run")
- registerEvent(flagpole_exit, "onInputUpdate", "locks")
- end
- --constructor
- function flagpole_exit.init(polePosition,poleSection,flagSong,slideLength,fanfareLength,exitSpeed)
- POLE_POSITION = polePosition
- POLE_SECTION = poleSection or 1
- FLAG_SONG = flagSong
- SLIDE_LENGTH = slideLength or 90
- FANFARE_LENGTH = fanfareLength or 420
- EXIT_SPEED = exitSpeed or 0.32
- normal = true
- end
- return flagpole_exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement