Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ###########################
- -- key_test
- -- version 0.3
- -- http://hevohevo.hatenablog.com/
- -- ###########################
- -- config
- MENU = {}
- MENU[1] = "EASY"
- MENU[2] = "NORMAL"
- MENU[3] = "DIFFICULT"
- MENU[4] = "EXIT"
- BASE_X = 7
- BASE_Y = 7
- -- ###########################
- -- functions
- function moveSymbol(x,y)
- term.write(" ")
- term.setCursorPos(x,y)
- term.write(">")
- term.setCursorPos(x,y)
- end
- function drowMenu()
- term.clear()
- term.setCursorPos(BASE_X,BASE_Y)
- for i,v in ipairs(MENU) do
- term.write(" "..v)
- term.setCursorPos(BASE_X,BASE_Y+i)
- end
- moveSymbol(BASE_X,BASE_Y)
- end
- function choose(y)
- if y==1 or y==2 or y==3 then
- term.clear()
- term.setCursorPos(1,1)
- print(MENU[y])
- elseif y == 4 then
- --
- end
- end
- -- ###########################
- -- main
- drowMenu()
- while true do
- local event, key = os.pullEvent("key")
- if event == "key" then
- local x, y = term.getCursorPos() -- current position
- local rel_y = y - BASE_Y + 1 -- relative position x
- local rel_x = x - BASE_X + 1 -- relative position y
- if key == keys.up and rel_y > 1 then
- moveSymbol(x,y-1)
- elseif key == keys.down and rel_y < #MENU then
- moveSymbol(x,y+1)
- elseif key == keys.space then
- choose(rel_y)
- break
- end
- end
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement