Advertisement
Guest User

Untitled

a guest
Feb 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. local pnpc = API.load("pnpc")
  2. local rng = API.load("rng")
  3. local classExpander = API.load("local_classExpander")
  4. local colliders = API.load("colliders")
  5. local expandedDefines = API.load("expandedDefines")
  6. local vectr = API.load("vectr");
  7.  
  8. local movingplatform = {}
  9.  
  10. movingplatform.horizonID = 299
  11.  
  12. function movingplatform.onInitAPI()
  13. registerEvent(movingplatform, "onStart")
  14. registerEvent(movingplatform, "onTick")
  15. registerEvent(movingplatform, "onDraw")
  16. end
  17.  
  18. function movingplatform.onStart()
  19. for _,v in pairs(NPC.get(movingplatform.horizonID)) do
  20. v.ai1 = 0;
  21. v.ai2 = 0;
  22. end
  23. end
  24.  
  25. function movingplatform.onTick()
  26. if player:getStandingNPC() then
  27. Text.print(player:getStandingNPC().speedX,10,50)
  28. -- raycast arg 3
  29. local collisionTable = {}
  30. for k,v in ipairs(Block.getIntersecting(player.x - 128, player.y - 20 , player.x + player.width + 128, player.y + player.height + 20)) do
  31. if expandedDefines.BLOCK_SOLID_MAP[v.id] and not v.isHidden then
  32. table.insert(collisionTable, v)
  33. end
  34. end
  35.  
  36.  
  37. local platformvector = vectr.v2(player:getStandingNPC().speedX + (player.width*.5*math.sign(player:getStandingNPC().speedX)),player:getStandingNPC().speedY)*-1
  38.  
  39. local side = 0
  40. if math.sign(player:getStandingNPC().speedX) > 0 then
  41. side = player.width
  42. end
  43.  
  44. if(#collisionTable > 0) then
  45. local b,p,n,obj = colliders.raycast({player.x + player.width*0.5,player.y + player.height - 1},platformvector,collisionTable)
  46. Text.print(p,10,100)
  47. if p then
  48. --????
  49. end
  50. end
  51. end
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58. for _,v in ipairs(NPC.get({movingplatform.horizonID})) do
  59. if v:mem(0x64, FIELD_WORD) ~= -1 and not Defines.levelFreeze then
  60. local platform = pnpc.wrap(v)
  61.  
  62. if (v:mem(0x12A, FIELD_WORD) ~= -1) and (platform.data.exists ~= nil) then
  63.  
  64. if colliders.collide(platform.data.triggerCollider,player) and player:isGroundTouching() and v.ai1 == 0 and v.ai2 == 0 then
  65. v.ai1 = 2
  66. end
  67.  
  68. if player.ForcedAnimationState == 0 then
  69. platform.data.triggerCollider.x = platform.data.triggerCollider.x + v.speedX
  70. if v.ai1 >= 2 then
  71. v.ai1 = v.ai1 + 1
  72. if v.ai1 <= 22 then
  73. v.speedX = .5 * platform.data.direction
  74. elseif v.ai1 > 18 and v.ai1 <= 50 then
  75. v.speedX = v.speedX + 0.5 * platform.data.direction
  76. elseif v.ai1 == 57 then
  77. v.speedX = 6 * platform.data.direction
  78. elseif v.ai1 == 58 then
  79. v.ai1 = 0
  80. v.ai2 = 2
  81. v.speedX = 0
  82. end
  83. end
  84. if v.ai2 >= 2 then
  85. v.ai2 = v.ai2 + 1
  86. if v.ai2 ==32 then
  87. v.speedX = -2 * platform.data.direction
  88. elseif v.ai2 == 192 then
  89. v.speedX = 0
  90. v.ai2 = 0
  91. end
  92. end
  93. else
  94. v.x = v.x - v.speedX
  95. end
  96.  
  97. end
  98. end
  99. end
  100. end
  101.  
  102. function movingplatform.onDraw()
  103. for _,v in ipairs(NPC.get({movingplatform.horizonID})) do
  104. if v:mem(0x64, FIELD_WORD) ~= -1 and not Defines.levelFreeze then
  105. local platform = pnpc.wrap(v)
  106. if platform.data.exists == nil then
  107. platform.data.exists = 0;
  108. platform.data.triggerCollider = colliders.Box(v.x,v.y-6,v.width,4)
  109. platform.data.direction = v.direction
  110. end
  111. if v.ai1 >= 2 or v.ai2 >= 2 then
  112. v.animationFrame = 1
  113. end
  114. end
  115. end
  116. end
  117.  
  118. return movingplatform;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement