Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Tunnel Digger Program for Advanced Pocket Computer
- -- Set up the screen
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- term.clear()
- -- Display the title at x = 13
- term.setCursorPos(7, 1)
- term.write("Tunnel Digger")
- -- Function to draw the black strip at the bottom with perspective
- local function drawBlackStrip()
- local width, height = term.getSize()
- local roadWidth = width
- local roadHeight = 4
- -- Drawing the road with perspective
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.black)
- for i = height - roadHeight + 1, height do
- term.setCursorPos(1, i)
- term.write(string.rep(" ", roadWidth))
- roadWidth = roadWidth - 2 -- Narrow the road as we go up
- end
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- end
- -- Function to draw cave graphics
- local function drawCaveGraphics()
- local width, height = term.getSize()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.lightGray)
- -- Add some cave-like texture
- for y = 2, height - 4 do
- for x = 1, width do
- if math.random() > 0.85 then
- term.setCursorPos(x, y)
- term.write("*")
- end
- end
- end
- end
- -- Draw the black strip
- drawBlackStrip()
- -- Draw the cave graphics
- drawCaveGraphics()
- -- Draw the buttons
- local function drawButton(x, y, text)
- term.setCursorPos(x, y)
- term.write("[" .. text .. "]")
- end
- local function clearButton(x, y, text)
- term.setCursorPos(x, y)
- term.write(string.rep(" ", #text + 2))
- end
- local function isWithinBounds(x, y, bx, by, bw, bh)
- return x >= bx and x <= bx + bw and y >= by and y <= by + bh
- end
- -- Position and dimensions of buttons
- local digButton = {x = 2, y = 6, text = "Dig", width = 5, height = 1}
- local stopButton = {x = 20, y = 6, text = "Stop", width = 5, height = 1}
- -- Draw the buttons initially
- drawButton(digButton.x, digButton.y, digButton.text)
- drawButton(stopButton.x, stopButton.y, stopButton.text)
- -- Main loop to handle button clicks
- while true do
- local event, button, x, y = os.pullEvent("mouse_click")
- -- Check if Dig button was clicked
- if isWithinBounds(x, y, digButton.x, digButton.y, digButton.width, digButton.height) then
- clearButton(digButton.x, digButton.y, digButton.text)
- term.setCursorPos(digButton.x, digButton.y)
- term.write("[" .. digButton.text .. "]")
- rednet.send(12, "goldMine infinite false false")
- rednet.send(8, "goldMine infinite false false")
- rednet.send(14, "goldMine infinite false false")
- rednet.send(15, "goldMine infinite false false")
- rednet.send(13, "goldMine infinite false false")
- rednet.send(11, "goldMine infinite false false")
- os.sleep(0.2)
- drawButton(digButton.x, digButton.y, digButton.text)
- end
- -- Check if Stop button was clicked
- if isWithinBounds(x, y, stopButton.x, stopButton.y, stopButton.width, stopButton.height) then
- clearButton(stopButton.x, stopButton.y, stopButton.text)
- term.setCursorPos(stopButton.x, stopButton.y)
- term.write("[" .. stopButton.text .. "]")
- rednet.send(12, "terminate")
- rednet.send(8, "terminate")
- rednet.send(14, "terminate")
- rednet.send(15, "terminate")
- rednet.send(13, "terminate")
- rednet.send(11, "terminate")
- os.sleep(0.2)
- drawButton(stopButton.x, stopButton.y, stopButton.text)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement