Advertisement
Morok

Untitled

Jul 3rd, 2015
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.53 KB | None | 0 0
  1. -- sensor on the floor
  2. -- computer above the sensor
  3. -- monitor above the computer
  4. -- monitor can be any size
  5.  
  6. -- make sure the whole setup is FACING north.
  7. -- the monitor must be facing north!
  8.  
  9. os.loadAPI("ocs/apis/sensor")
  10.  
  11. local sonic = sensor.wrap("bottom")
  12.  
  13. local monitor = peripheral.wrap("top")
  14.  
  15. local centerY = 0
  16. local centerZ = 0
  17. local width = 0
  18. local height = 0
  19.  
  20.  
  21. -- draw a block on the screen
  22. function drawBlock(block)
  23.  
  24.   local c = colors.white
  25.  
  26.   if block.Type == "SOLID" then
  27.     c = colors.yellow  
  28.   elseif block.Type == "LIQUID" then
  29.     c = colors.lightBlue  
  30.   end
  31.  
  32.   monitor.setBackgroundColor(c)
  33.   monitor.setCursorPos(centerX - block.Position.X, centerY - block.Position.Z)
  34.   monitor.write(" ")
  35.  
  36. end
  37.  
  38.  
  39. -- forever...
  40. while true do
  41.  
  42.   -- get the monitor width and height (in case it changes, we'll do this every loop)  
  43.   width, height = monitor.getSize()
  44.  
  45.   -- find the center point
  46.   centerX = width / 2;
  47.   centerY = height / 2;
  48.  
  49.   -- get all the targets available
  50.   local targets = sonic.getTargets()
  51.  
  52.   -- clear the monitor (to black)
  53.   monitor.setBackgroundColor(colors.black)
  54.   monitor.clear()
  55.  
  56.   -- draw the sensor block
  57.   drawBlock({
  58.     Position =  {
  59.       X = 0,
  60.       Z = 0
  61.     },
  62.     Type = "SENSOR"
  63.   });
  64.  
  65.   -- loop through all the data from the sensor
  66.   for key, data in pairs(targets) do
  67.  
  68.     -- if the Y position is the same as the sensor
  69.     if data.Position.Y == 0 then
  70.  
  71.       -- draw the block
  72.       drawBlock(data)
  73.  
  74.     end
  75.  
  76.   end
  77.  
  78.   -- wait a second before doing it again
  79.   sleep(1)
  80.  
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement