Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local difficulty
- local player = 2
- local monitorSide = "back"
- local modemSide = "bottom"
- local running = true
- local xpos, ypos
- --Arrays Cooresponding to position of buttons on monitor
- --16 Difficulties, P1 Ready, P2 Ready, X to Reboot
- local xd = {8, 14, 20, 26, 8, 14, 20, 26, 8, 14, 20, 26, 8, 14, 20, 26, 8, 23, 33}
- local yd = {7, 7, 7, 7, 10, 10, 10, 10, 13, 13, 13, 13, 16, 16, 16, 16, 20, 20, 2}
- --Color (decimal) of Difficulty when printed
- local difficultyState = {}
- --Color of playerOne
- local playerOne = 1
- --Color of playerTwo
- local playerTwo = 1
- --Menu State and Table of Run Fuctions
- local menuState = "difficulty"
- local mopt = {
- ["difficulty"] = {draw = drawDifficulty, changer = changeDifficulty},
- ["ready"] = {draw = drawReady, changer = changeReady}
- }
- --Monitor Setup
- m = peripheral.wrap(monitorSide)
- m.setTextScale(0.5)
- local wm,hm = m.getSize()
- function aSum(array,int)
- arraySum = 0
- for i=1,int do
- arraySum = arraySum + array[i]
- end
- return arraySum
- end
- function round(num, idp)
- local mult = 10^(idp or 0)
- return math.floor(num * mult + 0.5) / mult
- end
- function monitorCentered(str,ypos)
- m.setCursorPos(wm/2 - #str/2, ypos)
- m.write(str)
- end
- function monitorRight(str,ypos)
- m.setCursorPos(wm - #str, ypos)
- m.write(str)
- end
- function monitorLeft(str,ypos)
- m.setCursorPos(1 , ypos)
- m.write(str)
- end
- function drawMonitorBG(title)
- m.clear()
- m.setTextColor(colors.gray)
- monitorCentered(string.rep("-",wm),1)
- m.setTextColor(colors.lightGray)
- monitorCentered(title, 2)
- m.setTextColor(colors.gray)
- monitorCentered(string.rep("-",wm),3)
- monitorLeft("|",2)
- monitorRight("|",2)
- local th = 4
- for th=4,hm-1 do
- monitorLeft("|",th)
- monitorRight("|",th)
- end
- monitorCentered(string.rep("-",wm),hm)
- m.setTextColor(colors.red)
- m.setCursorPos(wm-3,2)
- m.write("X")
- end
- function drawDifficulty()
- for i=1,16 do
- m.setTextColor(difficultyState[i])
- m.setCursorPos(xd[i], yd[i])
- m.write(tostring(i))
- end
- m.setTextColor(playerOne)
- m.setCursorPos(8,20)
- m.write("1P Ready")
- m.setTextColor(playerTwo)
- m.setCursorPos(20,20)
- m.write("2P Ready")
- end
- function changeDifficulty()
- --For difficulty selection
- for i=1,16 do
- local xMax, xMin, yMax, yMin
- xMax = xd[i] + 2
- xMin = xd[i] - 2
- yMax = yd[i] + 1
- yMin = yd[i] - 1
- if xpos >= xMin and xpos <= xMax and ypos >= yMin and ypos <= yMax then
- --Resets Difficulty Colors
- for j=1,16 do
- difficultyState[j] = 1
- end
- difficulty=i
- --Makes active choice orange
- difficultyState[i] = 2
- --Locks Door...lol
- rednet.broadcast("S"..player)
- end
- end
- --For bottom buttons
- for i=17,18 do
- local xMax, xMin, yMax, yMin
- xMax = xd[i] + 5
- xMin = xd[i] - 5
- yMax = yd[i] + 1
- yMin = yd[i] - 1
- if xpos >= xMin and xpos <= xMax and ypos >= yMin and ypos <= yMax and aSum(difficultyState,16)==17 then
- if i == 17 then
- playerOne = 2
- playerTwo = 1
- print("ready p1")
- rednet.broadcast("D"..difficulty)
- rednet.broadcast("P1")
- end
- if i == 18 then
- playerOne = 1
- playerTwo = 2
- print("ready p2")
- rednet.broadcast("D"..difficulty)
- rednet.broadcast("P2")
- end
- --Locks Door...lol
- rednet.broadcast("S"..player)
- end
- end
- --To reboot
- local xMax, xMin, yMax, yMin
- xMax = xd[19] + 1
- xMin = xd[19] - 1
- yMax = yd[19] + 1
- yMin = yd[19] - 1
- if xpos >= xMin and xpos <= xMax and ypos >= yMin and ypos <= yMax then
- os.reboot()
- end
- end
- --Initialization
- --Open Rednet
- rednet.open(modemSide)
- --Broadcasts Signal to Unlock forcefield if locked
- rednet.broadcast("N"..player)
- --Background Black
- m.setBackgroundColor(colors.black)
- --Resets Difficulty Array
- for i=1,16 do
- difficultyState[i] = 1
- end
- --Extend for touchscreen
- --Draws Initial Page
- drawMonitorBG("Select Difficulty")
- drawDifficulty()
- --Operation
- while running do
- event, a, xpos, ypos = os.pullEvent()
- if event == "monitor_touch" then
- --Push Red X in Top Right to Reboot System
- if (xpos == 33 and ypos == 2) then
- os.reboot()
- end
- changeDifficulty()
- drawDifficulty()
- end
- if event == "rednet_message" then
- if xpos == "reboot" then
- os.reboot()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement