Move key config to dictionaries

This commit is contained in:
Juhani Krekelä 2019-06-29 14:43:35 +03:00
parent 6617a243ce
commit d79fa1abf4
1 changed files with 18 additions and 19 deletions

View File

@ -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