Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- sensor on the floor
- -- computer above the sensor
- -- monitor above the computer
- -- monitor can be any size
- -- make sure the whole setup is FACING north.
- -- the monitor must be facing north!
- os.loadAPI("ocs/apis/sensor")
- local sonic = sensor.wrap("bottom")
- local monitor = peripheral.wrap("top")
- local centerY = 0
- local centerZ = 0
- local width = 0
- local height = 0
- -- draw a block on the screen
- function drawBlock(block)
- local c = colors.white
- if block.Type == "SOLID" then
- c = colors.yellow
- elseif block.Type == "LIQUID" then
- c = colors.lightBlue
- end
- monitor.setBackgroundColor(c)
- monitor.setCursorPos(centerX - block.Position.X, centerY - block.Position.Z)
- monitor.write(" ")
- end
- -- forever...
- while true do
- -- get the monitor width and height (in case it changes, we'll do this every loop)
- width, height = monitor.getSize()
- -- find the center point
- centerX = width / 2;
- centerY = height / 2;
- -- get all the targets available
- local targets = sonic.getTargets()
- -- clear the monitor (to black)
- monitor.setBackgroundColor(colors.black)
- monitor.clear()
- -- draw the sensor block
- drawBlock({
- Position = {
- X = 0,
- Z = 0
- },
- Type = "SENSOR"
- });
- -- loop through all the data from the sensor
- for key, data in pairs(targets) do
- -- if the Y position is the same as the sensor
- if data.Position.Y == 0 then
- -- draw the block
- drawBlock(data)
- end
- end
- -- wait a second before doing it again
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement