Advertisement
Guest User

turtle.lua

a guest
Jul 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. --[[
  2.     Turtle Tracking Program
  3.     by brad lmoah
  4. --]]
  5.  
  6. local w, h = term.getSize()
  7. local termC = term.current()
  8. local turtles = {} -- table of windows
  9.  
  10. function initScreen()
  11.     -- init bg
  12.     term.setBackgroundColor(colors.lightGray)
  13.     paintutils.drawFilledBox(0,0,w,h,colors.gray)
  14.     paintutils.drawFilledBox(0,0,w,1,colors.lightGray)
  15.    
  16.     term.setTextColor(colors.black)
  17.     term.setCursorPos(1,1)
  18.     term.write("Turtle Tracking")
  19.    
  20.     local width = w/2-1
  21.     local col2pos = width + 3
  22.    
  23.     turtles["farm1"] = window.create(termC,2,3,w/2-1,5,true)
  24.     turtles["farm2"] = window.create(termC,2,9,w/2-1,5,true)
  25.     turtles["farm3"] = window.create(termC,2,15,w/2-1,5,true)
  26.    
  27.     turtles["mine1"] = window.create(termC,col2pos,3,w/2-1,5,true)
  28.     turtles["mine2"] = window.create(termC,col2pos,9,w/2-1,5,true)
  29.     turtles["mine3"] = window.create(termC,col2pos,15,w/2-1,5,true)
  30.    
  31.     for k,v in pairs(turtles) do
  32.         term.redirect(v)
  33.         local tW,tH = term.getSize()
  34.         paintutils.drawFilledBox(0,0,w,h,colors.lightGray)
  35.         local posInit = vector.new(0,0,0)
  36.         updateText("N/A","N/A",posInit)
  37.     end
  38. end
  39.  
  40. function updateText(name,status,pos)
  41.     term.setTextColor(colors.black)
  42.     term.setCursorPos(2,2)
  43.     term.write("Name: "..name.."     ")
  44.     term.setCursorPos(2,3)
  45.     term.write("State: "..status.."     ")
  46.     term.setCursorPos(2,4)
  47.     term.write("Pos:("..pos.x..","..pos.y..","..pos.z..")     ")
  48. end
  49.  
  50. -- to do replace with protocols instead
  51. -- of hard coded id
  52. function updateScreen(id,msg)
  53.     if id == 27 then
  54.         term.redirect(turtles["farm1"])
  55.         updateText(msg[1],msg[2],msg[3])
  56.     elseif id == 43 then
  57.         term.redirect(turtles["mine1"])
  58.         updateText(msg[1],msg[2],msg[3])
  59.     elseif id == 42 then
  60.         term.redirect(turtles["mine2"])
  61.         updateText(msg[1],msg[2],msg[3])
  62.     end
  63.     term.redirect(termC)
  64. end
  65.    
  66. initScreen()
  67. rednet.open("top")
  68. while true do
  69.    local id,msg = rednet.receive()
  70.    updateScreen(id,msg)
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement