summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cactus.lua33
1 files changed, 23 insertions, 10 deletions
diff --git a/cactus.lua b/cactus.lua
index 0934d55..30603e3 100644
--- a/cactus.lua
+++ b/cactus.lua
@@ -37,6 +37,7 @@ local function moveby_y(delta)
local fn = turtle.up
if delta < 0 then fn = turtle.down delta = -delta end
for i=1,delta do fn() end
+ POS.y = POS.y + delta
end
local function rotatev(v,nq)
@@ -60,21 +61,33 @@ end
local function turn_to_face(newfacing)
if newfacing == FACING then return
- elseif newfacing == -FACING then turtle.turnRight() turtle.turnRight()
- elseif newfacing == rotatev(FACING,1) then turtle.turnRight()
- elseif newfacing == rotatev(FACING,-1) then turtle.turnLeft()
+ elseif newfacing == -FACING then turn_right() turn_right()
+ elseif newfacing == rotatev(FACING,1) then turn_right()
+ elseif newfacing == rotatev(FACING,-1) then turn_left()
else error("invalid facing "..tostring(newfacing),2)
end
end
+local function move_linear(n)
+ local dir = turtle.forward
+ if n < 0 then dir = turtle.back end
+ for i = 1,math.abs(n) do dir() end
+ POS = POS + n*FACING
+end
+
local function moveby_xz(dv)
- if dv.x ~= 0 then
- turn_to_face(vector.new(numutil.sign(dv.x), 0, 0))
- for i=1,math.abs(dv.x) do turtle.forward() end
- end
- if dv.z ~= 0 then
- turn_to_face(vector.new(0, 0, numutil.sign(dv.z)))
- for i=1,math.abs(dv.z) do turtle.forward() end
+ if FACING.x ~= 0 then
+ move_linear(dv.x)
+ if dv.z ~= 0 then
+ turn_to_face(0,0,numutil.sign(dv.z))
+ move_linear(math.abs(dv.z))
+ end
+ elseif FACING.z ~= 0 then
+ move_linear(dv.z)
+ if dv.x ~= 0 then
+ turn_to_face(numutil.sign(dv.x),0,0)
+ move_linear(math.abs(dv.x))
+ end
end
end