Advertisement
Dlog_M125

Tunnel Digger

Jul 21st, 2024 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. -- Tunnel Digger Program for Advanced Pocket Computer
  2.  
  3. -- Set up the screen
  4. term.setBackgroundColor(colors.gray)
  5. term.setTextColor(colors.white)
  6. term.clear()
  7.  
  8. -- Display the title at x = 13
  9. term.setCursorPos(7, 1)
  10. term.write("Tunnel Digger")
  11.  
  12. -- Function to draw the black strip at the bottom with perspective
  13. local function drawBlackStrip()
  14. local width, height = term.getSize()
  15. local roadWidth = width
  16. local roadHeight = 4
  17.  
  18. -- Drawing the road with perspective
  19. term.setBackgroundColor(colors.black)
  20. term.setTextColor(colors.black)
  21. for i = height - roadHeight + 1, height do
  22. term.setCursorPos(1, i)
  23. term.write(string.rep(" ", roadWidth))
  24. roadWidth = roadWidth - 2 -- Narrow the road as we go up
  25. end
  26.  
  27. term.setBackgroundColor(colors.gray)
  28. term.setTextColor(colors.white)
  29. end
  30.  
  31. -- Function to draw cave graphics
  32. local function drawCaveGraphics()
  33. local width, height = term.getSize()
  34. term.setBackgroundColor(colors.gray)
  35. term.setTextColor(colors.lightGray)
  36. -- Add some cave-like texture
  37. for y = 2, height - 4 do
  38. for x = 1, width do
  39. if math.random() > 0.85 then
  40. term.setCursorPos(x, y)
  41. term.write("*")
  42. end
  43. end
  44. end
  45. end
  46.  
  47. -- Draw the black strip
  48. drawBlackStrip()
  49.  
  50. -- Draw the cave graphics
  51. drawCaveGraphics()
  52.  
  53. -- Draw the buttons
  54. local function drawButton(x, y, text)
  55. term.setCursorPos(x, y)
  56. term.write("[" .. text .. "]")
  57. end
  58.  
  59. local function clearButton(x, y, text)
  60. term.setCursorPos(x, y)
  61. term.write(string.rep(" ", #text + 2))
  62. end
  63.  
  64. local function isWithinBounds(x, y, bx, by, bw, bh)
  65. return x >= bx and x <= bx + bw and y >= by and y <= by + bh
  66. end
  67.  
  68. -- Position and dimensions of buttons
  69. local digButton = {x = 2, y = 6, text = "Dig", width = 5, height = 1}
  70. local stopButton = {x = 20, y = 6, text = "Stop", width = 5, height = 1}
  71.  
  72. -- Draw the buttons initially
  73. drawButton(digButton.x, digButton.y, digButton.text)
  74. drawButton(stopButton.x, stopButton.y, stopButton.text)
  75.  
  76. -- Main loop to handle button clicks
  77. while true do
  78. local event, button, x, y = os.pullEvent("mouse_click")
  79.  
  80. -- Check if Dig button was clicked
  81. if isWithinBounds(x, y, digButton.x, digButton.y, digButton.width, digButton.height) then
  82. clearButton(digButton.x, digButton.y, digButton.text)
  83. term.setCursorPos(digButton.x, digButton.y)
  84. term.write("[" .. digButton.text .. "]")
  85. rednet.send(12, "goldMine infinite false false")
  86. rednet.send(8, "goldMine infinite false false")
  87. rednet.send(14, "goldMine infinite false false")
  88. rednet.send(15, "goldMine infinite false false")
  89. rednet.send(13, "goldMine infinite false false")
  90. rednet.send(11, "goldMine infinite false false")
  91. os.sleep(0.2)
  92. drawButton(digButton.x, digButton.y, digButton.text)
  93. end
  94.  
  95. -- Check if Stop button was clicked
  96. if isWithinBounds(x, y, stopButton.x, stopButton.y, stopButton.width, stopButton.height) then
  97. clearButton(stopButton.x, stopButton.y, stopButton.text)
  98. term.setCursorPos(stopButton.x, stopButton.y)
  99. term.write("[" .. stopButton.text .. "]")
  100. rednet.send(12, "terminate")
  101. rednet.send(8, "terminate")
  102. rednet.send(14, "terminate")
  103. rednet.send(15, "terminate")
  104. rednet.send(13, "terminate")
  105. rednet.send(11, "terminate")
  106. os.sleep(0.2)
  107. drawButton(stopButton.x, stopButton.y, stopButton.text)
  108. end
  109. end
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement