Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ------------------------------------------------------------
- -- Name: RCMaster
- -- version: 1.1.6
- -- Author: Dustin Rosebery
- -- Description: Program that provides touchscreen turtle
- -- operation including movement, inventory,
- -- placing, and mining.
- -- setup: 4x4 advanced monitors with an advanced computer
- -- on the bottom of the monitors with a wireless
- -- modem on the right side. Also requires an
- -- advanced turtle with RCreceive installed
- -- and a wireless modem on the left side.
- ------------------------------------------------------------
- m = peripheral.wrap("top")
- modem = peripheral.wrap("right")
- m.clear()
- buttons = {}
- --------------------------------------------------
- -- button creation
- --------------------------------------------------
- -- Directional button background color
- dirColor = colors.red
- -- Inventory button background color
- invBackgroundColor = colors.white
- -- Inventory button text color
- invTextColor = colors.black
- ---------------------------------
- --Directional buttons
- ---------------------------------
- -- fbut (forward)
- fxMin = 23
- fxSize = 7
- fxMax = fxMin + fxSize - 1
- fyMin = 6
- fySize = 4
- fyMax = fyMin + fySize - 1
- fbut = window.create(m,fxMin,fyMin,fxSize,fySize)
- fbut.setBackgroundColor(dirColor)
- fbut.restoreCursor()
- fbut.redraw()
- fbut.setCursorPos(1,2)
- fbut.write("forward")
- -- bbut (backwards)
- bxMin = 23
- bxSize = 7
- bxMax = bxMin + bxSize - 1
- byMin = 12
- bySize = 4
- byMax = byMin + bySize - 1
- bbut = window.create(m,bxMin,byMin,bxSize,bySize)
- bbut.setBackgroundColor(dirColor)
- bbut.redraw()
- bbut.restoreCursor()
- bbut.setCursorPos(1,2)
- bbut.write(" back ")
- bbut.redraw()
- -- lbut (left)
- lxMin = 19
- lxSize = 7
- lxMax = lxMin + lxSize - 1
- lyMin = 9
- lySize = 4
- lyMax = lyMin + lySize - 1
- lbut = window.create(m,lxMin,lyMin,lxSize,lySize)
- lbut.setBackgroundColor(dirColor)
- lbut.redraw()
- lbut.setCursorPos(1,2)
- lbut.write(" left ")
- -- rbut (right)
- rxMin = 27
- rxSize = 7
- rxMax = rxMin + rxSize - 1
- ryMin = 9
- rySize = 4
- ryMax = ryMin + rySize - 1
- rbut = window.create(m,rxMin,ryMin,rxSize,rySize)
- rbut.setBackgroundColor(dirColor)
- rbut.redraw()
- rbut.setCursorPos(1,2)
- rbut.write(" right ")
- -- ubut (up)
- uxMin = 36
- uxSize = 2
- uxMax = uxMin + uxSize - 1
- uyMin = 7
- uySize = 3
- uyMax = uyMin + uySize - 1
- ubut = window.create(m,uxMin,uyMin,uxSize,uySize)
- ubut.setBackgroundColor(dirColor)
- ubut.restoreCursor()
- for i = 1, uySize do
- ubut.setCursorPos(1,i)
- ubut.write(" ")
- end
- m.setCursorPos(36,6)
- m.write("up")
- -- dbut (down)
- dxMin = 36
- dxSize = 2
- dxMax = dxMin + dxSize - 1
- dyMin = 11
- dySize = 3
- dyMax = dyMin + dySize - 1
- dbut = window.create(m,dxMin,dyMin,dxSize,dySize)
- dbut.setBackgroundColor(dirColor)
- dbut.restoreCursor()
- for i = 1, dySize do
- dbut.setCursorPos(1,i)
- dbut.write(" ")
- end
- m.setCursorPos(35,14)
- m.write("down")
- ----------------------------
- --Inventory Buttons
- ----------------------------
- invButtons = {}
- ixMin = 1 -- x_min
- ixSize = 14 -- x_width
- ixMax = ixMin + ixSize - 1 -- x_max
- iySize = 1 -- y_height
- -- sets initial inventory button parameters and inserts into global list
- function initInventoryButton(button)
- button.setBackgroundColor(invBackgroundColor)
- button.restoreCursor()
- button.setTextColor(invTextColor)
- button.setCursorPos(1,1)
- for i = 1, ixSize do
- button.write(" ")
- end
- table.insert(invButtons, button)
- end
- -- invLabel
- invLabelyMin = 1
- invLabel = window.create(m,ixMin,invLabelyMin,ixSize,iySize)
- invLabel.setTextColor(colors.white)
- invLabel.restoreCursor()
- invLabel.write("Inventory:")
- -- i1
- i1yMin = 2
- i1 = window.create(m,ixMin,i1yMin,ixSize,iySize)
- initInventoryButton(i1)
- -- i2
- i2yMin = 3
- i2 = window.create(m,ixMin,i2yMin,ixSize,iySize)
- initInventoryButton(i2)
- -- i3
- i3yMin = 4
- i3 = window.create(m,ixMin,i3yMin,ixSize,iySize)
- initInventoryButton(i3)
- -- i4
- i4yMin = 5
- i4 = window.create(m,ixMin,i4yMin,ixSize,iySize)
- initInventoryButton(i4)
- -- i5
- i5yMin = 6
- i5 = window.create(m,ixMin,i5yMin,ixSize,iySize)
- initInventoryButton(i5)
- -- i6
- i6yMin = 7
- i6 = window.create(m,ixMin,i6yMin,ixSize,iySize)
- initInventoryButton(i6)
- -- i7
- i7yMin = 8
- i7 = window.create(m,ixMin,i7yMin,ixSize,iySize)
- initInventoryButton(i7)
- -- i8
- i8yMin = 9
- i8 = window.create(m,ixMin,i8yMin,ixSize,iySize)
- initInventoryButton(i8)
- -- i9
- i9yMin = 10
- i9 = window.create(m,ixMin,i9yMin,ixSize,iySize)
- initInventoryButton(i9)
- -- i10
- i10yMin = 11
- i10 = window.create(m,ixMin,i10yMin,ixSize,iySize)
- initInventoryButton(i10)
- -- i11
- i11yMin = 12
- i11 = window.create(m,ixMin,i11yMin,ixSize,iySize)
- initInventoryButton(i11)
- -- i12
- i12yMin = 13
- i12 = window.create(m,ixMin,i12yMin,ixSize,iySize)
- initInventoryButton(i12)
- -- i13
- i13yMin = 14
- i13 = window.create(m,ixMin,i13yMin,ixSize,iySize)
- initInventoryButton(i13)
- -- i14
- i14yMin = 15
- i14 = window.create(m,ixMin,i14yMin,ixSize,iySize)
- initInventoryButton(i14)
- -- i15
- i15yMin = 16
- i15 = window.create(m,ixMin,i15yMin,ixSize,iySize)
- initInventoryButton(i15)
- -- i16
- i16yMin = 17
- i16 = window.create(m,ixMin,i16yMin,ixSize,iySize)
- initInventoryButton(i16)
- -- cleans item names by removing modID:
- function split(name)
- start, stop = string.find( name, ":" )
- result = string.sub( name, start+1, -1 )
- return result
- end
- -- initial inventory button display
- function initInventory()
- for i = 1, 16 do
- rednet.broadcast(i)
- senderID, message, protocol = rednet.receive()
- if message == "empty" then
- invButtons[i].restoreCursor()
- invButtons[i].setCursorPos(1,1)
- invButtons[i].write("<empty>")
- else
- output = split(message)
- invButtons[i].restoreCursor()
- invButtons[i].setCursorPos(1,1)
- invButtons[i].write(output)
- end
- end
- end
- -- updates inventory on inventory button click
- function updateInventory(index)
- senderID, message, protocol = rednet.receive()
- invButtons[index].clear()
- invButtons[index].redraw()
- invButtons[index].restoreCursor()
- invButtons[index].setCursorPos(1,1)
- if not message == "empty" then
- output = split(message)
- else
- output = ("<empty>")
- end
- invButtons[index].write(output)
- end
- ----------------------------------------------------------------------
- -- Input listener
- ----------------------------------------------------------------------
- while(true) do
- rednet.open("right")
- initInventory()
- event, side, xpos, ypos = os.pullEvent("monitor_touch")
- write(xpos .. ", " .. ypos.."\n") -- show touch location
- -- directional control
- if ( xpos >= fxMin and xpos <= fxMax and
- ypos >= fyMin and ypos <= fyMax )then
- rednet.broadcast("forward")
- elseif ( xpos >= bxMin and xpos <= bxMax and
- ypos >= byMin and ypos <= byMax )then
- rednet.broadcast("back")
- elseif ( xpos >= lxMin and xpos <= lxMax and
- ypos >= lyMin and ypos <= lyMax )then
- rednet.broadcast("left")
- elseif ( xpos >= rxMin and xpos <= rxMax and
- ypos >= ryMin and ypos <= ryMax )then
- rednet.broadcast("right")
- elseif ( xpos >= uxMin and xpos <= uxMax and
- ypos >= uyMin and ypos <= uyMax )then
- rednet.broadcast("up")
- elseif ( xpos >= dxMin and xpos <= dxMax and
- ypos >= dyMin and ypos <= dyMax )then
- rednet.broadcast("down")
- -- inventory control
- elseif ( xpos >= ixMin and xpos <= ixMax )then
- if ( ypos == i1yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i2yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i3yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i4yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i5yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i6yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i7yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i8yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i9yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i10yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i11yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i12yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i13yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i14yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i15yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- elseif( ypos == i16yMin ) then
- rednet.broadcast(ypos)
- updateInventory(ypos)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement