Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local dice = {}
- dice[1] = {
- "+---------+ |",
- "| | |",
- "| | |",
- "| O | |",
- "| | /",
- "| |/",
- "+---------+",
- }
- dice[2] = {
- "+---------+ |",
- "| | |",
- "| | |",
- "| O O | |",
- "| | /",
- "| |/",
- "+---------+",
- }
- dice[3] = {
- "+---------+ |",
- "| O | |",
- "| | |",
- "| O | |",
- "| | /",
- "| O |/",
- "+---------+",
- }
- dice[4] = {
- "+---------+ |",
- "| | |",
- "| O O | |",
- "| | |",
- "| O O | /",
- "| |/",
- "+---------+",
- }
- dice[5] = {
- "+---------+ |",
- "| O O | |",
- "| | |",
- "| O | |",
- "| | /",
- "| O O |/",
- "+---------+",
- }
- dice[6] = {
- "+---------+ |",
- "| O O | |",
- "| | |",
- "| O O | |",
- "| | /",
- "| O O |/",
- "+---------+",
- }
- local function cwrite(t)
- term.setCursorPos((51-#t)/2, ({term.getCursorPos()})[2])
- write(t)
- end
- local function cprint(t)
- cwrite(t)
- write("\n")
- end
- local function clear(c)
- term.setBackgroundColor(c)
- term.setTextColor(colors.white)
- term.clear()
- term.setCursorPos(1, 1)
- end
- local function makeDice(val)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(24, 6)
- write("+---------+")
- term.setCursorPos(23, 7)
- write("/ /|")
- term.setCursorPos(22, 8)
- write("/ / |")
- for i = 1, 7 do
- term.setCursorPos(21, 8+i)
- write(dice[val][i])
- end
- end
- local function last5(last)
- -- Last 5 rolls
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.cyan)
- write("Last 9|")
- term.setBackgroundColor(colors.blue)
- for i = 1, 18 do
- term.setCursorPos(1, i+1)
- if i % 2 == 1 then
- last[(i+1)/2] = last[(i+1)/2] and last[(i+1)/2] or 0
- for j = 1, last[(i+1)/2] do
- write("o")
- end
- for j = 1, 6 - last[(i+1)/2] do
- write(" ")
- end
- write("|")
- else
- write("+-----<")
- end
- end
- end
- local function roll(last)
- clear(colors.black)
- -- Close button
- term.setCursorPos(50, 1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- write("\\/")
- term.setCursorPos(50, 2)
- write("/\\")
- last5(last)
- -- Roll
- local val
- for i = 0.1, 0.7, 0.03 do
- val = math.random(1,6)
- makeDice(val)
- sleep(i*i)
- end
- -- Move items in last
- for i = 9, 2, -1 do
- last[i] = last[i-1]
- end
- last[1] = val
- last5(last)
- return last
- end
- ---------------
- -- Splash
- clear(colors.black)
- cprint("Dice roll")
- cprint("Click on screen to roll dice!")
- cprint("(or click on X to exit)")
- term.setCursorPos(1, 15)
- term.setTextColor(colors.yellow)
- cprint("Click on screen to continue")
- term.setCursorPos(1, 19)
- term.setTextColor(colors.gray)
- cwrite("by Jesusthekiller")
- os.pullEvent("mouse_click")
- -- Roll
- local last = {}
- while true do
- last = roll(last)
- local e, b, x, y = os.pullEvent("mouse_click")
- if x >= 50 and y <= 2 then
- break
- end
- end
- clear(colors.black)
- cprint("By Jesusthekiller")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement