Advertisement
thatparadox

WASD turtle control

Jul 4th, 2013
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. term.clear()
  2. x,y = term.getSize()
  3.  
  4. -- screen display
  5. term.setCursorPos(3, y/3-1)
  6. print("Q")
  7. term.setCursorPos(x/2, y/3-1)
  8. print("W")
  9. term.setCursorPos(x-3, y/3-1)
  10. print("E")
  11. term.setCursorPos(1, y/3)
  12. print("Quit")
  13. term.setCursorPos(x/2-3, y/3)
  14. print("Forward")
  15. term.setCursorPos(x-5, y/3)
  16. print("place")
  17. term.setCursorPos(x/5, y/3*2)
  18. print("A")
  19. term.setCursorPos(x/2, y/3*2)
  20. print("S")
  21. term.setCursorPos(x/5*4, y/3*2)
  22. print("D")
  23. term.setCursorPos(x/5-2, y/3*2+1)
  24. print("Left")
  25. term.setCursorPos(x/2-2, y/3*2+1)
  26. print("Back")
  27. term.setCursorPos(x/5*4-2, y/3*2+1)
  28. print("Right")
  29. term.setCursorPos(1, y-3)
  30. print("[Shift]")
  31. term.setCursorPos(3,y-2)
  32. print("Up")
  33. term.setCursorPos(1, y-1)
  34. print("[Ctrl]")
  35. term.setCursorPos(x/2-3, y-1)
  36. print("[Space]")
  37. term.setCursorPos(x-8, y-1)
  38. print("[<-] [->]")
  39. term.setCursorPos(2, y)
  40. print("Down")
  41. term.setCursorPos(x/2-1, y-1)
  42. print("Dig")
  43. term.setCursorPos(x-6, y-1)
  44. print("Slot")
  45.  
  46. --select slot 1 by default
  47. turtle.select(1)
  48. slot = 1
  49.  
  50. --button selection
  51. while true do
  52.   event, p1 = os.pullEvent()
  53.   if p1 == "a" then
  54.     turtle.turnLeft()
  55.   elseif p1 == "s" then
  56.     turtle.back()
  57.   elseif p1 == "d" then
  58.     turtle.turnRight()
  59.   elseif p1 == "w" then
  60.     turtle.forward()
  61.   elseif p1 == 42 then
  62.     turtle.up()
  63.   elseif p1 == 29 then
  64.     turtle.down()
  65.   elseif p1 == 57 then  
  66.     turtle.dig() -- change to turtle.attack() for melee turtle
  67.   elseif p1 == "q" then
  68.     term.clear()
  69.     term.setCursorPos(1,1)
  70.     break
  71.   elseif p1 == "e" then
  72.     turtle.place()
  73.   elseif p1 == 205 then
  74.     slot = slot+1
  75.     if slot > 16 then
  76.       slot = 1
  77.       turtle.select(slot)
  78.     else
  79.       turtle.select(slot)
  80.     end
  81.   elseif p1 == 203 then
  82.     slot = slot - 1
  83.     if slot < 1 then
  84.       slot = 16
  85.       turtle.select(slot)
  86.     else
  87.       turtle.select(slot)
  88.     end
  89.   end
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement