Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function drawNewButton(label, color, ...)
- count = count + 1 or 1
- tx = (count%10)
- if tx == 0 then tx = 10 end
- ty = math.ceil(count/10)
- bcolor = colors[color]
- if arg[1] then tcolor = colors[arg[1]]
- else tcolor = colors.white end
- shell.run("makeButton", label, tx, ty, bcolor, tcolor)
- end
- function drawOutline(colX, rowY)
- shell.run("outline", colX, rowY)
- end
- function hitButton(hit)
- local posX = hit[3]
- local posY = hit[4]
- t1 = math.ceil(posX/10)
- t2 = math.ceil(posY/3)
- --Check for button and ignore
- test = (t2-1) * 10 + t1
- if test > count then return 0 end
- if (t1==col) and (t2==row) and pressed then
- --Retrieve ball and deselect
- sendCommand("PULL", selected)
- pressed = false
- selected = 0
- else --Retrieve ball if there is one
- if pressed then sendCommand("PULL", selected) end
- sleep(0.5)
- --Select and push ball
- pressed = true
- selected = (t2-1) * 10 + t1
- sendCommand("PUSH", selected)
- end
- col = t1
- row = t2
- print(selected)
- end
- function sendCommand(com, num)
- tab = {com, num}
- modem.transmit(10, 0, tab)
- end
- --Main starts here
- mon = peripheral.wrap("monitor_1")
- mon.setTextColor(colors.white)
- mon.setTextScale(0.5)
- modem = peripheral.wrap("back")
- modem.open(10)
- pressed = false
- selected = 0
- while true do
- --Reset screen
- mon.setBackgroundColor(colors.black)
- mon.clear()
- count = 0
- --Draw buttons
- drawNewButton("SHEEP", "gray")
- drawNewButton("COW", "brown")
- drawNewButton("CHICKEN", "white", "black")
- drawNewButton("PIG", "pink")
- drawNewButton("TEST5", "red")
- drawNewButton("TEST6", "blue")
- drawNewButton("TEST7", "red")
- drawNewButton("TEST8", "blue")
- drawNewButton("TEST9", "red")
- drawNewButton("TEST10", "blue")
- drawNewButton("TEST11", "red")
- drawNewButton("TEST12", "blue")
- --Currently selected option
- if pressed then
- drawOutline(col, row) end
- --Wait for touches
- event = {os.pullEvent("monitor_touch")}
- hitButton(event)
- sleep(0.5)
- end
Advertisement
Add Comment
Please, Sign In to add comment