Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if posx == nil then posx = 1 end
- if posy == nil then posy = 0 end
- if fieldx == nil then fieldx = 9 end
- if fieldy == nil then fieldy = 9 end
- if wait == nil then wait = 5 end
- if waitafter == nil then waitafter = true end
- function coord()
- print("Position: "..posx.." / "..posy)
- end
- function iposx()
- posx = posx + 1
- end
- function iposy()
- posy = posy + 1
- end
- function dposx()
- posx = posx - 1
- end
- function dposy()
- posy = posy - 1
- end
- function mine()
- print("doing stuff here")
- end
- function move(dx, dy)
- moveDirX(posx, dx)
- moveDirY(posy, dy)
- end
- function moveDirX(ax, dx)
- if ax == 0 then step(dx, 1) else
- delta = ax-dx
- step(delta, 0)
- end
- end
- function moveDirY(ay, dy)
- if ay == 0 then step(dy, 1) else
- delta = ay-dy
- step(delta, 1)
- end
- end
- function betrag(zahl1)
- if zahl1 < 0 then return zahl1 * -1
- else return zahl1
- end
- end
- function step(count, axis)
- if axis == 0 then
- if count > 0 then
- moveLeft(betrag(count))
- return true
- elseif count < 0 then
- moveRight(betrag(count))
- return true
- end
- elseif axis == 1 then
- if count > 0 then
- moveBack(betrag(count))
- return true
- elseif count < 0 then
- moveForward(betrag(count))
- return true
- end
- end
- end
- function moveRight(ci)
- turtle.turnRight(1)
- for i=1, ci do
- print("Moving right. New: "..(posx+1).." / "..posy)
- if not turtle.detect() then
- turtle.forward()
- iposx()
- else print("I crashed right!")
- end
- end
- turtle.turnLeft(1)
- end
- function moveLeft(ci)
- turtle.turnLeft(1)
- for i=1, ci do
- print("Moving left. New: "..(posx-1).." / "..posy)
- if not turtle.detect() then
- turtle.forward()
- dposx()
- else print("I crashed left!")
- end
- end
- turtle.turnRight(1)
- end
- function moveForward(ci)
- for i=1, ci do
- print("Moving forward. New: "..posx.." / "..(posy+1))
- if not turtle.detect() then
- turtle.forward()
- iposy()
- else print("I crashed forward!")
- end
- end
- end
- function moveBack(ci)
- turn180()
- for i=1, ci do
- print("Moving back. New: "..posx.." / "..(posy-1))
- if not turtle.detect() then
- turtle.forward()
- dposy()
- else print("I crashed backward!")
- end
- end
- turn180()
- end
- function turn180()
- turtle.turnRight()
- turtle.turnRight()
- end
- if not waitafter then sleep(wait) end
- --.....
- move(1,1)
- move(1,1)
- if waitafter then sleep(wait) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement