Mercurial > fife-parpg
comparison demos/rpg/scripts/gamecontroller.py @ 512:6ddb1eb9dfa6
Added the Scene which loads the town map. It is no longer a black screen demo.
Changed the keys to be more common. Screenshot is now the print screen key. The console is now the backtick key. Screenshots are now date/time stamped as well.
Removed the scripts/common directory as I have removed the dependency on the EventListenerBase class.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Fri, 21 May 2010 17:31:08 +0000 |
parents | cd959b05a262 |
children | edf5c0cf52f3 |
comparison
equal
deleted
inserted
replaced
511:773dc1dbe69d | 512:6ddb1eb9dfa6 |
---|---|
26 | 26 |
27 import sys, os, re, math, random, shutil | 27 import sys, os, re, math, random, shutil |
28 | 28 |
29 from fife import fife | 29 from fife import fife |
30 | 30 |
31 from scripts.scene import Scene | |
31 from scripts.guicontroller import GUIController | 32 from scripts.guicontroller import GUIController |
32 | 33 |
34 class GameListener(fife.IKeyListener, fife.IMouseListener): | |
35 def __init__(self, gamecontroller): | |
36 self._engine = gamecontroller.engine | |
37 self._gamecontroller = gamecontroller | |
38 self._settings = gamecontroller.settings | |
39 self._eventmanager = self._engine.getEventManager() | |
40 | |
41 fife.IMouseListener.__init__(self) | |
42 self._eventmanager.addMouseListener(self) | |
43 | |
44 fife.IKeyListener.__init__(self) | |
45 self._eventmanager.addKeyListener(self) | |
46 | |
47 self._attached = False | |
48 | |
49 def attach(self): | |
50 if not self._attached: | |
51 self._eventmanager.addMouseListenerFront(self) | |
52 self._eventmanager.addKeyListenerFront(self) | |
53 self._attached = True | |
54 | |
55 def detach(self): | |
56 if self._attached: | |
57 self._eventmanager.removeMouseListener(self) | |
58 self._eventmanager.removeKeyListener(self) | |
59 self._attached = False | |
60 | |
61 def mousePressed(self, event): | |
62 pass | |
63 def mouseReleased(self, event): | |
64 pass | |
65 def mouseEntered(self, event): | |
66 pass | |
67 def mouseExited(self, event): | |
68 pass | |
69 def mouseClicked(self, event): | |
70 pass | |
71 def mouseWheelMovedUp(self, event): | |
72 pass | |
73 def mouseWheelMovedDown(self, event): | |
74 pass | |
75 def mouseMoved(self, event): | |
76 pass | |
77 def mouseDragged(self, event): | |
78 pass | |
79 def keyPressed(self, event): | |
80 keyval = event.getKey().getValue() | |
81 keystr = event.getKey().getAsString().lower() | |
82 if keyval == fife.Key.ESCAPE: | |
83 self.detach() | |
84 self._gamecontroller.guicontroller.showMainMenu() | |
85 event.consume() | |
86 | |
87 def keyReleased(self, event): | |
88 pass | |
89 | |
33 class GameController(object): | 90 class GameController(object): |
34 def __init__(self, application, engine, settings): | 91 def __init__(self, application, engine, settings): |
35 self._application = application | 92 self._application = application |
36 self._engine = engine | 93 self._engine = engine |
37 self._settings = settings | 94 self._settings = settings |
38 | 95 |
39 self._guicontroller = GUIController(self, self._engine, self._settings) | 96 self._guicontroller = GUIController(self) |
97 | |
98 self._listener = GameListener(self) | |
40 | 99 |
41 self._guicontroller.showMainMenu() | 100 self._guicontroller.showMainMenu() |
101 | |
102 self._scene = None | |
42 | 103 |
43 def onConsoleCommand(self, command): | 104 def onConsoleCommand(self, command): |
44 """ | 105 """ |
45 Might be useful if you want to have the game parse a command | 106 Might be useful if you want to have the game parse a command. |
107 Not sure if I am going to keep this or not. | |
46 """ | 108 """ |
47 result = "" | 109 result = "" |
48 return result | 110 return result |
49 | 111 |
50 def newGame(self): | 112 def newGame(self): |
51 pass | 113 self._guicontroller.hideMainMenu() |
114 | |
115 if self._scene: | |
116 self._scene.destroyScene() | |
117 self._scene = None | |
118 | |
119 self._scene = Scene(self) | |
120 self._scene.createScene(self._settings.get("RPG", "TownMapFile", "maps/town.xml")) | |
121 | |
122 #start listening to events | |
123 self._listener.attach() | |
52 | 124 |
53 def quit(self): | 125 def quit(self): |
54 self._application.requestQuit() | 126 self._application.requestQuit() |
55 | 127 |
56 def pump(self): | 128 def pump(self): |
57 pass | 129 if self._scene: |
130 self._scene.updateScene() | |
131 | |
132 | |
133 def _getGUIController(self): | |
134 return self._guicontroller | |
135 | |
136 def _getEngine(self): | |
137 return self._engine | |
138 | |
139 def _getSettings(self): | |
140 return self._settings | |
141 | |
142 guicontroller = property(_getGUIController) | |
143 engine = property(_getEngine) | |
144 settings = property(_getSettings) |