From d79fa1abf44ba93c920cb644794386c59f80c676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sat, 29 Jun 2019 14:43:35 +0300 Subject: [PATCH] Move key config to dictionaries --- bundle/main.lua | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/bundle/main.lua b/bundle/main.lua index 2b74cf6..aa9806a 100644 --- a/bundle/main.lua +++ b/bundle/main.lua @@ -21,6 +21,18 @@ local move_repeat_counter = nil local gamemodes = {normal = 0, won = 1} local game_mode = gamemodes.normal +local direction_keys = {} +direction_keys['i'] = directions.up +direction_keys['u'] = directions.upleft +direction_keys['j'] = directions.left +direction_keys['m'] = directions.downleft +direction_keys['k'] = directions.down +direction_keys['.'] = directions.downright +direction_keys['l'] = directions.right +direction_keys['o'] = directions.upright + +local control_keys = {quit = 'q', restart = 'r'} + -- ------------------------------------------------------------------ -- Cavern generation -- ------------------------------------------------------------------ @@ -601,26 +613,13 @@ end function love.keypressed(key) last_key_pressed = key - if key == 'r' then - newGame() - elseif key == 'i' then - step(directions.up) - elseif key == 'j' then - step(directions.left) - elseif key == 'k' then - step(directions.down) - elseif key == 'l' then - step(directions.right) - elseif key == 'u' then - step(directions.upleft) - elseif key == 'm' then - step(directions.downleft) - elseif key == '.' then - step(directions.downright) - elseif key == 'o' then - step(directions.upright) - elseif key == 'q' then + + if key == control_keys.quit then love.event.quit() + elseif key == control_keys.restart then + newGame() + elseif direction_keys[key] ~= nil then + step(direction_keys[key]) elseif key == 'printscreen' then debug = true end