+import pygame.locals as pgl
+
from naja.attrdict import AttrDict
# Player States
MOVE = 1
ACT = 2
+
+KEYS = AttrDict({
+ 'UP': (pgl.K_UP, pgl.K_w, pgl.K_COMMA),
+ 'DOWN': (pgl.K_DOWN, pgl.K_s, pgl.K_o),
+ 'LEFT': (pgl.K_LEFT, pgl.K_a),
+ 'RIGHT': (pgl.K_RIGHT, pgl.K_d, pgl.K_e),
+
+ 'SELECT': (pgl.K_RETURN, pgl.K_KP_ENTER),
+ 'QUIT': (pgl.K_ESCAPE, pgl.K_q),
+})
import pygame.locals as pgl
+from naja.constants import KEYS
from naja.scenes.scene import Scene
from naja.widgets.text import TextWidget, TextBoxWidget
from naja.events import SceneChangeEvent
box_width=100))
def handle_scene_event(self, ev):
- if ev.type == pgl.KEYUP and ev.key in (pgl.K_q, pgl.K_ESCAPE):
+ if ev.type == pgl.KEYUP and ev.key in KEYS.QUIT:
from naja.scenes.menu import MenuScene
SceneChangeEvent.post(MenuScene)
return
import pygame.locals as pgl
+from naja.constants import KEYS
from naja.events import SceneChangeEvent
from naja.scenes.scene import Scene
from naja.widgets.board import BoardWidget
def handle_scene_event(self, ev):
from naja.scenes.menu import MenuScene
- if ev.type == pgl.KEYUP and ev.key in (pgl.K_q, pgl.K_ESCAPE):
+ if ev.type == pgl.KEYUP and ev.key in KEYS.QUIT:
SceneChangeEvent.post(MenuScene)
return
import pygame.locals as pgl
+from naja.constants import KEYS
from naja.scenes.scene import Scene
from naja.widgets.text import TextWidget
from naja.widgets.selector import SelectorWidget
def handle_scene_event(self, ev):
if ev.type == pgl.KEYDOWN:
- if ev.key in (pgl.K_q, pgl.K_ESCAPE):
+ if ev.key in KEYS.QUIT:
QuitGameEvent.post()
return
import pygame
import pygame.locals as pgl
-from naja.constants import INFO_SIZE, EIGHT_BIT_SCALE, MOVE, ACT
+from naja.constants import INFO_SIZE, EIGHT_BIT_SCALE, MOVE, ACT, KEYS
from naja.events import InvalidateTheWorld
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT
if self.state.gameboard.player_mode == MOVE:
return super(InfoAreaWidget, self).handle_event(ev)
if ev.type == pgl.KEYDOWN:
- if ev.key in (pgl.K_RETURN, pgl.K_KP_ENTER):
+ if ev.key in KEYS.SELECT:
action = self.card.actions[self.chosen]
if not action.check_available(self.state.gameboard.player):
print "BEEP!"
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
- if ev.key in (pgl.K_UP, pgl.K_w, pgl.K_COMMA):
+ if ev.key in KEYS.UP:
if self.chosen > 0:
self.chosen -= 1
InvalidateTheWorld.post()
return True
- if ev.key in (pgl.K_DOWN, pgl.K_s, pgl.K_o):
+ if ev.key in KEYS.DOWN:
if self.chosen + 1 < len(self.card.actions):
self.chosen += 1
InvalidateTheWorld.post()
import pygame.locals as pgl
-from naja.constants import PLAYER_SIZE, BIT_SIZE, TILE_SIZE, BITS, ACT
+from naja.constants import PLAYER_SIZE, BIT_SIZE, TILE_SIZE, BITS, ACT, KEYS
from naja.events import InvalidateTheWorld
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT
if self.state.gameboard.player_mode == ACT:
return super(RobotWidget, self).handle_event(ev)
if ev.type == pgl.KEYDOWN:
- if ev.key in (pgl.K_UP, pgl.K_w, pgl.K_COMMA):
+ if ev.key in KEYS.UP:
if self.state.player.move(BITS.NORTH):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
- if ev.key in (pgl.K_DOWN, pgl.K_s, pgl.K_o):
+ if ev.key in KEYS.DOWN:
if self.state.player.move(BITS.SOUTH):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
- if ev.key in (pgl.K_LEFT, pgl.K_a):
+ if ev.key in KEYS.LEFT:
if self.state.player.move(BITS.WEST):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
- if ev.key in (pgl.K_RIGHT, pgl.K_d, pgl.K_e):
+ if ev.key in KEYS.RIGHT:
if self.state.player.move(BITS.EAST):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
import pygame.locals as pgl
+from naja.constants import KEYS
from naja.widgets.base import Container
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT, R270
def handle_event(self, ev):
if ev.type == pgl.KEYDOWN:
- if ev.key in (pgl.K_DOWN, pgl.K_s, pgl.K_o,
- pgl.K_UP, pgl.K_w, pgl.K_COMMA):
- if ev.key in (pgl.K_DOWN, pgl.K_s, pgl.K_o):
+ if ev.key in KEYS.UP + KEYS.DOWN:
+ if ev.key in KEYS.DOWN:
self.position += 1
else:
self.position -= 1
self.position %= len(self.widgets)
return True
- elif ev.key in (pgl.K_RETURN, pgl.K_KP_ENTER):
+ elif ev.key in KEYS.SELECT:
return self.widgets[self.position].callback('click')
return super(SelectorWidget, self).handle_event(ev)