Kryzeth

startup-sender

Oct 18th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. function drawNewButton(label, color, ...)
  2.   count = count + 1 or 1
  3.   tx = (count%10)
  4.   if tx == 0 then tx = 10 end
  5.   ty = math.ceil(count/10)
  6.   bcolor = colors[color]
  7.   if arg[1] then tcolor = colors[arg[1]]
  8.   else tcolor = colors.white end
  9.   shell.run("makeButton", label, tx, ty, bcolor, tcolor)
  10. end
  11.  
  12. function drawOutline(colX, rowY)
  13.   shell.run("outline", colX, rowY)
  14. end
  15.  
  16. function hitButton(hit)
  17.   local posX = hit[3]
  18.   local posY = hit[4]
  19.   t1 = math.ceil(posX/10)
  20.   t2 = math.ceil(posY/3)
  21.   --Check for button and ignore
  22.   test = (t2-1) * 10 + t1
  23.   if test > count then return 0 end
  24.   if (t1==col) and (t2==row) and pressed then
  25.     --Retrieve ball and deselect
  26.     sendCommand("PULL", selected)
  27.     pressed = false
  28.     selected = 0
  29.   else --Retrieve ball if there is one
  30.       if pressed then sendCommand("PULL", selected) end
  31.     sleep(0.5)
  32.     --Select and push ball
  33.     pressed = true
  34.     selected = (t2-1) * 10 + t1
  35.     sendCommand("PUSH", selected)
  36.   end
  37.   col = t1
  38.   row = t2
  39.   print(selected)
  40. end
  41.  
  42. function sendCommand(com, num)
  43.   tab = {com, num}
  44.   modem.transmit(10, 0, tab)
  45. end
  46.  
  47. --Main starts here
  48. mon = peripheral.wrap("monitor_1")
  49. mon.setTextColor(colors.white)
  50. mon.setTextScale(0.5)
  51. modem = peripheral.wrap("back")
  52. modem.open(10)
  53.  
  54. pressed = false
  55. selected = 0
  56.  
  57. while true do
  58.   --Reset screen
  59.   mon.setBackgroundColor(colors.black)
  60.   mon.clear()
  61.   count = 0
  62.   --Draw buttons
  63.   drawNewButton("SHEEP", "gray")
  64.   drawNewButton("COW", "brown")
  65.   drawNewButton("CHICKEN", "white", "black")
  66.   drawNewButton("PIG", "pink")
  67.   drawNewButton("TEST5", "red")
  68.   drawNewButton("TEST6", "blue")
  69.   drawNewButton("TEST7", "red")
  70.   drawNewButton("TEST8", "blue")
  71.   drawNewButton("TEST9", "red")
  72.   drawNewButton("TEST10", "blue")
  73.   drawNewButton("TEST11", "red")
  74.   drawNewButton("TEST12", "blue")
  75.  
  76.   --Currently selected option
  77.   if pressed then
  78.   drawOutline(col, row) end
  79.  
  80.   --Wait for touches
  81.   event = {os.pullEvent("monitor_touch")}
  82.   hitButton(event)
  83.  
  84.   sleep(0.5)
  85. end
Advertisement
Add Comment
Please, Sign In to add comment