local w, h = term.getSize() -- Paint title paintutils.drawFilledBox(0, 0, w, h, colors.gray) paintutils.drawFilledBox(0, 0, w, 2, colors.cyan) function printCentered(sText) local x, y = term.getCursorPos() x = math.max(math.floor((w / 2) - (#sText / 2)), 0) term.setCursorPos(x,y) print(sText) end function displayNumber(num, isInt) num = num or 0 isInt = isInt or false if num >= 100000 then newNum = num / 100000 newNum = math.floor(newNum * 100)/100 newNum = tostring(newNum) if isInt == false then newNum = string.format("%.1f", newNum) .. "M" end elseif num >= 1000 then newNum = num / 1000 newNum = math.floor(newNum * 100)/100 newNum = tostring(newNum) if isInt == false then newNum = string.format("%.1f", newNum) .. "K" end else newNum = tostring(num) if isInt == false then newNum = string.format("%.1f", newNum) end end return newNum end term.setCursorPos(0,1) term.setTextColour(colours.white) printCentered("Diamond Digger") print(string.rep("-", w)) -- Draw diamond paintutils.drawPixel(5, 6, colors.black) paintutils.drawPixel(6, 6, colors.black) paintutils.drawPixel(7, 6, colors.black) paintutils.drawPixel(8, 7, colors.black) paintutils.drawPixel(9, 8, colors.black) paintutils.drawPixel(10, 9, colors.black) paintutils.drawPixel(10, 10, colors.black) paintutils.drawPixel(9, 11, colors.black) paintutils.drawPixel(8, 12, colors.black) paintutils.drawPixel(7, 12, colors.black) paintutils.drawPixel(6, 12, colors.black) paintutils.drawPixel(5, 12, colors.black) paintutils.drawPixel(4, 12, colors.black) paintutils.drawPixel(3, 11, colors.black) paintutils.drawPixel(2, 10, colors.black) paintutils.drawPixel(2, 9, colors.black) paintutils.drawPixel(3, 8, colors.black) paintutils.drawPixel(4, 7, colors.black) paintutils.drawPixel(5, 7, colors.white) paintutils.drawPixel(6, 7, colors.white) paintutils.drawPixel(7, 7, colors.white) paintutils.drawPixel(4, 8, colors.white) paintutils.drawPixel(5, 8, colors.cyan) paintutils.drawPixel(6, 8, colors.cyan) paintutils.drawPixel(7, 8, colors.cyan) paintutils.drawPixel(8, 8, colors.cyan) paintutils.drawPixel(3, 9, colors.cyan) paintutils.drawPixel(4, 9, colors.blue) paintutils.drawPixel(5, 9, colors.cyan) paintutils.drawPixel(6, 9, colors.cyan) paintutils.drawPixel(7, 9, colors.cyan) paintutils.drawPixel(8, 9, colors.blue) paintutils.drawPixel(9, 9, colors.cyan) paintutils.drawPixel(3, 10, colors.cyan) paintutils.drawPixel(4, 10, colors.blue) paintutils.drawPixel(5, 10, colors.blue) paintutils.drawPixel(6, 10, colors.blue) paintutils.drawPixel(7, 10, colors.blue) paintutils.drawPixel(8, 10, colors.blue) paintutils.drawPixel(9, 10, colors.cyan) paintutils.drawLine(4, 11, 8, 11, colors.cyan) function updateDiamondOutline() drawDiamondOutline(colors.white) sleep(.2) drawDiamondOutline(colors.gray) end function drawDiamondOutline(color) color = color or colors.gray paintutils.drawLine(5, 5, 7, 5, color) paintutils.drawPixel(8, 6, color) paintutils.drawPixel(9, 7, color) paintutils.drawPixel(10, 8, color) paintutils.drawLine(11, 9, 11, 10, color) paintutils.drawPixel(10, 11, color) paintutils.drawPixel(9, 12, color) paintutils.drawLine(8, 13, 4, 13, color) paintutils.drawPixel(3, 12, color) paintutils.drawPixel(2, 11, color) paintutils.drawLine(1, 10, 1, 9, color) paintutils.drawPixel(2, 8, color) paintutils.drawPixel(3, 7, color) paintutils.drawPixel(4, 6, color) end score = 0 diamondsGiven = 0 function setScore() x = x or 0 y = y or 0 while true do os.sleep(0) if commands then if score == 10 and diamondsGiven == 0 then diamondsGiven = diamondsGiven + 1 commands.say("@p has earned a diamond by playing Diamond Digger!") commands.exec("give @p diamond 1") end end drawUpgrades() cps = woodPickCPS score = score + (cps * .05) term.setBackgroundColor(colors.gray) term.setTextColor(colors.white) term.setCursorPos(2,4) term.clearLine() term.write(tostring(displayNumber(score)) .. " diamonds") end end function handleTouchInputs() while true do local event, side, x, y = os.pullEvent() if event == "monitor_touch" or event == "mouse_click" then if ((x>=3 and x<=10) and (y>= 6 and y<= 12)) then updateDiamondOutline() term.setCursorPos(2,4) term.clearLine() score = score + 1 end end drawUpgrades(x, y) end end woodPickPrice = 15 woodPicksOwned = 0 woodPickCPS = 0 cps = 0 function drawUpgrades(x,y) x = x or 0 y = y or 0 -- Draw the first upgrade if score >= woodPickPrice then term.setBackgroundColor(colors.green) paintutils.drawFilledBox(15, 6, 27, 10, colors.green) if ((x>=15 and x<=25) and (y>=6 and y<=10)) then score = score - woodPickPrice woodPicksOwned = woodPicksOwned + 1 woodPickPrice = math.floor((woodPickPrice * 1.25) + 0.5) woodPickCPS = woodPickCPS + .1 end elseif score < woodPickPrice then term.setBackgroundColor(colors.red) paintutils.drawFilledBox(15, 6, 27, 10, colors.red) end term.setCursorPos(16,6) term.write("Wooden") term.setCursorPos(16,7) term.write("Pickaxe") term.setCursorPos(16,8) term.write("Price:" .. displayNumber(woodPickPrice, true)) term.setCursorPos(16,9) term.write("Owned:" .. displayNumber(woodPicksOwned, true)) term.setCursorPos(16,10) term.write("CPS:" .. (displayNumber(woodPickCPS))) end parallel.waitForAny(setScore, handleTouchInputs)