Mercurial > fife-parpg
diff demos/rpg/scripts/gamecontroller.py @ 550:d0282579668c
Added QuestManager. The player can now move from map to map and the state of the quests remains persistent. Both quests the NPC gives you are now completable. Still have to clean up the quest loading code.
Started adding more comments.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 15 Jun 2010 17:53:20 +0000 |
parents | e59ece21ab3e |
children | 3b933753cba8 |
line wrap: on
line diff
--- a/demos/rpg/scripts/gamecontroller.py Fri Jun 11 21:29:58 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Tue Jun 15 17:53:20 2010 +0000 @@ -36,9 +36,14 @@ from scripts.actors.baseactor import TalkAction, PickUpItemAction, EnterPortalAction from scripts.objects.baseobject import GameObjectTypes from scripts.misc.exceptions import ObjectNotFoundError, ObjectAlreadyInSceneError +from scripts.quests.questmanager import QuestManager class KeyState(object): + """ + Holds the current state of the keys on the keyboard (down or up). + False = down, True = up. + """ def __init__(self): self._keystate = { } @@ -52,9 +57,19 @@ return False def reset(self): + """ + Empties the keystate dictionary (assumes all keys are False) + """ self._keystate.clear() class GameListener(fife.IKeyListener, fife.IMouseListener): + """ + Main game listener. Listens for Mouse and Keyboard events. + + This class also has the ability to attach and detach itself from + the event manager in cases where you do not want input processed (i.e. when + the main menu is visible). It is NOT attached by default. + """ def __init__(self, gamecontroller): self._engine = gamecontroller.engine self._gamecontroller = gamecontroller @@ -69,6 +84,9 @@ self._lastmousepos = (0.0,0.0) def attach(self): + """ + Attaches to the event manager. + """ if not self._attached: self._gamecontroller.keystate.reset() self._eventmanager.addMouseListenerFront(self) @@ -76,6 +94,9 @@ self._attached = True def detach(self): + """ + Detaches from the event manager. + """ if self._attached: self._eventmanager.removeMouseListener(self) self._eventmanager.removeKeyListener(self) @@ -180,6 +201,12 @@ self._gamecontroller.keystate.updateKey(keyval, False) class GameController(object): + """ + The main game class. + + This handles all game related code including setting up the scene, displaying user + interfaces, managing sound, etc etc. + """ def __init__(self, application, engine, settings): self._application = application self._engine = engine @@ -195,6 +222,8 @@ self._guicontroller.showMainMenu() + self._questmanager = QuestManager(self) + self._scene = None self._instancerenderer = None self._floatingtextrenderer = None @@ -204,8 +233,7 @@ def onConsoleCommand(self, command): """ - Might be useful if you want to have the game parse a command. - Not sure if I am going to keep this or not. + Parses game related console commands. """ result = "" @@ -257,6 +285,10 @@ return result def newGame(self): + """ + Removes any save games and starts a new game. + """ + self._guicontroller.hideMainMenu() for filename in glob.glob(os.path.join("saves" , "*.xml")): @@ -267,6 +299,10 @@ def loadMap(self, mapname): + """ + Creates the scene for the map and attaches the listener. + """ + if self._listener: self._listener.detach() @@ -288,6 +324,10 @@ self._listener.attach() def switchMap(self, newmapname): + """ + Queues a map switch for next frame. This must be done next frame to ensure + all events pertaining to the current frame have finished being processed. + """ self._switchmaprequested = True self._newmap = newmapname @@ -295,6 +335,9 @@ self._scene.serialize() def endGame(self): + """ + Saves the game state and destroys the scene. + """ if self._scene: self._scene.serialize() @@ -321,6 +364,9 @@ def _getGUIController(self): return self._guicontroller + def _getQuestManager(self): + return self._questmanager + def _getEngine(self): return self._engine @@ -340,6 +386,7 @@ return self._application.logger guicontroller = property(_getGUIController) + questmanager = property(_getQuestManager) engine = property(_getEngine) settings = property(_getSettings) scene = property(_getScene)