Advertisement
MrDionesalvi

LP

Apr 19th, 2021 (edited)
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. white = 0
  2. orange = 0
  3. magenta = 0
  4. ltBlue = 0
  5. totale = 0
  6.  
  7.  
  8. local function drawPixelInternal(xPos, yPos)
  9.     term.setCursorPos(xPos, yPos)
  10.     term.write(" ")
  11. end
  12.  
  13. local tColourLookup = {}
  14. for n = 1, 16 do
  15.     tColourLookup[string.byte("0123456789abcdef", n, n)] = 2 ^ (n - 1)
  16. end
  17.  
  18. function drawFilledBox(startX, startY, endX, endY, nColour)
  19.     if type(startX) ~= "number" or type(startX) ~= "number" or type(endX) ~=
  20.         "number" or type(endY) ~= "number" or
  21.         (nColour ~= nil and type(nColour) ~= "number") then
  22.         error("Expected startX, startY, endX, endY, colour", 2)
  23.     end
  24.  
  25.     startX = math.floor(startX)
  26.     startY = math.floor(startY)
  27.     endX = math.floor(endX)
  28.     endY = math.floor(endY)
  29.  
  30.     if nColour then term.setBackgroundColor(nColour) end
  31.     if startX == endX and startY == endY then
  32.         drawPixelInternal(startX, startY)
  33.         return
  34.     end
  35.  
  36.     local minX = math.min(startX, endX)
  37.     if minX == startX then
  38.         minY = startY
  39.         maxX = endX
  40.         maxY = endY
  41.     else
  42.         minY = endY
  43.         maxX = startX
  44.         maxY = startY
  45.     end
  46.  
  47.     for x = minX, maxX do for y = minY, maxY do drawPixelInternal(x, y) end end
  48. end
  49.  
  50.  
  51. function finish()
  52.  
  53.     term.clear()
  54.  
  55. end
  56.  
  57. -- CAE  :
  58.  
  59. function clear()
  60.     term.clear()
  61.     drawFilledBox(18, 12, 34, 14, colors.yellow)
  62.     term.setCursorPos(22, 13)
  63.     term.setTextColor(colors.black)
  64.     term.write("HO FINITO")
  65.     term.setBackgroundColor(colors.black)
  66.     term.setTextColor(colors.white)
  67.     term.setCursorPos(1, 1)
  68.     term.write("Oggetti contati: 0")
  69. end
  70.  
  71. clear()
  72.  
  73. while true do
  74.     os.pullEvent("redstone")
  75.     col = rs.getBundledInput("bottom")
  76.     if colors.test(col, colors.orange) then
  77.     orange = orange + 32
  78.     end
  79.     if colors.test(col, colors.magenta) then
  80.     magenta = magenta + 32
  81.     end
  82.     if colors.test(col, colors.lightBlue) then
  83.     ltBlue = ltBlue + 2
  84.     end
  85.     if colors.test(col, colors.white) then
  86.     white = white + 32
  87.     end
  88.     clear()
  89.     term.setCursorPos(1, 1)
  90.     totale = orange+magenta+ltBlue+white
  91.     print("Oggetti contati: "..totale)
  92.  
  93.     local myTimer = os.startTimer(1)
  94.     local event, par1, x, y = os.pullEvent("mouse_click")
  95.     if event == "mouse_click" and y > 12 and y < 14 and x > 18 and x < 34 then
  96.         finish()
  97.     end
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement