Skip to content

Instantly share code, notes, and snippets.

@gillesv
Created March 25, 2010 11:55
Show Gist options
  • Save gillesv/343461 to your computer and use it in GitHub Desktop.
Save gillesv/343461 to your computer and use it in GitHub Desktop.
private var keyBuffer:Array = [];
private var konami:Array = [Keyboard.UP, Keyboard.UP, Keyboard.DOWN, Keyboard.DOWN, Keyboard.LEFT, Keyboard.RIGHT, Keyboard.LEFT, Keyboard.RIGHT, "a".charCodeAt(), "b".charCodeAt() ];
private var type_timeout:uint;
private function init_cheats_listener():void{
stage.addEventListener(KeyboardEvent.KEY_UP, on_cheat_key_up);
}
private function on_cheat_key_up(evt:KeyboardEvent):void{
if(type_timeout)
clearTimeout(type_timeout);
if(keyBuffer.length == konami.length)
keyBuffer.shift();
if(evt.charCode == 0)
keyBuffer.push(evt.keyCode);
else
keyBuffer.push(evt.charCode);
if(keyBuffer.join("") == konami.join(""))
trace("The konami code!");
type_timeout = setTimeout(reset_cheats, 1000);
}
private function reset_cheats():void{
keyBuffer = [];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment