Advertisement
thatparadox

CarTurtle

Aug 27th, 2013
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. rednet.open("right")
  2.  
  3. con = "false"
  4.  
  5. result = fs.exists("pos")
  6. if result == true then
  7.   file = io.open("pos", "r")
  8.   pos = file.read()
  9.   file:close()
  10. else
  11.   pos = "back"
  12.   file = fs.open("pos", "w")
  13.   file.write(pos)
  14.   file:close()
  15. end
  16. if pos == "back" then
  17.   eng = peripheral.wrap("front")
  18. else
  19.   eng = peripheral.wrap("bottom")
  20. end
  21.  
  22. -- screen display
  23. term.clear()
  24. x,y = term.getSize()
  25. term.setCursorPos(x/2, y/3-1)
  26. print("W")
  27. term.setCursorPos(x/2-3, y/3)
  28. print("Forward")
  29. term.setCursorPos(x/5, y/3*2)
  30. print("A")
  31. term.setCursorPos(x/2, y/3*2)
  32. print("S")
  33. term.setCursorPos(x/5*4, y/3*2)
  34. print("D")
  35. term.setCursorPos(x/5-2, y/3*2+1)
  36. print("Left")
  37. term.setCursorPos(x/2-2, y/3*2+1)
  38. print("Back")
  39. term.setCursorPos(x/5*4-2, y/3*2+1)
  40. print("Right")
  41. term.setCursorPos(1, y-3)
  42. print("[Shift]")
  43. term.setCursorPos(3,y-2)
  44. print("Up")
  45. term.setCursorPos(1, y-1)
  46. print("[Ctrl]")
  47. term.setCursorPos(2, y)
  48. print("Down")
  49.  
  50.  
  51. while true do
  52.   event, param = os.pullEvent()
  53.   if param ~= 31 and event == "key" then
  54.     if pos == "top" then
  55.       turtle.forward()
  56.       turtle.down()
  57.       turtle.turnRight()
  58.       turtle.turnRight()
  59.       pos = "back"
  60.       file = fs.open("pos", "w")
  61.       file.write(pos)
  62.       file:close()
  63.       eng = peripheral.wrap("front")
  64.     end
  65.     if param == 17 then
  66.       eng.move(2, false, false)
  67.       os.sleep(1)
  68.       turtle.forward()
  69.     elseif param == 32 then
  70.       eng.move(5, false, false)
  71.       turtle.turnRight()
  72.       turtle.forward()
  73.       turtle.turnLeft()
  74.       sleep(.2)
  75.     elseif param == 30 then
  76.       eng.move(4, false, false)
  77.       turtle.turnLeft()
  78.       turtle.forward()
  79.       turtle.turnRight()
  80.       sleep(.2)
  81.     elseif param == 42 then
  82.       eng.move(1, false, false)
  83.       turtle.up()
  84.       sleep(1)
  85.     elseif param == 29 then
  86.       eng.move(0, false, false)
  87.       turtle.down()
  88.       sleep(1)    
  89.     end
  90.   elseif param == 31 then
  91.     if pos == "back" then
  92.       turtle.up()
  93.       turtle.forward()
  94.       turtle.turnRight()
  95.       turtle.turnRight()
  96.       pos = "top"
  97.       file = fs.open("pos", "w")
  98.       file.write(pos)
  99.       file:close()
  100.       eng = peripheral.wrap("bottom")
  101.     end
  102.     eng.move(3, false, false)
  103.     turtle.forward()
  104.     sleep(1)
  105.   end
  106. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement