Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------
- --------------
- CONTROLLER = 'Firestonnne'
- KEY_BINDS = {UP=73,DOWN=75,LEFT=74,RIGHT=76}
- LENGTH = 10
- --------------
- --------------
- rendered = true
- wormHead = {x=40, y=20}
- dir = 1
- function eventLoop(currentTime, timeRemaining)
- if (dir == 1) then wormHead.y = wormHead.y - 1
- elseif (dir == 2) then wormHead.x = wormHead.x + 1
- elseif (dir == 3) then wormHead.y = wormHead.y + 1
- elseif (dir == 4) then wormHead.x = wormHead.x - 1
- end
- tfm.exec.addConjuration(wormHead.x, wormHead.y, 500 * LENGTH)
- rendered = true
- end
- function turnRight()
- dir = dir + 1
- if (dir == 5) then dir = 1 end
- end
- function turnLeft()
- dir = dir - 1
- if (dir == 0) then dir = 4 end
- end
- function eventKeyboard(name, keyCode, down, x, y)
- if (name ~= CONTROLLER or not rendered) then return end
- if (keyCode == KEY_BINDS.UP) then
- if (dir == 2) then turnLeft()
- elseif (dir == 4) then turnRight()
- else return end
- elseif (keyCode == KEY_BINDS.DOWN) then
- if (dir == 2) then turnRight()
- elseif (dir == 4) then turnLeft()
- else return end
- elseif (keyCode == KEY_BINDS.LEFT) then
- if (dir == 1) then turnLeft()
- elseif (dir == 3) then turnRight()
- else return end
- elseif (keyCode == KEY_BINDS.RIGHT) then
- if (dir == 1) then turnRight()
- elseif (dir == 3) then turnLeft()
- else return end
- end
- rendered = false
- end
- function bindKeys()
- tfm.exec.bindKeyboard(CONTROLLER, KEY_BINDS.UP, true, true)
- tfm.exec.bindKeyboard(CONTROLLER, KEY_BINDS.DOWN, true, true)
- tfm.exec.bindKeyboard(CONTROLLER, KEY_BINDS.LEFT, true, true)
- tfm.exec.bindKeyboard(CONTROLLER, KEY_BINDS.RIGHT, true, true)
- end
- function setKeybind(keybind, key)
- if (keybind == 'up') then
- KEY_BINDS.UP = key
- elseif (keybind == 'down') then
- KEY_BINDS.DOWN = key
- elseif (keybind == 'left') then
- KEY_BINDS.LEFT = key
- elseif (keybind == 'right') then
- KEY_BINDS.RIGHT = key
- end
- bindKeys()
- end
- function setController(name)
- CONTROLLER = name
- bindKeys()
- end
- function eventChatCommand(name, cmd)
- if (name ~= CONTROLLER) then return end
- local args = {}
- for i in string.gmatch(cmd, "%S+") do table.insert(args, i) end
- if (table.getn(args) > 1 and args[1] == 'worm') then
- if (args[2] == 'reset') then start()
- elseif (table.getn(args) > 3 and args[2] == 'set') then
- if (args[3] == 'controller') then CONTROLLER = args[4]
- elseif (args[3] == 'length') then LENGTH = tonumber(args[4])
- elseif (args[3] == 'keybind' and args[4] == 'default') then
- KEY_BINDS = {UP=73,DOWN=75,LEFT=74,RIGHT=76}
- bindKeys()
- elseif (table.getn(args) > 4 and args[3] == 'keybind') then
- setKeybind(args[4], tonumber(args[5]))
- end
- end
- end
- end
- function start()
- system.disableChatCommandDisplay('worm', true)
- bindKeys()
- dir = 1
- wormHead = {x=40, y=20}
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement