paramus

Turtle Controller

Aug 12th, 2025 (edited)
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.51 KB | Gaming | 0 0
  1. --rednet.open("back")
  2. local Stopped = true
  3. local Fuel = 200
  4. local MaxFuel = 1000
  5.  
  6. function PaintScreen()
  7.     term.setBackgroundColor(colors.white)
  8.     term.clear()
  9.     paintutils.drawFilledBox(1,1, 26,20, colors.black)
  10.    
  11.     -- Fuel level
  12.     term.setCursorPos(1,1)
  13.     write("Fuel")
  14.     paintutils.drawLine(1,2, 26,2, colors.gray)
  15.     paintutils.drawLine(1,2, (Fuel/MaxFuel)*26,2, colors.green)
  16.    
  17.     --Up
  18.     paintutils.drawPixel(12, 4, colors.green)
  19.     term.setCursorPos(12,4)
  20.     write("\24")
  21.    
  22.     --Turn Left
  23.     paintutils.drawPixel(10, 6, colors.green)
  24.     term.setCursorPos(10,6)
  25.     write("\17")
  26.    
  27.     --Stop/Go
  28.     if (Stopped) then
  29.         paintutils.drawPixel(12, 6, colors.red)
  30.     else
  31.         paintutils.drawPixel(12, 6, colors.green)
  32.     end
  33.     term.setCursorPos(12,6)
  34.     write("\7")
  35.    
  36.     -- Turn Right
  37.     paintutils.drawPixel(14, 6, colors.green)
  38.     term.setCursorPos(14,6)
  39.     write("\16")
  40.    
  41.     -- Down
  42.     paintutils.drawPixel(12, 8, colors.green)
  43.     term.setCursorPos(12,8)
  44.     write("\25")
  45.    
  46.     -- Down
  47.     paintutils.drawLine(2,10, 7,10, colors.green)
  48.     term.setCursorPos(2,10)
  49.     write("Refuel")
  50.    
  51.     -- Inventory
  52.     for ix=1,8,2 do
  53.         for iy=1,8,2 do
  54.             paintutils.drawPixel(18+ix, 11+iy, colors.yellow)
  55.         end
  56.     end
  57.    
  58. end
  59.  
  60. function CheckButton(x,y)
  61.     -- Missing inventory buttons
  62.    
  63.     if (x == 12 and y == 4) then --Up
  64.         rednet.broadcast("Up")
  65.     elseif (x == 12 and y == 8) then --Down
  66.         rednet.broadcast("Down")
  67.     elseif (x == 10 and y == 6) then --Left
  68.         rednet.broadcast("Left")
  69.     elseif (x == 14 and y == 6) then --Right
  70.         rednet.broadcast("Right")
  71.     elseif (x == 12 and y == 6) then --Stop/Go
  72.         if (Stopped == true) then
  73.             rednet.broadcast("Go")
  74.             Stopped = false
  75.         else
  76.             rednet.broadcast("Stop")
  77.             Stopped = true
  78.         end
  79.     end
  80. end
  81.  
  82. function GetData()
  83.     --Fuel
  84.     rednet.broadcast("GetFuel")
  85.     local id, msg = rednet.receive()
  86.     if (msg ~= nil) then
  87.         Fuel = msg
  88.     end
  89.    
  90.     --Max fuel
  91.     rednet.broadcast("GetMaxFuel")
  92.     id, msg = rednet.receive()
  93.     if (msg ~= nil) then
  94.         MaxFuel = msg
  95.     end
  96.    
  97.     --Is Digging
  98.     rednet.broadcast("IsDigging")
  99.     id, msg = rednet.receive()
  100.     if (msg ~= nil) then
  101.         Stopped = not msg
  102.     end
  103. end
  104.  
  105. peripheral.find("modem", rednet.open)
  106. while(true) do
  107.     --GetData()
  108.     PaintScreen()
  109.     local event, button, x, y = os.pullEvent("mouse_click")
  110.     CheckButton(x,y)
  111. end
Advertisement
Add Comment
Please, Sign In to add comment