Advertisement
Guest User

Untitled

a guest
Apr 26th, 2016
2,412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. MRADIUS=35
  2. CENTERX=128
  3. CENTERY=96
  4. DEADZONE=0.1
  5. RELEASE_TIMEOUT=5
  6. ENGAGE_TIMEOUT=10
  7.  
  8. function on_load(game)
  9. end
  10.  
  11. function on_unload()
  12. end
  13.  
  14. debounce = false
  15. enable = false
  16. release = 0
  17. engage = 0
  18.  
  19. function on_frame_update()
  20.  
  21.     local buttons = drastic.get_buttons()
  22.  
  23.     if ( ( buttons & drastic.C.BUTTON_L ) ~= 0 and ( buttons & drastic.C.BUTTON_R ) ~= 0) then
  24.         debounce = true
  25.     end
  26.  
  27.     if ( debounce and ( buttons & drastic.C.BUTTON_L ) == 0 and ( buttons & drastic.C.BUTTON_R ) == 0) then
  28.         debounce = false
  29.         enable = not enable
  30.     end
  31.  
  32.     if (enable) then
  33.         local lx = android.get_axis_lx()
  34.         local ly = android.get_axis_ly()
  35.         if ( ( buttons & drastic.C.BUTTON_Y ) ~= 0) then
  36.             buttons = buttons | drastic.C.BUTTON_A
  37.             buttons = buttons & (~drastic.C.BUTTON_Y)
  38.         end
  39.        
  40.         if( ( buttons & drastic.C.BUTTON_TOUCH) == 0) then
  41.             if (math.abs(lx)>DEADZONE) or (math.abs(ly)>DEADZONE) then
  42.                 if (engage >= ENGAGE_TIMEOUT) then
  43.                     local x = (MRADIUS)*lx
  44.                     local y = (MRADIUS)*ly
  45.                     local radius = math.min(math.sqrt(x*x+y*y),MRADIUS)
  46.                     local angle = math.atan2(x,y)
  47.                     drastic.set_touch(math.floor(math.sin(angle)*radius)+CENTERX,math.floor(math.cos(angle)*radius)+CENTERY)    
  48.                 else
  49.                     drastic.set_touch(CENTERX, CENTERY)
  50.                     engage = engage + 1
  51.                 end
  52.                 buttons = buttons | drastic.C.BUTTON_TOUCH
  53.                 release = 0
  54.             else
  55.                 if (release < RELEASE_TIMEOUT) then
  56.                     drastic.set_touch(CENTERX, CENTERY)
  57.                     buttons = buttons | drastic.C.BUTTON_TOUCH
  58.                     release = release + 1
  59.                 end
  60.                 engage = 0
  61.             end
  62.         end
  63.        
  64.         drastic.set_buttons(buttons)
  65.     end
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement