Advertisement
Guest User

Rocket Booster Mk2

a guest
Jan 4th, 2014
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.90 KB | None | 0 0
  1. function init()
  2.   data.lastJump = false
  3.   data.lastBoost = nil
  4.   data.ranOut = false
  5.   data.active = false
  6. end
  7.  
  8. function input(args)
  9.   local currentJump = args.moves["jump"]
  10.   local currentBoost = nil
  11.  
  12.   if not tech.onGround() then
  13.     if not tech.canJump() and currentJump and not data.lastJump then
  14.       if args.moves["right"] and args.moves["up"] then
  15.         currentBoost = "boostRightUp"
  16.       elseif args.moves["right"] and args.moves["down"] then
  17.         currentBoost = "boostRightDown"
  18.       elseif args.moves["left"] and args.moves["up"] then
  19.         currentBoost = "boostLeftUp"
  20.       elseif args.moves["left"] and args.moves["down"] then
  21.         currentBoost = "boostLeftDown"
  22.       elseif args.moves["right"] then
  23.         currentBoost = "boostRight"
  24.       elseif args.moves["down"] then
  25.         currentBoost = "boostDown"
  26.       elseif args.moves["left"] then
  27.         currentBoost = "boostLeft"
  28.       elseif args.moves["up"] then
  29.         currentBoost = "boostUp"
  30.     end
  31.     elseif currentJump and data.lastBoost then
  32.       currentBoost = data.lastBoost
  33.     end
  34.   end
  35.  
  36.     if args.moves["special"] == 1 then
  37.         if not data.active then
  38.             return "activate"
  39.         else
  40.             return "deactivate"
  41.         end
  42.     end
  43.    
  44.     if args.moves["primaryFire"] then
  45.         return "doubleboost"
  46.     end
  47.  
  48.   data.lastJump = currentJump
  49.   data.lastBoost = currentBoost
  50.  
  51.   return currentBoost
  52. end
  53.  
  54. function update(args)
  55.   local boostControlForce = tech.parameter("boostControlForce")
  56.   local boostSpeed = tech.parameter("boostSpeed")
  57.   local energyUsagePerSecond = tech.parameter("energyUsagePerSecond")
  58.   local energyUsage = energyUsagePerSecond * args.dt
  59.  
  60.     if not data.active and args.actions["activate"] then
  61.         world.logInfo("activate")
  62.         tech.setToolUsageSuppressed(true)
  63.         data.active = true
  64.     elseif data.active and args.actions["deactivate"] then
  65.         world.logInfo("deactivate")
  66.         tech.setToolUsageSuppressed(false)
  67.         data.active = false
  68.     end
  69.    
  70.     if data.active and args.actions["doubleboost"] then
  71.         boostSpeed = tech.parameter("doubleboostSpeed")
  72.     end
  73.  
  74.   if args.availableEnergy < energyUsage then
  75.     data.ranOut = true
  76.   elseif tech.onGround() or tech.inLiquid() then
  77.     data.ranOut = false
  78.   end
  79.  
  80.   if not data.active and args.actions["activate"] then
  81.     world.logInfo("activate")
  82.     tech.setToolUsageSuppressed(true)
  83.     data.active = true
  84.   elseif data.active and args.actions["deactivate"] then
  85.     world.logInfo("deactivate")
  86.     tech.setToolUsageSuppressed(false)
  87.     data.active = false
  88.   end
  89.  
  90.   local boosting = false
  91.   local diag = 1 / math.sqrt(2)
  92.  
  93.   if not data.ranOut then
  94.     boosting = true
  95.     if args.actions["boostRightUp"] then
  96.       tech.control({boostSpeed * diag, boostSpeed * diag}, boostControlForce, true, true)
  97.     elseif args.actions["boostRightDown"] then
  98.       tech.control({boostSpeed * diag, -boostSpeed * diag}, boostControlForce, true, true)
  99.     elseif args.actions["boostLeftUp"] then
  100.       tech.control({-boostSpeed * diag, boostSpeed * diag}, boostControlForce, true, true)
  101.     elseif args.actions["boostLeftDown"] then
  102.       tech.control({-boostSpeed * diag, -boostSpeed * diag}, boostControlForce, true, true)
  103.     elseif args.actions["boostRight"] then
  104.       tech.control({boostSpeed, 0}, boostControlForce, true, true)
  105.     elseif args.actions["boostDown"] then
  106.       tech.control({0, -boostSpeed}, boostControlForce, true, true)
  107.     elseif args.actions["boostLeft"] then
  108.       tech.control({-boostSpeed, 0}, boostControlForce, true, true)
  109.     elseif args.actions["boostUp"] then
  110.       tech.control({0, boostSpeed}, boostControlForce, true, true)
  111.     else
  112.       boosting = false
  113.     end
  114.   end
  115.  
  116.   if boosting then
  117.     tech.setAnimationState("boosting", "on")
  118.     tech.setParticleEmitterActive("boostParticles", true)
  119.     return energyUsage
  120.   else
  121.     tech.setAnimationState("boosting", "off")
  122.     tech.setParticleEmitterActive("boostParticles", false)
  123.     return 0
  124.   end
  125. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement