Advertisement
Deltekkio

OpenComputer excavator

Oct 28th, 2020 (edited)
2,792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. -- Librerie
  2. local term = require("term")
  3. local robot = require("robot")
  4. --
  5.  
  6. -- Variabili globali
  7. raggio = 0
  8. raggioDim = 0
  9. scavo = true
  10. --
  11.  
  12. function avanti()
  13. robot.forward()
  14. end
  15.  
  16. function indietro()
  17. robot.back()
  18. end
  19.  
  20. function su()
  21. robot.up()
  22. end
  23.  
  24. function giu()
  25. robot.down()
  26. end
  27.  
  28. function ruotaD()
  29. robot.turnRight()
  30. end
  31.  
  32. function ruotaS()
  33. robot.turnLeft()
  34. end
  35.  
  36. function scavaAvanti()
  37. robot.swing()
  38. end
  39.  
  40. function scavaSotto()
  41. robot.swingDown()
  42. end
  43.  
  44. function inizio()
  45. term.clear()
  46. print("Benvenuto! Inserisci il raggio di scavaggio: ")
  47. raggio = term.read()
  48. end
  49.  
  50. function scava()
  51.  
  52. scavo = true
  53.  
  54. repeat
  55.  
  56.     if(robot.detectDown()) then
  57.         robot.swingDown()
  58.     end
  59.  
  60.     if(robot.detectDown()) then
  61.         scavo = false
  62.     break end
  63.  
  64.     if(robot.detectDown() == false) then
  65.         giu()
  66.     end
  67.  
  68.     raggioDim = raggio
  69.  
  70.     repeat
  71.  
  72.         local i = 0
  73.  
  74.         for r = 1, 4, 1 do
  75.  
  76.             for i = 0, raggio-2, 1 do
  77.  
  78.                 if(robot.detectDown()) then
  79.                     scavaSotto()
  80.                 end
  81.  
  82.                 if(robot.detect()) then
  83.                     scavaAvanti()
  84.                     avanti()
  85.                 end
  86.  
  87.                 if(robot.detectDown()) then
  88.                     scavaSotto()
  89.                 end
  90.  
  91.             end
  92.  
  93.             if (raggioDim ~= 1) then ruotaD() end
  94.  
  95.         end
  96.  
  97.         raggioDim = raggioDim - 1
  98.  
  99.     until (raggioDim == 1)
  100.  
  101.     local dimezzato = math.floor(raggio/2)
  102.     local pos = 0
  103.  
  104.     ruotaS()
  105.    
  106.     repeat
  107.         avanti()
  108.         pos = pos + 1
  109.     until(pos == dimezzato)
  110.    
  111.     pos = 0
  112.  
  113.     ruotaS()
  114.  
  115.     repeat
  116.         avanti()
  117.         pos = pos + 1
  118.     until(pos == dimezzato)
  119.  
  120.     ruotaS()
  121.     ruotaS()
  122.    
  123.     scavaSotto()
  124.     giu()
  125.  
  126. until(scavo == false)
  127.  
  128. end
  129.  
  130. inizio()
  131. scava()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement