summaryrefslogtreecommitdiff
path: root/motion.lua
diff options
context:
space:
mode:
Diffstat (limited to 'motion.lua')
-rw-r--r--motion.lua49
1 files changed, 49 insertions, 0 deletions
diff --git a/motion.lua b/motion.lua
new file mode 100644
index 0000000..a4a9b3c
--- /dev/null
+++ b/motion.lua
@@ -0,0 +1,49 @@
+local p = peripheral.wrap"back"
+for i,mod in ipairs{"kinetic","sensor","keyboard","glasses"} do
+ assert(p.hasModule("plethora:"..mod), "need "..mod.."!")
+end
+
+local hover = false
+local hstrength = 1.6
+local vstrength = 4
+local hdelta = 0.01
+local vdelta = 0.2
+local yaw, pitch = 0,0
+
+local canvas = p.canvas()
+canvas.clear()
+local htext = canvas.addText({x=5,y=5}, tostring(hstrength))
+htext.setScale(3)
+htext.setAlpha(0)
+local vtext = canvas.addText({x=5,y=20}, tostring(vstrength))
+
+local function strengthclamp(x) return math.max(math.min(x,4),0) end
+
+parallel.waitForAny(
+ function() while true do
+ if hover then p.launch(0,-90,vstrength) end
+ end end,
+ function() while true do
+ vtext.setText(tostring(vstrength))
+ htext.setText(tostring(hstrength))
+ local _,key = os.pullEvent"key"
+ if key == 265 then hstrength=hstrength+hdelta
+ elseif key == 264 then hstrength=hstrength-hdelta
+ elseif key == 262 then vstrength=vstrength+vdelta
+ elseif key == 263 then vstrength=vstrength+vdelta
+ elseif key == 67 then p.launch(yaw, pitch, vstrength)
+ elseif key == 86 then hover = not hover
+ htext.setAlpha(hover and 255 or 0)
+ end
+ hstrength = strengthclamp(hstrength)
+ vstrength = strengthclamp(vstrength)
+ end end,
+ function() while true do
+ local player for i,e in ipairs(p.sense()) do
+ if e.key=="minecraft:player" and e.name=="ubq323" then player=e break
+ end end
+ assert(player, "couldnt find player??")
+ pitch,yaw = player.pitch, player.yaw
+ end end
+)
+