Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get wsLBFGgx BasicMovement
- CVF = require("CVF")
- POS = require("POS")
- BM = {}
- local initData = nil
- function BM.forward()
- if POS.direction then
- if turtle.forward() then
- POS.position = CVF.add(POS.position, POS.direction)
- return true
- else
- while not POS.get_GPS_Position() do sleep(1) end
- end
- else
- local oldPos = {x= POS.position.x, y=POS.position.y, z=POS.position.z}
- if turtle.forward() then
- while not POS.get_GPS_Position() do sleep(1) end
- POS.direction = {x=POS.position.x-oldPos.x, z=POS.position.z-oldPos.z}
- return true
- else
- while not POS.get_GPS_Position() do sleep(1) end
- end
- end
- return false
- end
- function BM.up()
- if turtle.up() then
- POS.position.y = POS.position.y + 1
- return true
- else
- while not POS.get_GPS_Position() do sleep(1) end
- end
- return false
- end
- function BM.down()
- if turtle.down() then
- POS.position.y = POS.position.y - 1
- return true
- else
- while not POS.get_GPS_Position() do sleep(1) end
- end
- return false
- end
- function BM.back()
- if turtle.back() then
- POS.position = CVF.sub(POS.position, POS.direction)
- return true
- else
- while not POS.get_GPS_Position() do sleep(1) end
- end
- return false
- end
- function BM.turnLeft()
- if turtle.turnLeft() then
- if POS.direction then
- POS.direction = CVF.getLeftDir(POS.direction)
- end
- return true
- end
- return false
- end
- function BM.turnRight()
- if turtle.turnRight() then
- if POS.direction then
- POS.direction = CVF.getRightDir(POS.direction)
- end
- return true
- end
- return false
- end
- function BM.turnAround()
- return BM.turnRight() and BM.turnRight()
- end
- function BM.turnInDirection(endDir)
- if not endDir then return false end
- if not initData then
- initData = SDM.TURTLE.loadInitData()
- end
- local dirList = {
- ["LEFT"] = initData.dirBottomBelt,
- ["RIGHT"] = initData.dirTopBelt,
- ["FORWARD"] = initData.dirSection,
- ["BACKWARD"] = CVF.mult(-1, initData.dirSection)
- }
- if type(endDir) == "string" then
- endDir = dirList[endDir]
- end
- local startDir = POS.direction
- local strTurnDir = CVF.getTurnDirection(startDir, endDir)
- if not strTurnDir then return true end
- local turnList = {
- ["left"] = BM.turnLeft,
- ["right"] = BM.turnRight,
- ["around"] = BM.turnAround
- }
- return turnList[strTurnDir]()
- end
- return BM
Advertisement
Add Comment
Please, Sign In to add comment