Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pnpc = API.load("pnpc")
- local rng = API.load("rng")
- local classExpander = API.load("local_classExpander")
- local colliders = API.load("colliders")
- local expandedDefines = API.load("expandedDefines")
- local vectr = API.load("vectr");
- local movingplatform = {}
- movingplatform.horizonID = 299
- function movingplatform.onInitAPI()
- registerEvent(movingplatform, "onStart")
- registerEvent(movingplatform, "onTick")
- registerEvent(movingplatform, "onDraw")
- end
- function movingplatform.onStart()
- for _,v in pairs(NPC.get(movingplatform.horizonID)) do
- v.ai1 = 0;
- v.ai2 = 0;
- end
- end
- function movingplatform.onTick()
- if player:getStandingNPC() then
- Text.print(player:getStandingNPC().speedX,10,50)
- -- raycast arg 3
- local collisionTable = {}
- for k,v in ipairs(Block.getIntersecting(player.x - 128, player.y - 20 , player.x + player.width + 128, player.y + player.height + 20)) do
- if expandedDefines.BLOCK_SOLID_MAP[v.id] and not v.isHidden then
- table.insert(collisionTable, v)
- end
- end
- local platformvector = vectr.v2(player:getStandingNPC().speedX + (player.width*.5*math.sign(player:getStandingNPC().speedX)),player:getStandingNPC().speedY)*-1
- local side = 0
- if math.sign(player:getStandingNPC().speedX) > 0 then
- side = player.width
- end
- if(#collisionTable > 0) then
- local b,p,n,obj = colliders.raycast({player.x + player.width*0.5,player.y + player.height - 1},platformvector,collisionTable)
- Text.print(p,10,100)
- if p then
- --????
- end
- end
- end
- for _,v in ipairs(NPC.get({movingplatform.horizonID})) do
- if v:mem(0x64, FIELD_WORD) ~= -1 and not Defines.levelFreeze then
- local platform = pnpc.wrap(v)
- if (v:mem(0x12A, FIELD_WORD) ~= -1) and (platform.data.exists ~= nil) then
- if colliders.collide(platform.data.triggerCollider,player) and player:isGroundTouching() and v.ai1 == 0 and v.ai2 == 0 then
- v.ai1 = 2
- end
- if player.ForcedAnimationState == 0 then
- platform.data.triggerCollider.x = platform.data.triggerCollider.x + v.speedX
- if v.ai1 >= 2 then
- v.ai1 = v.ai1 + 1
- if v.ai1 <= 22 then
- v.speedX = .5 * platform.data.direction
- elseif v.ai1 > 18 and v.ai1 <= 50 then
- v.speedX = v.speedX + 0.5 * platform.data.direction
- elseif v.ai1 == 57 then
- v.speedX = 6 * platform.data.direction
- elseif v.ai1 == 58 then
- v.ai1 = 0
- v.ai2 = 2
- v.speedX = 0
- end
- end
- if v.ai2 >= 2 then
- v.ai2 = v.ai2 + 1
- if v.ai2 ==32 then
- v.speedX = -2 * platform.data.direction
- elseif v.ai2 == 192 then
- v.speedX = 0
- v.ai2 = 0
- end
- end
- else
- v.x = v.x - v.speedX
- end
- end
- end
- end
- end
- function movingplatform.onDraw()
- for _,v in ipairs(NPC.get({movingplatform.horizonID})) do
- if v:mem(0x64, FIELD_WORD) ~= -1 and not Defines.levelFreeze then
- local platform = pnpc.wrap(v)
- if platform.data.exists == nil then
- platform.data.exists = 0;
- platform.data.triggerCollider = colliders.Box(v.x,v.y-6,v.width,4)
- platform.data.direction = v.direction
- end
- if v.ai1 >= 2 or v.ai2 >= 2 then
- v.animationFrame = 1
- end
- end
- end
- end
- return movingplatform;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement