Guest User

Untitled

a guest
Oct 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. -- Array of controller modes. We will switch
  2. -- between the three of these randomly
  3. local mode = {"P1", "P2", "ZEN"}
  4. local current = mode[1]
  5.  
  6. -- Pre-made array for resetting the P1 joypad
  7. local reset = joypad.get(1)
  8. for k,v in pairs(reset) do
  9. reset[k] = ''
  10. end
  11.  
  12. -- Seed randomness when we start
  13. math.randomseed(os.time())
  14.  
  15. event.onframestart( function()
  16. local p1 = joypad.get(1)
  17. local p2 = joypad.get(2)
  18. local output = {}
  19.  
  20. if current == "P1" then
  21. output = p1
  22. elseif current == "P2" then
  23. output = p2
  24. else
  25. output = intersection(p1, p2)
  26. end
  27.  
  28. gui.drawText(0,0, current)
  29. -- gui.drawText(0,15, dump(output))
  30. joypad.set(output,1)
  31. end)
  32.  
  33. event.onframeend( function()
  34. joypad.set(reset, 1)
  35. end)
  36.  
  37. function intersection(p1, p2)
  38. local ret = {}
  39. for k,v in pairs(p1) do
  40. ret[k] = p1[k] and p2[k]
  41. end
  42. return ret
  43. end
  44.  
  45. -- Print all pressed buttons
  46. function dump(o)
  47. local s = ''
  48. for k,v in pairs(o) do
  49. if v then s = s .. tostring(k) .. ' ' end
  50. end
  51. return s
  52. end
  53.  
  54. --------------------------------------
  55. -- Main loop --
  56. --------------------------------------
  57. while true do
  58. -- Switch mode randomly twice a second
  59. -- This might become the same mode as we
  60. -- already had
  61. if emu.framecount() % 30 == 0 then
  62. current = mode[ math.random(1,3) ]
  63. end
  64.  
  65. emu.frameadvance()
  66. end
Add Comment
Please, Sign In to add comment