Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function displayCord()
- print(x)
- print(y)
- print(getOrientation())
- end
- currentOrientation = 0
- io.write("What is your current x pos? ")
- x = io.read()
- io.write("What is your current y pos? ")
- y = io.read()
- io.write("What is your current depth? ")
- z = io.read()
- io.write("How far down do you wish to tunnel? ")
- tunnel = io.read()
- function initialiseOrientation()
- arrOrientation = {}
- arrOrientation[1] = "north"
- arrOrientation[2] = "east"
- arrOrientation[3] = "south"
- arrOrientation[4] = "west"
- currentOrientation = startingOrientation()
- end
- function getOrientation()
- return arrOrientation[currentOrientation]
- end
- function turn(direction)
- tmpTurn = string.lower(direction)
- if tmpTurn == "right" then
- if turtle.turnRight() then
- if currentOrientation == 4 then
- currentOrientation = 1
- else
- currentOrientation = currentOrientation + 1
- end
- end
- elseif tmpTurn == "left" then
- if turtle.turnLeft() then
- if currentOrientation == 1 then
- currentOrientation = 4
- else
- currentOrientation = currentOrientation - 1
- end
- end
- else
- return false
- end
- end
- function startingOrientation()
- io.write("Which way is the turtle currently facing?")
- facing =string.lower( io.read())
- if facing == "north" then
- return 1
- elseif facing == "east" then
- return 2
- elseif facing == "south" then
- return 3
- elseif facing == "west" then
- return 4
- else
- return 0
- end
- end
- function refuel()
- if turtle.getFuelLevel( ) < 10 then
- turtle.select(16)
- turtle.refuel(1)
- end
- end
- function move(direction)
- refuel()
- tmpDir = string.lower(direction)
- if tmpDir == "forward" then
- if turtle.forward() then
- updateXY("forward")
- end
- elseif tmpDir == "back" then
- if turtle.back() then
- updateXY("back")
- end
- elseif tmpDir == "up" then
- if turtle.up() then
- y = (y) + (1)
- end
- elseif tmpDir == "down" then
- if turtle.down() then
- y = (y) - (1)
- end
- else
- return false
- end
- end
- function updateXY(direction)
- if getOrientation() == "north" then
- if direction == "forward" then
- y = y - 1
- elseif direction == "back" then
- y = y + 1
- end
- elseif getOrientation() == "east" then
- if direction == "forward" then
- x = x + 1
- elseif direction == "back" then
- x = x - 1
- end
- elseif getOrientation() == "south" then
- if direction == "forward" then
- y = y + 1
- elseif direction == "back" then
- y = y - 1
- end
- elseif getOrientation() == "west" then
- if direction == "forward" then
- x = x - 1
- elseif direction == "back" then
- x = x + 1
- end
- end
- end
- initialiseOrientation()
- print(getOrientation())
- displayCord()
- for i = 1,30 do
- move("forward")
- displayCord()
- move("forward")
- displayCord()
- turn("right")
- displayCord()
- turn("right")
- displayCord()
- move("back")
- displayCord()
- turn("left")
- displayCord()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement