Mercurial > fife-parpg
comparison demos/rpg/scripts/scene.py @ 540:2e739ae9a8bc
Some misc code cleanup.
Added the EnterPortalAction action.
You can now move between town and level1.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Tue, 01 Jun 2010 19:17:30 +0000 |
parents | 764510a6d2f9 |
children | 67f6f3538e88 |
comparison
equal
deleted
inserted
replaced
539:4c7b5eee211c | 540:2e739ae9a8bc |
---|---|
34 from scripts.actors.baseactor import Actor | 34 from scripts.actors.baseactor import Actor |
35 from scripts.actors.questgiver import QuestGiver | 35 from scripts.actors.questgiver import QuestGiver |
36 from scripts.quests.basequest import Quest | 36 from scripts.quests.basequest import Quest |
37 from scripts.actors.player import Player | 37 from scripts.actors.player import Player |
38 from scripts.objects.baseobject import GameObjectTypes | 38 from scripts.objects.baseobject import GameObjectTypes |
39 from scripts.objects.items import BaseItem, GoldStack | 39 from scripts.objects.items import BaseItem, GoldStack, Portal |
40 from scripts.misc.exceptions import ObjectNotFoundError, ObjectAlreadyInSceneError | 40 from scripts.misc.exceptions import ObjectNotFoundError, ObjectAlreadyInSceneError |
41 | 41 |
42 class Scene(object): | 42 class Scene(object): |
43 def __init__(self, gamecontroller): | 43 def __init__(self, gamecontroller): |
44 self._gamecontroller = gamecontroller | 44 self._gamecontroller = gamecontroller |
61 itemdict = self._objectsettings.get("items", itemid, {}) | 61 itemdict = self._objectsettings.get("items", itemid, {}) |
62 modeldict = self._modelsettings.get("models", itemdict["typename"], {}) | 62 modeldict = self._modelsettings.get("models", itemdict["typename"], {}) |
63 | 63 |
64 loadImportFile(modeldict["file"], self._gamecontroller.engine) | 64 loadImportFile(modeldict["file"], self._gamecontroller.engine) |
65 | 65 |
66 if itemdict["typename"] == "GoldStack": | 66 if modeldict["type"] == "GOLD": |
67 newitem = GoldStack(self._gamecontroller, modeldict["model"], itemid) | 67 newitem = GoldStack(self._gamecontroller, modeldict["model"], itemid) |
68 newitem.value = itemdict["value"] | 68 newitem.value = itemdict["value"] |
69 elif modeldict["type"] == "PORTAL": | |
70 print "portal" | |
71 newitem = Portal(self._gamecontroller, modeldict["model"], itemid) | |
72 newitem.dest = itemdict["dest"] | |
69 else: | 73 else: |
70 newitem = BaseItem(self._gamecontroller, modeldict["model"], itemid) | 74 newitem = BaseItem(self._gamecontroller, modeldict["model"], itemid) |
71 | 75 |
72 newitem.setMapPosition(float(itemdict["posx"]), float(itemdict["posy"])) | 76 newitem.setMapPosition(float(itemdict["posx"]), float(itemdict["posy"])) |
73 | 77 |
111 | 115 |
112 def loadItems(self, mapfilename): | 116 def loadItems(self, mapfilename): |
113 for item in self._objectsettings.get("items", "itemlist", []): | 117 for item in self._objectsettings.get("items", "itemlist", []): |
114 try: | 118 try: |
115 newitem = self.loadItem(item) | 119 newitem = self.loadItem(item) |
120 self._gamecontroller.logger.log_debug("Loaded item: " + item) | |
116 except ObjectNotFoundError, e: | 121 except ObjectNotFoundError, e: |
117 self._gamecontroller.logger.log_error("Error while loading item: " + item) | 122 self._gamecontroller.logger.log_error("Error while loading item: " + item) |
118 continue | 123 continue |
119 | 124 |
120 try: | 125 try: |
124 | 129 |
125 def loadActors(self, mapfilename): | 130 def loadActors(self, mapfilename): |
126 for npc in self._objectsettings.get("npcs", "npclist", []): | 131 for npc in self._objectsettings.get("npcs", "npclist", []): |
127 try: | 132 try: |
128 actor = self.loadActor(npc) | 133 actor = self.loadActor(npc) |
134 self._gamecontroller.logger.log_debug("Loaded actor: " + npc) | |
129 except ObjectNotFoundError, e: | 135 except ObjectNotFoundError, e: |
130 self._gamecontroller.logger.log_error("Error while loading actor:" + actor) | 136 self._gamecontroller.logger.log_error("Error while loading actor:" + npc) |
131 continue | 137 continue |
132 | 138 |
133 try: | 139 try: |
134 self.addObjectToScene(actor) | 140 self.addObjectToScene(actor) |
135 except ObjectAlreadyInSceneError, e: | 141 except ObjectAlreadyInSceneError, e: |
137 | 143 |
138 def loadPlayer(self): | 144 def loadPlayer(self): |
139 """ | 145 """ |
140 @todo: once we have all art assets this should be able to load one of 3 player models | 146 @todo: once we have all art assets this should be able to load one of 3 player models |
141 """ | 147 """ |
142 modelfile = self._gamecontroller.settings.get("RPG", "AllObjectFile", "maps/allobjects.xml") | 148 modeldict = self._modelsettings.get("models", "Player", {}) |
143 modelsettings = Setting(app_name="", settings_file=modelfile) | |
144 modeldict = modelsettings.get("models", "Player", {}) | |
145 | 149 |
146 loadImportFile(modeldict["file"], self._gamecontroller.engine) | 150 loadImportFile(modeldict["file"], self._gamecontroller.engine) |
147 self._player = Player(self._gamecontroller, "warrior") | 151 self._player = Player(self._gamecontroller, "warrior") |
148 | 152 |
149 def createScene(self, mapfilename): | 153 def createScene(self, mapfilename): |
150 if not self._map: | 154 if self._map: |
151 self._map = loadMapFile(mapfilename, self._gamecontroller.engine) | |
152 else: | |
153 self.destroyScene() | 155 self.destroyScene() |
156 | |
157 self._map = loadMapFile(mapfilename, self._gamecontroller.engine) | |
154 | 158 |
155 self._mapname = os.path.splitext(os.path.basename(mapfilename))[0] | 159 self._mapname = os.path.splitext(os.path.basename(mapfilename))[0] |
156 objectfile = "maps/" + self._mapname + "_objects.xml" | 160 objectfile = "maps/" + self._mapname + "_objects.xml" |
157 modelfile = self._gamecontroller.settings.get("RPG", "AllObjectFile", "maps/allobjects.xml") | 161 modelfile = self._gamecontroller.settings.get("RPG", "AllObjectFile", "maps/allobjects.xml") |
158 | 162 |
160 self._modelsettings = Setting(app_name="", settings_file=modelfile) | 164 self._modelsettings = Setting(app_name="", settings_file=modelfile) |
161 | 165 |
162 for cam in self._map.getCameras(): | 166 for cam in self._map.getCameras(): |
163 self._cameras[cam.getId()] = cam | 167 self._cameras[cam.getId()] = cam |
164 | 168 |
165 self._cameras[self._maincameraname].setZoom(self._gamecontroller.settings.get("RPG", "DefaultZoom", 2.0)) | 169 self._cameras[self._maincameraname].setZoom(self._gamecontroller.settings.get("RPG", "DefaultZoom", 1.0)) |
166 | 170 |
167 self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer")) | 171 self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer")) |
168 self._itemlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ItemLayer", "item_layer")) | 172 self._itemlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ItemLayer", "item_layer")) |
169 | 173 |
170 self.loadItems(mapfilename) | 174 self.loadItems(mapfilename) |
171 self.loadActors(mapfilename) | 175 self.loadActors(mapfilename) |
172 | 176 |
173 #finally load the player | 177 #finally load the player |
174 self.loadPlayer() | 178 self.loadPlayer() |
175 | |
176 | 179 |
177 def destroyScene(self): | 180 def destroyScene(self): |
178 self._cameras.clear() | |
179 | |
180 self._player.destroy() | |
181 | |
182 for obj in self._objectlist.values(): | 181 for obj in self._objectlist.values(): |
183 obj.destroy() | 182 obj.destroy() |
184 | 183 |
184 self._objectlist.clear() | |
185 self._objectlist = {} | |
186 self._cameras.clear() | |
187 self._cameras = {} | |
188 | |
189 self._player.destroy() | |
190 self._player = None | |
191 | |
192 for cam in self._map.getCameras(): | |
193 cam.resetRenderers() | |
194 | |
185 if self._map: | 195 if self._map: |
186 self._gamecontroller.engine.getModel().deleteMap(self._map) | 196 self._gamecontroller.engine.getModel().deleteMap(self._map) |
197 | |
198 retval = self._gamecontroller.engine.getModel().deleteObjects() | |
187 | 199 |
188 self._map = None | 200 self._map = None |
189 self._mapname = None | 201 self._mapname = None |
190 | 202 |
191 self._actorlayer = None | 203 self._actorlayer = None |
192 self._itemlayer = None | 204 self._itemlayer = None |
193 | |
194 self._player = None | |
195 self._objectlist.clear() | |
196 | 205 |
197 self._objectsettings = None | 206 self._objectsettings = None |
198 self._modelsettings = None | 207 self._modelsettings = None |
199 | 208 |
200 def getInstancesAt(self, clickpoint, layer): | 209 def getInstancesAt(self, clickpoint, layer): |