Advertisement
skypop

RemoteController

Sep 15th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.82 KB | None | 0 0
  1. --@piloute33
  2. rednet.open("back") -- << Side du modem
  3. local channel = nil -- << ID de la Turtle
  4.  
  5. local display, btn
  6.  
  7. local function onclick(item,x,y)
  8.     return x >= item.x1
  9.     and x <= item.x2
  10.     and y >= item.y1
  11.     and y <= item.y2
  12. end
  13.  
  14. --Raccourcis
  15. local _r = string.rep
  16. local _c = string.char
  17.  
  18. if pocket then
  19.     local h=0
  20.     --GFX
  21.     display = function()
  22.     -- Résolution (pocket) : 26x20
  23.     -- +---------+-----------+
  24.     -- | Avancer | Reculer   |
  25.     -- +---------+-----------+
  26.     -- | Gauche  | Droite    |
  27.     -- +---------+-----------+
  28.     -- | Monter  | Descendre |
  29.     -- +---------+-----------+
  30.     -- | Casser  | Poser     |
  31.     -- +---------+-----------+
  32.     -- | Aspirer | Cracher   |
  33.     -- +---------+-----------+
  34.     -- | Quitter | Éteindre  |
  35.     -- +---------------------+
  36.         term.setCursorPos(1,2)
  37.         term.setTextColor(colors.white)
  38.         term.setBackgroundColor(colors.black)
  39.         local interline = _c(157).._r(_c(140),9).._c(157).._r(_c(140),11).._c(149)
  40.         print( string.format("  %s\n  channel: #%d\n"
  41.                 .."  %s\n"
  42.                 .."  %s Avancer %s Reculer   %s\n"
  43.                 .."  %s\n"
  44.                 .."  %s  Gauche %s Droite    %s\n"
  45.                 .."  %s\n"
  46.                 .."  %s  Monter %s Descendre %s\n"
  47.                 .."  %s\n"
  48.                 .."  %s  Casser %s Poser     %s\n"
  49.                 .."  %s\n"
  50.                 .."  %s Aspirer %s Cracher   %s\n"
  51.                 .."  %s\n"
  52.                 .."  %s Quitter %s Éteindre  %s\n"
  53.                 .."  %s\n",
  54.             shell.getRunningProgram(), channel,
  55.             _c(156).._r(_c(140),9).._c(156).._r(_c(140),11).._c(148),
  56.             _c(149), _c(149),  _c(149), interline,
  57.             _c(149), _c(149),  _c(149), interline,
  58.             _c(149), _c(149),  _c(149), interline,
  59.             _c(149), _c(149),  _c(149), interline,
  60.             _c(149), _c(149),  _c(149), interline,
  61.             _c(149), _c(149),  _c(149),
  62.             _c(141).._r(_c(140),9).._c(141).._r(_c(140),11).._c(133)
  63.            
  64.         ))
  65.     end
  66.     --hiboxes
  67.     btn = {
  68.         ["Avancer"]  ={x1= 4,x2=12,y1= 5,y2= 5},
  69.         ["Reculer"]  ={x1=14,x2=23,y1= 5,y2= 5},
  70.         ["Gauche"]   ={x1= 4,x2=12,y1= 7,y2= 7},
  71.         ["Droite"]   ={x1=14,x2=23,y1= 7,y2= 7},
  72.         ["Monter"]   ={x1= 4,x2=12,y1= 9,y2= 9},
  73.         ["Descendre"]={x1=14,x2=23,y1= 9,y2= 9},
  74.         ["Casser"]   ={x1= 4,x2=12,y1=11,y2=11},
  75.         ["Poser"]    ={x1=14,x2=23,y1=11,y2=11},
  76.         ["Aspirer"]  ={x1= 4,x2=12,y1=13,y2=13},
  77.         ["Cracher"]  ={x1=14,x2=23,y1=13,y2=13},
  78.         ["X"]        ={x1= 4,x2=12,y1=15,y2=15},
  79.         ["Eteindre"] ={x1=14,x2=23,y1=15,y2=15},
  80.     }
  81. else
  82.     --GFX
  83.     display = function()
  84.         local image = paintutils.loadImage("ig")
  85.         paintutils.drawImage(image , 1, 1)
  86.         term.setBackgroundColor(colors.red)
  87.         term.setCursorPos(8,3)
  88.         write("Avancé")
  89.         term.setCursorPos(23,3)
  90.         write("Cassé")
  91.         term.setCursorPos(37,3)
  92.         write("Reculé")
  93.         term.setCursorPos(8,8)
  94.         write("Monté")
  95.         term.setCursorPos(36,8)
  96.         write("Descendre")
  97.         term.setCursorPos(19,8)
  98.         write("Posé un bloc")
  99.         term.setCursorPos(8,13)
  100.         write("Gauche")
  101.         term.setCursorPos(36,13)
  102.         write("Droite")
  103.         term.setCursorPos(21,13)
  104.         write("Recupéré")
  105.         term.setCursorPos(48,1)
  106.         write("X")
  107.         term.setCursorPos(38,17)
  108.         write("Eteindre")
  109.         term.setCursorPos(1,1)
  110.         term.setBackgroundColor(colors.black)
  111.         term.setTextColor(colors.black)
  112.     end
  113.     --hitboxes
  114.     btn = {
  115.         ["Avancer"]  ={x1= 4,x2=17,y1= 2,y2= 5},
  116.         ["Casser"]   ={x1=19,x2=31,y1= 2,y2= 5},
  117.         ["Reculer"]  ={x1=33,x2=45,y1= 2,y2= 5},
  118.         ["Monter"]   ={x1= 4,x2=17,y1= 7,y2=10},
  119.         ["Descendre"]={x1=32,x2=47,y1= 7,y2=10},
  120.         ["Poser"]    ={x1=19,x2=31,y1= 7,y2=11},
  121.         ["Gauche"]   ={x1= 3,x2=17,y1=12,y2=16},
  122.         ["Droite"]   ={x1=33,x2=45,y1=12,y2=16},
  123.         ["Aspirer"]  ={x1=18,x2=31,y1=12,y2=16},
  124.         ["X"]        ={x1=47,x2=49,y1= 1,y2= 2},
  125.         ["Eteindre"] ={x1=36,x2=49,y1=17,y2=18},
  126.     }
  127. end
  128.  
  129. local _debug = false
  130. term.clear()
  131. display()
  132. while true do
  133.     local _, mouse, x, y = os.pullEvent("mouse_click")
  134.     term.setTextColor(colors.white)
  135.     if _debug then
  136.         if pocket then
  137.             term.setCursorPos(1,19) term.clearLine() term.write(_f("x:%d | y:%d",x,y))
  138.         else
  139.             print(x,y)
  140.         end
  141.     else
  142.         if onclick(btn["Avancer"], x, y) then
  143.             rednet.send(channel, "forward")  
  144.         elseif onclick(btn["Casser"], x, y) then
  145.             rednet.send(channel, "dig")
  146.         elseif onclick(btn["Reculer"], x, y) then
  147.             rednet.send(channel, "back")
  148.         elseif onclick(btn["Monter"], x, y) then
  149.             rednet.send(channel, "up")
  150.         elseif onclick(btn["Descendre"], x, y) then
  151.             rednet.send(channel, "down")
  152.         elseif onclick(btn["Poser"], x, y) then
  153.             rednet.send(channel, "place")
  154.         elseif onclick(btn["Gauche"], x, y) then
  155.             rednet.send(channel, "turnleft")
  156.         elseif onclick(btn["Droite"], x, y) then
  157.             rednet.send(channel, "turnright")
  158.         elseif onclick(btn["Aspirer"], x, y) then
  159.             rednet.send(channel, "suck")
  160.         elseif pocket and onclick(btn["Cracher"], x, y) then
  161.             rednet.send(channel, "drop")
  162.         elseif onclick(btn["X"], x, y) then
  163.             --os.shutdown()
  164.             term.setCursorPos(1,1)
  165.             term.clear()
  166.             printError("Terminated")
  167.             sleep(.3)
  168.             return
  169.         elseif onclick(btn["Eteindre"], x, y) then
  170.             rednet.send(channel, "urgence")
  171.         end
  172.     end
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement