Make keyrepeat work for autoexplore too

This commit is contained in:
Juhani Krekelä 2019-06-30 18:46:09 +03:00
parent a85b6de70a
commit f5ba1bdb17
1 changed files with 11 additions and 13 deletions

View File

@ -21,7 +21,6 @@ local flash_player_red_counter = 0
local slimes = {}
local last_key_pressed = nil
local last_direction_moved = nil
local move_repeat_counter = nil
local gamemodes = {normal = 0, won = 1, lost = 2, config = 3}
@ -667,14 +666,6 @@ end
function step(direction)
if game_mode == gamemodes.normal then
if last_direction_moved == direction then
-- Repeat faster after the initial threshold for repetition has been met
move_repeat_counter = 0.1
else
last_direction_moved = direction
move_repeat_counter = 0.3
end
rememberVisible()
if direction ~= directions.inplace then
@ -1069,8 +1060,8 @@ end
function love.update(dt)
if move_repeat_counter ~= nil and move_repeat_counter > 0 then
move_repeat_counter = move_repeat_counter - dt
if move_repeat_counter <= 0 then
step(last_direction_moved)
if move_repeat_counter <= 0 and last_key_pressed ~= nil then
love.keypressed(last_key_pressed)
end
end
@ -1106,7 +1097,12 @@ function love.keypressed(key)
game_mode = gamemodes.normal
end
else
last_key_pressed = key
if last_key_pressed == key then
-- Repeat faster after the initial threshold for repetition has been met
move_repeat_counter = 0.1
else
move_repeat_counter = 0.3
end
if key == control_keys.configure and game_mode == gamemodes.normal then
direction_keys = {}
@ -1118,8 +1114,10 @@ function love.keypressed(key)
newGame()
elseif key == control_keys.autoexplore then
autoexplore()
last_key_pressed = key
elseif direction_keys[key] ~= nil then
step(direction_keys[key])
last_key_pressed = key
elseif key == 'pause' then
debug = not debug
end
@ -1128,7 +1126,7 @@ end
function love.keyreleased(key)
if last_key_pressed == key then
last_direction_moved = nil
last_key_pressed = nil
move_repeat_counter = nil
end
end