Skip to content

Instantly share code, notes, and snippets.

@jiaaro
Last active June 8, 2020 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jiaaro/3875a8969aa66643f06b04dabac1ea3e to your computer and use it in GitHub Desktop.
Save jiaaro/3875a8969aa66643f06b04dabac1ea3e to your computer and use it in GitHub Desktop.
Love2d Konami Code module
--[[
Example use:
function love.keypressed(key)
konami(key, function()
love.window.showMessageBox("Konami", "the konami code was entered")
end)
end
]]
local MAX_DELAY = 1.5
local last_key_t = 0
local sequence = {"up", "up", "down", "down", "left", "right", "left", "right", "b", "a", "return"}
local i = 1
return function(key, callback)
local t = love.timer.getTime()
if (t - last_key_t) > MAX_DELAY then
i = 1
end
if sequence[i] == key then
last_key_t = t
i = i + 1
if i > #sequence then
callback()
end
else
i = 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment