Mercurial > fife-parpg
comparison demos/rpg/scripts/rpg.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 | cb7ec12214a9 |
children | 69d50e751c9a |
comparison
equal
deleted
inserted
replaced
549:c9113e23b004 | 550:d0282579668c |
---|---|
34 from fife.extensions import pychan | 34 from fife.extensions import pychan |
35 from fife.extensions.pychan import widgets | 35 from fife.extensions.pychan import widgets |
36 from fife.extensions.fife_utils import getUserDataDirectory | 36 from fife.extensions.fife_utils import getUserDataDirectory |
37 | 37 |
38 class KeyFilter(fife.IKeyFilter): | 38 class KeyFilter(fife.IKeyFilter): |
39 """ | |
40 This is the implementation of the fife.IKeyFilter class. | |
41 | |
42 Prevents any filtered keys from being consumed by guichan. | |
43 """ | |
39 def __init__(self, keys): | 44 def __init__(self, keys): |
40 fife.IKeyFilter.__init__(self) | 45 fife.IKeyFilter.__init__(self) |
41 self._keys = keys | 46 self._keys = keys |
42 | 47 |
43 def isFiltered(self, event): | 48 def isFiltered(self, event): |
44 return event.getKey().getValue() in self._keys | 49 return event.getKey().getValue() in self._keys |
45 | 50 |
46 class ApplicationListener(fife.IKeyListener, fife.ICommandListener, fife.ConsoleExecuter): | 51 class ApplicationListener(fife.IKeyListener, fife.ICommandListener, fife.ConsoleExecuter): |
52 """ | |
53 Listens for window commands, console commands and keyboard input. | |
54 | |
55 Does not process game related input. | |
56 """ | |
47 def __init__(self, engine, gamecontroller): | 57 def __init__(self, engine, gamecontroller): |
58 """ | |
59 Initializes all listeners and registers itself with the eventmanager. | |
60 """ | |
48 self._engine = engine | 61 self._engine = engine |
49 self._gamecontroller = gamecontroller | 62 self._gamecontroller = gamecontroller |
50 self._eventmanager = self._engine.getEventManager() | 63 self._eventmanager = self._engine.getEventManager() |
51 | 64 |
52 fife.IKeyListener.__init__(self) | 65 fife.IKeyListener.__init__(self) |
64 self._eventmanager.setKeyFilter(keyfilter) | 77 self._eventmanager.setKeyFilter(keyfilter) |
65 | 78 |
66 self.quit = False | 79 self.quit = False |
67 | 80 |
68 def keyPressed(self, event): | 81 def keyPressed(self, event): |
82 """ | |
83 Processes any non game related keyboar input. | |
84 """ | |
85 if event.isConsumed(): | |
86 return | |
87 | |
69 keyval = event.getKey().getValue() | 88 keyval = event.getKey().getValue() |
70 keystr = event.getKey().getAsString().lower() | 89 keystr = event.getKey().getAsString().lower() |
71 | |
72 if event.isConsumed(): | |
73 return | |
74 | 90 |
75 if keyval == fife.Key.ESCAPE: | 91 if keyval == fife.Key.ESCAPE: |
76 self.quit = True | 92 self.quit = True |
77 event.consume() | 93 event.consume() |
78 elif keyval == fife.Key.BACKQUOTE: | 94 elif keyval == fife.Key.BACKQUOTE: |
87 | 103 |
88 def onCommand(self, command): | 104 def onCommand(self, command): |
89 self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME) | 105 self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME) |
90 if self.quit: | 106 if self.quit: |
91 command.consume() | 107 command.consume() |
92 self._gamecontroller.endGame() | |
93 | 108 |
94 def onConsoleCommand(self, command): | 109 def onConsoleCommand(self, command): |
95 result = "" | 110 result = "" |
96 | 111 |
97 args = command.split(" ") | 112 args = command.split(" ") |
123 | 138 |
124 def onToolsClick(self): | 139 def onToolsClick(self): |
125 print "No tools set up yet" | 140 print "No tools set up yet" |
126 | 141 |
127 class RPGApplication(ApplicationBase): | 142 class RPGApplication(ApplicationBase): |
143 """ | |
144 The main application. It inherits fife.extensions.ApplicationBase. | |
145 | |
146 Implements ApplicationBase._pump(). | |
147 """ | |
128 def __init__(self, TDS): | 148 def __init__(self, TDS): |
129 super(RPGApplication,self).__init__(TDS) | 149 super(RPGApplication,self).__init__(TDS) |
130 self._settings = TDS | 150 self._settings = TDS |
131 | 151 |
132 pychan.init(self.engine, debug=self._settings.get("FIFE", "PychanDebug", False)) | 152 pychan.init(self.engine, debug=self._settings.get("FIFE", "PychanDebug", False)) |
140 """ | 160 """ |
141 self._listener = ApplicationListener(self.engine, self._gamecontroller) | 161 self._listener = ApplicationListener(self.engine, self._gamecontroller) |
142 return self._listener | 162 return self._listener |
143 | 163 |
144 def requestQuit(self): | 164 def requestQuit(self): |
165 """ | |
166 Sends the quit command to the application's listener. We could set | |
167 self.quitRequested to true also but this is a good example on how | |
168 to build and dispatch a fife.Command. | |
169 """ | |
145 cmd = fife.Command() | 170 cmd = fife.Command() |
146 cmd.setSource(None) | 171 cmd.setSource(None) |
147 cmd.setCommandType(fife.CMD_QUIT_GAME) | 172 cmd.setCommandType(fife.CMD_QUIT_GAME) |
148 self.engine.getEventManager().dispatchCommand(cmd) | 173 self.engine.getEventManager().dispatchCommand(cmd) |
149 | 174 |
150 def _pump(self): | 175 def _pump(self): |
151 if self._listener.quit: | 176 if self._listener.quit: |
152 self.breakRequested = True | 177 self._gamecontroller.endGame() |
178 self.quitRequested = True | |
153 else: | 179 else: |
154 self._gamecontroller.pump() | 180 self._gamecontroller.pump() |
155 | 181 |
156 | 182 |
157 def _getLogManager(self): | 183 def _getLogManager(self): |