skypop

MapDisplay

Sep 17th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("apis/blittle")
  2. local file = "map"
  3. local mon = peripheral.wrap("top")
  4. local bg = colors.black
  5. local img = blittle.shrink(paintutils.loadImage(file),bg)
  6. local padX,padY = 7,2
  7. local ed = peripheral.find("EntityDetector")
  8. local range,ox,oy,oz = 20,-586,20,126
  9.  
  10. local function drawBG()
  11.   mon.setBackgroundColor(bg)
  12.   mon.setTextScale(.5)
  13.   mon.clear()
  14.   blittle.draw(img,padX,padY,mon)
  15. end
  16.  
  17. local function pix(x,y,c)
  18.   c = c or "d" --lime=5 green=d
  19.   mon.setCursorPos(x,y)
  20.   mon.blit(" ","f","d")
  21.   mon.setBackgroundColor(bg)
  22. end
  23.  
  24. local function input()
  25.   local tx,ty = term.getCursorPos()
  26.   local _i,_z,_y
  27.   while true do
  28.     term.setCursorPos(tx,ty)
  29.     term.clearLine()
  30.     term.write("Z= ")
  31.     _i = tonumber(read())
  32.     if not _i then
  33.       term.setCursorPos(tx,ty)
  34.       term.clearLine()
  35.       printError("Invalid Z coordinate")
  36.       sleep(.5)
  37.     else
  38.       _z = _i
  39.       break
  40.     end
  41.   end
  42.   while true do
  43.     term.setCursorPos(tx,ty+1)
  44.     term.clearLine()
  45.     term.write("Y= ")
  46.     _i = tonumber(read())
  47.     if not _i then
  48.       term.setCursorPos(tx,ty+1)
  49.       term.clearLine()
  50.       printError("Invalid Y coordinate")
  51.       sleep(.5)
  52.     else
  53.       _y = _i
  54.       break
  55.     end
  56.   end
  57.   return _z,_y
  58. end
  59.  
  60. local _2t = 2/3
  61. local function convert(x,y)
  62.   local _x = 18-(x - 118)
  63.   local _y = math.floor((24-(y - 7))*_2t+.5)
  64. --  print("Conv ("..x..","..y..")->(".._x..",".._y..")")
  65. --  drawBG()
  66. --  pix(_x+padX+1,_y+padY)
  67.   return _x+padX+1,_y+padY
  68. end
  69.  
  70. local function lookup()
  71.   local _x,_y
  72.   local list,_,e = ed.getEntityList(range,ox,oy,oz)
  73.   for _,mob in pairs(list) do
  74.     if mob.name=="Zombie" then
  75.       _x = math.floor(tonumber(mob.z))
  76.       _y = math.floor(tonumber(mob.y))
  77.       _x,_y = convert(_x,_y)
  78.       pix(_x,_y,colors.green)
  79.     end
  80.   end
  81. end
  82.  
  83. drawBG()
  84. local tick = os.startTimer(.1)
  85. local delay = .5
  86. while true do
  87.   local e,p,x,y = os.pullEvent("timer")
  88.   if e == "monitor_touch" then
  89.     os.cancelTimer(tick)
  90.     drawBG()
  91.     pix(x,y)
  92.     print("X:"..x.." | Y:"..y)
  93.     sleep(.2)
  94.     tick = os.startTimer(delay)
  95.   elseif e=="key" and p==keys.enter then
  96.     os.cancelTimer(tick)
  97.     local x,y = input()
  98.     convert(x,y,colors.lime)
  99.     tick = os.startTimer(delay)
  100.   elseif e=="timer" and p==tick then
  101.     drawBG()
  102.     lookup()
  103.     tick = os.startTimer(delay)
  104.   end
  105. end
Add Comment
Please, Sign In to add comment