Advertisement
Nike622000

Aufzug

Mar 30th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.54 KB | None | 0 0
  1. local monSide = "back"
  2. local Bcol    = colors.lightGray
  3. local Bside   = "front"
  4.  
  5. mon = peripheral.wrap(monSide)
  6. mon.setTextScale(.5)
  7.  
  8. local xMax,yMax = mon.getSize()
  9.  
  10. Button = {}
  11. Button[1] = {        2, 2, xMax/2-1, yMax-1,"Hoch"  ,colors.lime,false,colors.red}
  12. Button[2] = { xMax/2+1, 2, xMax-1  , yMax-1,"Runter",colors.red ,false,colors.yellow}
  13.  
  14. function Background(col)
  15.   mon.setBackgroundColor(col)
  16.   for yPos = 1,yMax do
  17.     for xPos = 1,xMax do
  18.       mon.setCursorPos(xPos,yPos)
  19.       mon.write(" ")
  20.     end
  21.   end
  22. end
  23.  
  24. function printButton()
  25.   for i = 1,#Button do
  26.     mon.setTextColor(colors.white)
  27.     mon.setBackgroundColor(Button[i][6])
  28.     for yPos = Button[i][2],Button[i][4] do
  29.       for xPos = Button[i][1],Button[i][3] do
  30.         mon.setCursorPos(xPos,yPos)
  31.         mon.write(" ")
  32.       end
  33.     end
  34.     mon.setCursorPos((Button[i][1]+Button[i][3])/2-#Button[i][5]/2,(Button[i][2]+Button[i][4])/2)
  35.     mon.write(Button[i][5])
  36.   end
  37. end
  38.  
  39. function checkButton(xP,yP)
  40.   for i = 1,#Button do
  41.     if xP >= Button[i][1] and xP <= Button[i][3]
  42.     and yP >= Button[i][2] and yP <= Button[i][4]
  43.     then
  44.       Button[i][7] = true
  45.     end
  46.   end
  47. end
  48.  
  49. function move()
  50.   for i = 1,#Button do
  51.     if Button[i][7] then
  52.       rs.setBundledOutput(Bside,Button[i][8])
  53.       sleep(.5)
  54.       rs.setBundledOutput(Bside,0)
  55.       Button[i][7] = false
  56.     end
  57.   end
  58. end
  59.  
  60. while true do
  61.   Background(Bcol)
  62.   printButton()
  63.   event,_,xPos,yPos = os.pullEvent("monitor_touch")
  64.   checkButton(xPos,yPos)
  65.   move()
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement