Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rednet.open("left")
- maxx, maxy = term.getSize()
- xscale=0
- yscale=0
- xbounds = {}
- ybounds = {}
- entities = {}
- function termwrite(message)
- cx, cy = term.getCursorPos()
- mx, my = term.getSize()
- if(cy == my) then
- term.scroll(1)
- term.setCursorPos(1, cy)
- else
- term.setCursorPos(1, cy + 1)
- end
- term.write(message)
- end
- function parsedraw(message)
- separated=textutils.unserialize(message)
- id=separated[1]
- category=separated[2]
- position=textutils.unserialize(separated[3])
- updatebounds(position)
- updateentity(id, category, position)
- turtledraw()
- end
- function updateentity(id, category, position)
- local s=category
- if s == "T" then
- if (position[4]==0) then s="v"
- elseif(position[4]==1) then s="<"
- elseif(position[4]==2) then s="^"
- elseif(position[4]==3) then s=">" end
- end
- local coords={position[1],position[2],s}
- entities[id] = coords
- end
- function updatebounds(position)
- if(xbounds[1] == null) or (xbounds[1] > position[1]) then
- xbounds[1] = position[1]
- end
- if(xbounds[2] == null) or (xbounds[2] < position[1]) then
- xbounds[2] = position[1]
- end
- if(ybounds[1] == null) or (ybounds[1] > position[2]) then
- ybounds[1] = position[2]
- end
- if(ybounds[2] == null) or (ybounds[2] < position[2]) then
- ybounds[2] = position[2]
- end
- xscale=xbounds[2]-xbounds[1]
- yscale=ybounds[2]-ybounds[1]
- end
- function calccp(x, y)
- xcp = math.ceil(((x-xbounds[1])/xscale)*(maxx-1))+1
- ycp = math.ceil(((y-ybounds[1])/yscale)*(maxy-1))+1
- return xcp, ycp
- end
- function turtledraw()
- term.clear()
- for id, position in pairs(entities) do
- x,y = calccp(position[1],position[2])
- term.setCursorPos(x,y)
- term.write(position[3])
- end
- end
- term.clear()
- term.setCursorPos(1,0)
- termwrite("Listening...")
- while true do
- id, msg = rednet.receive()
- if id ~= null then
- parsedraw(msg)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment