A-Vladimir

test 3

Jan 12th, 2020
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. require "/scripts/vec2.lua"
  2.  
  3. function init()
  4. self.holdingJump = false
  5. self.active = false
  6. self.flightControlForce = config.getParameter("flightControlForce")
  7. end
  8.  
  9. function input(args)
  10. if args.moves["jump"] and mcontroller.jumping() then
  11. self.holdingJump = true
  12. elseif not args.moves["jump"] then
  13. self.holdingJump = false
  14. end
  15.  
  16. if args.moves["jump"] and not mcontroller.canJump() and not self.holdingJump then
  17. return "angelflight"
  18. else
  19. return nil
  20. end
  21. end
  22.  
  23. function update(args)
  24. local action = input(args)
  25. local energyUsagePerSecond = config.getParameter("energyUsagePerSecond")
  26. local hDirection = args.moves["left"] and -1 or (args.moves["right"] and 1 or 0)
  27. local vDirection = args.moves["down"] and -1 or (args.moves["up"] and 1 or 0)
  28. local energyOff = (hDirection == 0 and vDirection == 0) and 0 or 1
  29.  
  30. if action == "angelflight" and (not status.statPositive("activeMovementAbilities")) and status.overConsumeResource("energy", energyUsagePerSecond * args.dt * energyOff) then
  31. animator.setAnimationState("wings", "fly")
  32.  
  33. --WING FACING DIRECTION
  34. if mcontroller.facingDirection() == -1 then
  35. --LOOKING LEFT
  36. animator.setGlobalTag("facingDirection", "left");
  37. else
  38. --LOOKING RIGHT
  39. animator.setGlobalTag("facingDirection", "right");
  40. end
  41.  
  42. local maxSpeed = math.min(20^0.6 + 25, 45)
  43. local angle = (hDirection ~= 0 or vDirection ~= 0) and vec2.angle({hDirection, vDirection}) or false
  44. local velocity = angle and vec2.withAngle(angle, maxSpeed) or {0,0}
  45. mcontroller.controlApproachVelocity(velocity, self.flightControlForce)
  46. if vDirection == 0 then mcontroller.controlApproachYVelocity(0, self.flightControlForce) end
  47.  
  48. if not self.active then
  49. end
  50. self.active = true
  51. else
  52. if self.active then
  53. mcontroller.controlApproachVelocity({0,0}, self.flightControlForce * 10)
  54. status.setResourceLocked("energy", energyOff == 0)
  55. end
  56. self.active = false
  57. status.setResourceLocked("energy", false)
  58. animator.setAnimationState("wings", "off")
  59. end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment