Guest User

diamonds

a guest
Aug 3rd, 2021
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.18 KB | None | 0 0
  1. local w, h = term.getSize()
  2.  
  3. -- Paint title
  4. paintutils.drawFilledBox(0, 0, w, h, colors.gray)
  5. paintutils.drawFilledBox(0, 0, w, 2, colors.cyan)
  6.  
  7. function printCentered(sText)
  8.   local x, y = term.getCursorPos()
  9.   x = math.max(math.floor((w / 2) - (#sText / 2)), 0)
  10.   term.setCursorPos(x,y)
  11.   print(sText)
  12. end
  13.  
  14. function displayNumber(num, isInt)
  15.  
  16.     num = num or 0
  17.     isInt = isInt or false
  18.    
  19.     if num >= 100000 then
  20.         newNum = num / 100000
  21.         newNum = math.floor(newNum * 100)/100
  22.         newNum = tostring(newNum)
  23.         if isInt == false then
  24.             newNum = string.format("%.1f", newNum) .. "M"
  25.         end
  26.     elseif num >= 1000 then
  27.         newNum = num / 1000
  28.         newNum = math.floor(newNum * 100)/100
  29.         newNum = tostring(newNum)
  30.         if isInt == false then
  31.             newNum = string.format("%.1f", newNum) .. "K"
  32.         end
  33.     else
  34.         newNum = tostring(num)
  35.         if isInt == false then
  36.             newNum = string.format("%.1f", newNum)
  37.         end
  38.     end
  39.    
  40.     return newNum
  41. end
  42.  
  43. term.setCursorPos(0,1)
  44. term.setTextColour(colours.white)
  45. printCentered("Diamond Digger")
  46. print(string.rep("-", w))
  47.  
  48. -- Draw diamond
  49.  
  50. paintutils.drawPixel(5, 6, colors.black)
  51. paintutils.drawPixel(6, 6, colors.black)
  52. paintutils.drawPixel(7, 6, colors.black)
  53. paintutils.drawPixel(8, 7, colors.black)
  54. paintutils.drawPixel(9, 8, colors.black)
  55. paintutils.drawPixel(10, 9, colors.black)
  56. paintutils.drawPixel(10, 10, colors.black)
  57. paintutils.drawPixel(9, 11, colors.black)
  58. paintutils.drawPixel(8, 12, colors.black)
  59. paintutils.drawPixel(7, 12, colors.black)
  60. paintutils.drawPixel(6, 12, colors.black)
  61. paintutils.drawPixel(5, 12, colors.black)
  62. paintutils.drawPixel(4, 12, colors.black)
  63. paintutils.drawPixel(3, 11, colors.black)
  64. paintutils.drawPixel(2, 10, colors.black)
  65. paintutils.drawPixel(2, 9, colors.black)
  66. paintutils.drawPixel(3, 8, colors.black)
  67. paintutils.drawPixel(4, 7, colors.black)
  68. paintutils.drawPixel(5, 7, colors.white)
  69. paintutils.drawPixel(6, 7, colors.white)
  70. paintutils.drawPixel(7, 7, colors.white)
  71. paintutils.drawPixel(4, 8, colors.white)
  72. paintutils.drawPixel(5, 8, colors.cyan)
  73. paintutils.drawPixel(6, 8, colors.cyan)
  74. paintutils.drawPixel(7, 8, colors.cyan)
  75. paintutils.drawPixel(8, 8, colors.cyan)
  76. paintutils.drawPixel(3, 9, colors.cyan)
  77. paintutils.drawPixel(4, 9, colors.blue)
  78. paintutils.drawPixel(5, 9, colors.cyan)
  79. paintutils.drawPixel(6, 9, colors.cyan)
  80. paintutils.drawPixel(7, 9, colors.cyan)
  81. paintutils.drawPixel(8, 9, colors.blue)
  82. paintutils.drawPixel(9, 9, colors.cyan)
  83. paintutils.drawPixel(3, 10, colors.cyan)
  84. paintutils.drawPixel(4, 10, colors.blue)
  85. paintutils.drawPixel(5, 10, colors.blue)
  86. paintutils.drawPixel(6, 10, colors.blue)
  87. paintutils.drawPixel(7, 10, colors.blue)
  88. paintutils.drawPixel(8, 10, colors.blue)
  89. paintutils.drawPixel(9, 10, colors.cyan)
  90. paintutils.drawLine(4, 11, 8, 11, colors.cyan)
  91.  
  92. function updateDiamondOutline()
  93.     drawDiamondOutline(colors.white)
  94.     sleep(.2)
  95.     drawDiamondOutline(colors.gray)
  96. end
  97.  
  98. function drawDiamondOutline(color)
  99.  
  100.     color = color or colors.gray
  101.    
  102.     paintutils.drawLine(5, 5, 7, 5, color)
  103.     paintutils.drawPixel(8, 6, color)
  104.     paintutils.drawPixel(9, 7, color)
  105.     paintutils.drawPixel(10, 8, color)
  106.     paintutils.drawLine(11, 9, 11, 10, color)
  107.     paintutils.drawPixel(10, 11, color)
  108.     paintutils.drawPixel(9, 12, color)
  109.     paintutils.drawLine(8, 13, 4, 13, color)
  110.     paintutils.drawPixel(3, 12, color)
  111.     paintutils.drawPixel(2, 11, color)
  112.     paintutils.drawLine(1, 10, 1, 9, color)
  113.     paintutils.drawPixel(2, 8, color)
  114.     paintutils.drawPixel(3, 7, color)
  115.     paintutils.drawPixel(4, 6, color)
  116. end
  117.  
  118.  
  119. score = 0
  120. diamondsGiven = 0
  121.  
  122. function setScore()
  123.  
  124.     x = x or 0
  125.     y = y or 0
  126.    
  127.     while true do
  128.         os.sleep(0)
  129.        
  130.         if commands then
  131.             if score == 10 and diamondsGiven == 0 then
  132.                 diamondsGiven = diamondsGiven + 1
  133.                 commands.say("@p has earned a diamond by playing Diamond Digger!")
  134.                 commands.exec("give @p diamond 1")
  135.             end
  136.         end
  137.        
  138.         drawUpgrades()
  139.         cps = woodPickCPS
  140.         score = score + (cps * .05)
  141.         term.setBackgroundColor(colors.gray)
  142.         term.setTextColor(colors.white)
  143.         term.setCursorPos(2,4)
  144.         term.clearLine()
  145.         term.write(tostring(displayNumber(score)) .. " diamonds")
  146.     end
  147. end    
  148.  
  149. function handleTouchInputs()
  150.     while true do
  151.        
  152.         local event, side, x, y = os.pullEvent()
  153.        
  154.        
  155.         if event == "monitor_touch" or event == "mouse_click" then
  156.             if ((x>=3 and x<=10) and (y>= 6 and y<= 12)) then
  157.                 updateDiamondOutline()
  158.                 term.setCursorPos(2,4)
  159.                 term.clearLine()
  160.                 score = score + 1
  161.             end
  162.         end
  163.    
  164.         drawUpgrades(x, y)
  165.     end
  166. end
  167.  
  168. woodPickPrice = 15
  169. woodPicksOwned = 0
  170. woodPickCPS = 0
  171.  
  172. cps = 0
  173.  
  174. function drawUpgrades(x,y)
  175.    
  176.     x = x or 0
  177.     y = y or 0
  178.    
  179.         -- Draw the first upgrade
  180.         if score >= woodPickPrice then
  181.             term.setBackgroundColor(colors.green)
  182.             paintutils.drawFilledBox(15, 6, 27, 10, colors.green)
  183.             if ((x>=15 and x<=25) and (y>=6 and y<=10)) then
  184.                 score = score - woodPickPrice
  185.                 woodPicksOwned = woodPicksOwned + 1
  186.                 woodPickPrice = math.floor((woodPickPrice * 1.25) + 0.5)
  187.                 woodPickCPS = woodPickCPS + .1
  188.             end
  189.         elseif score < woodPickPrice then
  190.             term.setBackgroundColor(colors.red)
  191.             paintutils.drawFilledBox(15, 6, 27, 10, colors.red)
  192.         end  
  193.    
  194.         term.setCursorPos(16,6)
  195.         term.write("Wooden")
  196.         term.setCursorPos(16,7)
  197.         term.write("Pickaxe")
  198.         term.setCursorPos(16,8)
  199.         term.write("Price:" .. displayNumber(woodPickPrice, true))
  200.         term.setCursorPos(16,9)
  201.         term.write("Owned:" .. displayNumber(woodPicksOwned, true))
  202.         term.setCursorPos(16,10)
  203.         term.write("CPS:" .. (displayNumber(woodPickCPS)))
  204.                      
  205. end
  206.  
  207.  
  208. parallel.waitForAny(setScore, handleTouchInputs)
Advertisement
Add Comment
Please, Sign In to add comment