Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Starting kiosk...")
- local screenWidth, screenHeight = term.getSize()
- function initKiosk()
- term.setBackgroundColor(colors.white)
- term.clear()
- term.setTextColor(colors.black)
- term.setCursorPos(2, 2)
- term.write("Szymekk's Kiosk - super gazety w super cenie!")
- end
- function initPeripherals()
- energyCube = peripheral.wrap("mekanism_machine_0")
- sensor = peripheral.wrap("openperipheral_sensor_0")
- noteBlock = peripheral.wrap("note_block_0")
- end
- function drawProgressBar(y, text, factor, centerText)
- centerText = centerText or ""
- local offset = 1
- local barColor1 = "5"
- local barColor2 = "e"
- term.setTextColor(colors.black)
- term.setCursorPos(1 + offset, y)
- term.write(text)
- local barWidth = math.floor(screenWidth * 0.75)
- local blitText = { }
- local blitFgStr = { }
- local blitBgStr = { }
- for i = 0, barWidth do
- blitText[#blitText + 1] = " "
- blitFgStr[#blitFgStr + 1] = "f"
- blitBgStr[#blitBgStr + 1] = (i / barWidth) <= factor + 0.01 and barColor1 or barColor2
- end
- for i = 1, #centerText do
- local textOffset = math.floor((barWidth / 2) - (#centerText / 2))
- blitText[textOffset + i] = string.sub(centerText, i, i)
- end
- blitText = table.concat(blitText)
- blitBgStr = table.concat(blitBgStr)
- blitFgStr = table.concat(blitFgStr)
- term.setCursorPos(screenWidth - offset - barWidth, y)
- term.blit(blitText, blitFgStr, blitBgStr)
- end
- function enterLoop()
- while true do
- loop()
- os.sleep(1)
- end
- end
- function loop()
- -- Energy cube
- local energyCur = energyCube.getEnergyStored()
- local energyMax = energyCube.getMaxEnergyStored()
- drawProgressBar(4, "Energia", energyCur / energyMax, energyCur .. " / " .. energyMax .. " RF")
- drawProgressBar(6, "Drama", 0.2, "Low")
- -- Sensor
- local players = sensor.getPlayers()
- local foundPly = false
- for k, v in pairs(players) do
- if(v.name == "szymski") then
- foundPly = true
- break
- end
- end
- local foundSomeoneElse = not foundPly and #players ~= 0
- if foundPly then
- term.setCursorPos(2, 8)
- term.write("Czesc, Szymekk!")
- else
- term.setCursorPos(2, 8)
- term.write(" ")
- end
- if foundSomeoneElse then
- noteBlock.playSound("random.levelup", 0.7, 1)
- os.sleep(0.5)
- noteBlock.playSound("random.levelup", 0.3, 1)
- os.sleep(0.5)
- noteBlock.playSound("random.levelup", 0.1, 1)
- term.setCursorPos(2, 8)
- term.write("Wynocha, " .. players[1].name .. "!")
- end
- end
- initKiosk()
- initPeripherals()
- enterLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement