Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ###########################
- -- key_test
- -- version 0.1
- -- http://hevohevo.hatenablog.com/
- -- ###########################
- -- functions
- function moveSymbol(x,y)
- term.setCursorPos(x,y)
- term.write("@")
- term.setCursorPos(x,y)
- end
- function moveSymbol2(x,y)
- term.write(" ")
- term.setCursorPos(x,y)
- term.write("@")
- term.setCursorPos(x,y)
- end
- -- ###########################
- -- main
- MAX_X, MAX_Y = term.getSize()
- term.clear()
- moveSymbol(1,1)
- while true do
- local ename, keycode = os.pullEvent("key")
- if ename == "key" then
- local x, y = term.getCursorPos()
- if keycode == keys.up and y > 1 then
- moveSymbol(x,y-1)
- elseif keycode == keys.down and y < MAX_Y then
- moveSymbol(x,y+1)
- elseif keycode == keys.left and x > 1 then
- moveSymbol(x-1,y)
- elseif keycode == keys.right and x < MAX_X then
- moveSymbol(x+1,y)
- elseif keycode == keys.q then
- break -- terminated
- else
- -- do nothing
- end
- end
- sleep(0)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement