Mercurial > fife-parpg
diff demos/rpg/scripts/gamecontroller.py @ 513:edf5c0cf52f3
Added the Actor and Player classes. Actor is the base class that the player and all enemies + NPCs will inherit.
Added a help file for the console.
Added a KeyState class for keeping track of the state of the keys.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 21 May 2010 20:33:43 +0000 |
parents | 6ddb1eb9dfa6 |
children | d70fc46c8aa5 |
line wrap: on
line diff
--- a/demos/rpg/scripts/gamecontroller.py Fri May 21 17:31:08 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Fri May 21 20:33:43 2010 +0000 @@ -31,6 +31,22 @@ from scripts.scene import Scene from scripts.guicontroller import GUIController +class KeyState(object): + def __init__(self): + self._keystate = { } + + def updateKey(self, key, state): + self._keystate[key] = state + + def checkKey(self, key): + if key in self._keystate: + return self._keystate[key] + else: + return False + + def reset(self): + self._keystate.clear() + class GameListener(fife.IKeyListener, fife.IMouseListener): def __init__(self, gamecontroller): self._engine = gamecontroller.engine @@ -83,9 +99,15 @@ self.detach() self._gamecontroller.guicontroller.showMainMenu() event.consume() + + self._gamecontroller.keystate.updateKey(keyval, True) def keyReleased(self, event): - pass + keyval = event.getKey().getValue() + keystr = event.getKey().getAsString().lower() + + self._gamecontroller.keystate.updateKey(keyval, False) + class GameController(object): def __init__(self, application, engine, settings): @@ -93,6 +115,8 @@ self._engine = engine self._settings = settings + self._keystate = KeyState() + self._guicontroller = GUIController(self) self._listener = GameListener(self) @@ -112,6 +136,8 @@ def newGame(self): self._guicontroller.hideMainMenu() + self._keystate.reset() + if self._scene: self._scene.destroyScene() self._scene = None @@ -122,7 +148,13 @@ #start listening to events self._listener.attach() + def endGame(self): + if self._scene: + self._scene.destroyScene() + self._scene = None + def quit(self): + self.endGame() self._application.requestQuit() def pump(self): @@ -139,6 +171,14 @@ def _getSettings(self): return self._settings + def _getScene(self): + return self._scene + + def _getKeyState(self): + return self._keystate + guicontroller = property(_getGUIController) engine = property(_getEngine) settings = property(_getSettings) + scene = property(_getScene) + keystate = property(_getKeyState)