From cdb82efa9692569bc506eb48c7540a83365a7bb3 Mon Sep 17 00:00:00 2001 From: Jeremy Thurgood Date: Fri, 16 May 2014 21:53:43 +0200 Subject: [PATCH] Konami code. --- naja/constants.py | 16 +++++++++++++++- naja/options.py | 1 + naja/scenes/menu.py | 17 ++++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/naja/constants.py b/naja/constants.py index 5442988..bee1ac5 100644 --- a/naja/constants.py +++ b/naja/constants.py @@ -91,9 +91,23 @@ KEYS = AttrDict({ 'SELECT': (pgl.K_RETURN, pgl.K_KP_ENTER), 'QUIT': (pgl.K_ESCAPE, pgl.K_q), 'SWITCH': (pgl.K_TAB,), + + 'KONAMI': ( + pgl.K_UP, pgl.K_DOWN, pgl.K_LEFT, pgl.K_RIGHT, pgl.K_a, pgl.K_b), }) -# PALETTE +KONAMI_CODE = [ + pgl.K_UP, + pgl.K_UP, + pgl.K_DOWN, + pgl.K_DOWN, + pgl.K_LEFT, + pgl.K_RIGHT, + pgl.K_LEFT, + pgl.K_RIGHT, + pgl.K_b, + pgl.K_a, +] PALETTE = AttrDict({ 'BLACK': (0, 0, 0), diff --git a/naja/options.py b/naja/options.py index e280b67..4c5abea 100644 --- a/naja/options.py +++ b/naja/options.py @@ -42,6 +42,7 @@ def parse_args(args): if getattr(opts, k, None) is not None: options[k] = getattr(opts, k) options['save_location'] = opts.save_location + options['cheat_enabled'] = False def _get_default_save_location(): diff --git a/naja/scenes/menu.py b/naja/scenes/menu.py index a10d9b3..8d0126a 100644 --- a/naja/scenes/menu.py +++ b/naja/scenes/menu.py @@ -4,8 +4,9 @@ Main menu scene. import pygame.locals as pgl -from naja.constants import KEYS, PALETTE +from naja.constants import KEYS, PALETTE, KONAMI_CODE from naja.events import SceneChangeEvent, QuitGameEvent +from naja.options import options from naja.scenes.scene import Scene from naja.scenes.credits import CreditsScene from naja.scenes.game import GameScene @@ -65,9 +66,23 @@ class MenuScene(Scene): quit.add_callback('click', lambda event: QuitGameEvent.post()) selector.add(quit) + self.konami = [] + def scene_callback(self, scene_class): return lambda event: SceneChangeEvent.post(scene_class) + def handle_event(self, ev): + if ev.type == pgl.KEYDOWN and self.konami is not None: + if ev.key in KEYS.KONAMI: + self.konami.append(ev.key) + if self.konami == KONAMI_CODE: + options['cheat_enabled'] = True + print "Cheats enabled." + self.konami = None + elif self.konami != KONAMI_CODE[:len(self.konami)]: + self.konami = None + return super(MenuScene, self).handle_event(ev) + def handle_scene_event(self, ev): if ev.type == pgl.KEYDOWN: if ev.key in KEYS.QUIT: -- 2.34.1