Sign in to follow this  
chillypacman

Key combinations (such as konami code)

Recommended Posts

I tried googling this but I can't think of a decent search term. To put it simply: what's a good algorithm that can help you detect key presses in any given order like with the konami code? I'm thinking have a vector of bools with each index corresponding to a key but I'm not sure if that's a good way of diong it...

Share this post


Link to post
Share on other sites
An array of bools wouldn't say anything about the order in witch the keys have been pressed.
I think you should let an array remember the last ten key codes.. And then for every key event check if the last x number of key codes matches any specific combination.

Share this post


Link to post
Share on other sites
A queue containing the previous x-amount of key presses.

Implement a timeout - once a key is pressed the player has a specific amount of time to press another key (say, 1 second) or it won't get added to the queue.

Pattern-match your key combinations to the array after each key press has been added, to check for successful combos.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this