From: Jeremy Thurgood Date: Fri, 16 May 2014 19:53:43 +0000 (+0200) Subject: Konami code. X-Git-Tag: 0.1~194 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=cdb82efa9692569bc506eb48c7540a83365a7bb3;p=naja.git Konami code. --- 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: