Konami Code Key Combo

Detect a specific sequence of key presses using the Keyboard Key Combo system and trigger an event when the sequence is completed.

Konami Code Key Combo, running
1024 × 768
GitHub
class Example extends Phaser.Scene
{
    create ()
    {

        //  37 = LEFT
        //  38 = UP
        //  39 = RIGHT
        //  40 = DOWN

        const combo = this.input.keyboard.createCombo([ 38, 38, 38, 40, 40, 40, 37, 37, 37, 39, 39, 39 ], { resetOnMatch: true });

        this.input.keyboard.on('keycombomatch', event =>
        {

            console.log('Konami Code entered!');

        });

    }
}

const config = {
    scale: { mode: Phaser.Scale.FIT },
    type: Phaser.CANVAS,
    parent: 'game-container',
    scene: Example
};

const game = new Phaser.Game(config);

More in Keyboard22 examples