SHARE
TWEET

ComputerCraft Tutorial: key_test0_2

hevohevo Dec 24th, 2013 376 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- ###########################
  2. -- key_test
  3. -- version 0.2
  4. -- http://hevohevo.hatenablog.com/
  5.  
  6. -- ###########################
  7. -- functions
  8. function moveSymbol(x,y)
  9.   term.write(" ")
  10.   term.setCursorPos(x,y)
  11.   term.write(">")
  12.   term.setCursorPos(x,y)
  13. end
  14.  
  15. -- ###########################
  16. -- main
  17.  
  18. term.clear()
  19. term.setCursorPos(1,1)
  20. write("  EASY\n")  -- write and newline-char
  21. print("  NORMAL") -- print
  22. print("  DIFFICULT")
  23. print("  EXIT")
  24. moveSymbol(1,1)
  25.  
  26. while true do
  27.   local ename, keycode = os.pullEvent("key")
  28.   local _, y = term.getCursorPos()
  29.  
  30.   if ename == "key" then
  31.     if keycode == keys.up and y > 1 then
  32.       moveSymbol(x,y-1)
  33.     elseif keycode == keys.down and y < 4 then
  34.       moveSymbol(x,y+1)
  35.     elseif keycode == keys.space then
  36.       if y == 1 then
  37.         term.clear()
  38.         term.setCursorPos(1,1)
  39.         print("EASY")
  40.         break
  41.       elseif y == 2 then
  42.         term.clear()
  43.         term.setCursorPos(1,1)
  44.         print("NORMAL")
  45.         break
  46.       elseif y == 3 then
  47.         term.clear()
  48.         term.setCursorPos(1,1)
  49.         print("DIFFICULT")
  50.         break
  51.       elseif y == 4 then
  52.         break
  53.       end
  54.     end
  55.   end
  56.  
  57.   sleep(0)
  58. end
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top