Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Pilot: A simple program to manipulate a turtle with the keyboard
- --
- if term.isColor() then
- HEADER_COLOR = colors.blue
- HEADER_TEXT_COLOR = colors.white
- else
- HEADER_COLOR = colors.white
- HEADER_TEXT_COLOR = colors.black
- end
- local keytable = {
- ['17'] = 'f', ['200'] = 'f',
- ['30'] = 'l', ['203'] = 'l',
- ['31'] = 'b', ['208'] = 'b',
- ['32'] = 'r', ['205'] = 'r',
- ['42'] = 'd', ['54'] = 'd',
- ['57'] = 'u',
- ['16'] = 'q'
- }
- function lAndRAligned(left, right)
- local maxx, maxy = term.getSize()
- local padding = maxx - (string.len(left) + string.len(right))
- return left .. string.rep(' ', padding) .. right
- end
- function printUsage()
- term.clear()
- term.setBackgroundColor(HEADER_COLOR)
- term.setTextColor(HEADER_TEXT_COLOR)
- term.setCursorPos(1, 1)
- term.write(lAndRAligned('Pilot', '0.2-alpha'))
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- term.setCursorPos(1, 2)
- print('W or Up Arrow: Forward')
- print('A or Left Arrow: Turn left')
- print('S or Down Arrow: Back')
- print('D or Right Arrow: Turn right')
- print('Space: Go up')
- print('LShift or RShift: Go down')
- if term.isColor() then
- print('Mouse scroll: Change selected slot')
- print('Left click: Break/Attack front')
- print('Right click: Place selected block')
- end
- print('Q: Quit')
- end
- printUsage()
- while true do
- local e, v1, v2, v3 = os.pullEvent()
- if e == 'key' then
- local dir = keytable[tostring(v1)]
- if dir == 'f' then turtle.forward()
- elseif dir == 'l' then turtle.turnLeft()
- elseif dir == 'b' then turtle.back()
- elseif dir == 'r' then turtle.turnRight()
- elseif dir == 'u' then turtle.up()
- elseif dir == 'd' then turtle.down()
- elseif dir == 'q' then
- os.queueEvent('tmp')
- os.pullEvent() --Clear leftover events
- break
- end
- elseif e == 'mouse_scroll' then
- if turtle.getSelectedSlot() + v1 == 0 then v1 = v1 + 16
- elseif turtle.getSelectedSlot() + v1 == 17 then v1 = v1 - 16
- end
- turtle.select(turtle.getSelectedSlot() + v1)
- elseif e == 'mouse_click' then
- if v1 == 1 then turtle.attack(); turtle.dig()
- elseif v1 == 2 then turtle.place()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement