Created
March 25, 2010 11:55
-
-
Save gillesv/343461 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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