Last active
June 8, 2020 15:07
-
-
Save jiaaro/3875a8969aa66643f06b04dabac1ea3e to your computer and use it in GitHub Desktop.
Love2d Konami Code module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
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