# HG changeset patch # User prock@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1275077433 0 # Node ID ea26e7b6f56c3d06dce27ac8d966618cc6dd3f9d # Parent d0bce896a52629ab54a993a17e4c32001da639d9 Added the loadActor and loadItem functions so you can load single items at any time. Cleaned up the base object a bit so you can modify it's position easily. diff -r d0bce896a526 -r ea26e7b6f56c demos/rpg/objects/actors/player/warrior/object.xml --- a/demos/rpg/objects/actors/player/warrior/object.xml Fri May 28 16:25:00 2010 +0000 +++ b/demos/rpg/objects/actors/player/warrior/object.xml Fri May 28 20:10:33 2010 +0000 @@ -1,5 +1,5 @@ - + diff -r d0bce896a526 -r ea26e7b6f56c demos/rpg/objects/actors/player/warrior/walk/000.png Binary file demos/rpg/objects/actors/player/warrior/walk/000.png has changed diff -r d0bce896a526 -r ea26e7b6f56c demos/rpg/objects/actors/player/warrior/walk/animation.xml --- a/demos/rpg/objects/actors/player/warrior/walk/animation.xml Fri May 28 16:25:00 2010 +0000 +++ b/demos/rpg/objects/actors/player/warrior/walk/animation.xml Fri May 28 20:10:33 2010 +0000 @@ -1,4 +1,5 @@ - + + diff -r d0bce896a526 -r ea26e7b6f56c demos/rpg/scripts/gamecontroller.py --- a/demos/rpg/scripts/gamecontroller.py Fri May 28 16:25:00 2010 +0000 +++ b/demos/rpg/scripts/gamecontroller.py Fri May 28 20:10:33 2010 +0000 @@ -197,7 +197,19 @@ Might be useful if you want to have the game parse a command. Not sure if I am going to keep this or not. """ + result = "" + + args = command.split(" ") + for arg in args: + arg = arg.strip() + + if args[0] == "spawn": + if len(args) != 4: + result = "Usage: spawn [itemid] [posx] [posy]" + else: + result = "Success!" + return result def newGame(self): diff -r d0bce896a526 -r ea26e7b6f56c demos/rpg/scripts/objects/baseobject.py --- a/demos/rpg/scripts/objects/baseobject.py Fri May 28 16:25:00 2010 +0000 +++ b/demos/rpg/scripts/objects/baseobject.py Fri May 28 20:10:33 2010 +0000 @@ -70,6 +70,7 @@ self._id = self._name self._instance = None + self._position = fife.DoublePoint(0.0, 0.0) if not hasattr(self, "_type"): self._type = GameObjectTypes["DEFAULT"] @@ -85,6 +86,8 @@ self._instance = self._gamecontroller.scene.actorlayer.getInstance(self._id) self._instance.thisown = 0 + self._activated = True + def destroy(self): """ @@ -102,11 +105,11 @@ def setMapPosition(self, x, y): curloc = self.location - exactloc = self.location.getExactLayerCoordinates() - exactloc.x = x - exactloc.y = y + self._position = self.location.getExactLayerCoordinates() + self._position.x = x + self._position.y = y - curloc.setExactLayerCoordinates(exactloc) + curloc.setExactLayerCoordinates(self._position) self.location = curloc def _createFIFEInstance(self, layer): @@ -118,8 +121,11 @@ self._instance = layer.createInstance(self._fifeobject, fife.ModelCoordinate(0,0), self._id) fife.InstanceVisual.create(self._instance) + self._instance.thisown = 0 - + + self.setMapPosition(self._position.x,self._position.y) + def _getLocation(self): return self._instance.getLocation() @@ -137,9 +143,25 @@ def _getModelName(self): return self._name - + + def _getPosition(self): + self._position = self.location.getExactLayerCoordinates() + return (self._position.x, self._position.y) + + def _setPosition(self, tuplexy): + self.setMapPosition(tuplexy[0],tuplexy[1]) + + def _getActivated(self): + return self._activated + + def _setActivated(self, activate): + self._activated = activate + + location = property(_getLocation, _setLocation) instance = property(_getInstance) type = property(_getType) id = property(_getId) modelname = property(_getModelName) + position = property(_getPosition, _setPosition) + activated = property(_getActivated, _setActivated) diff -r d0bce896a526 -r ea26e7b6f56c demos/rpg/scripts/scene.py --- a/demos/rpg/scripts/scene.py Fri May 28 16:25:00 2010 +0000 +++ b/demos/rpg/scripts/scene.py Fri May 28 20:10:33 2010 +0000 @@ -42,6 +42,7 @@ self._gamecontroller = gamecontroller self._map = None + self._mapname = None self._maincameraname = self._gamecontroller.settings.get("RPG", "DefaultCameraName", "camera1") self._cameras = {} @@ -49,74 +50,63 @@ self._player = None self._objectlist = {} + + self._objectsettings = None + self._modelsettings = None + + def loadItem(self, itemid): + itemdict = self._objectsettings.get("items", itemid, {}) + modeldict = self._modelsettings.get("models", itemdict["typename"], {}) + + loadImportFile(modeldict["file"], self._gamecontroller.engine) + + if itemdict["typename"] == "GoldStack": + newitem = GoldStack(self._gamecontroller, modeldict["model"], itemid) + newitem.value = itemdict["value"] + else: + newitem = BaseItem(self._gamecontroller, modeldict["model"], itemid) + + newitem.setMapPosition(float(itemdict["posx"]), float(itemdict["posy"])) + + return newitem + + def loadActor(self, actorid): + objdict = self._objectsettings.get("npcs", actorid, {}) + modeldict = self._modelsettings.get("models", objdict["typename"], {}) + + loadImportFile(modeldict["file"], self._gamecontroller.engine) + + if modeldict["type"] == "QUESTGIVER": + actor = QuestGiver(self._gamecontroller, modeldict["model"], actorid, True) + questcount = self._modelsettings.get(actorid, "questcount", 0) + for x in range(1,questcount+1): + quest = "quest" + str(x) + questdict = self._modelsettings.get(actorid, quest, {}) + quest = Quest(actor, questdict['name'], questdict['desc']) + + for ritem in questdict['items'].split(" , "): + if ritem == "GoldStack": + quest.addRequiredGold(int(questdict['value'])) + else: + quest.addRequiredItem(ritem) + + actor.addQuest(quest) + + elif modeldict["type"] == "NPC": + actor = Actor(self._gamecontroller, modeldict["model"], npc, True) + + actor.setMapPosition(float(objdict["posx"]), float(objdict["posy"])) + + return actor def loadItems(self, mapfilename): - """ - @todo: create a new function "loadItem(self, itemname)" which takes care of - loading an individual item in case at some point in the game you want to - load one at some point. - """ - mapname = os.path.splitext(os.path.basename(mapfilename)) - objectfile = "maps/" + mapname[0] + "_objects.xml" - modelfile = self._gamecontroller.settings.get("RPG", "AllObjectFile", "maps/allobjects.xml") - - objectsettings = Setting(app_name="",settings_file=objectfile) - modelsettings = Setting(app_name="", settings_file=modelfile) - - for item in objectsettings.get("items", "itemlist", []): - itemdict = objectsettings.get("items", item, {}) - modeldict = modelsettings.get("models", itemdict["typename"], {}) - - loadImportFile(modeldict["file"], self._gamecontroller.engine) - - if itemdict["typename"] == "GoldStack": - newitem = GoldStack(self._gamecontroller, modeldict["model"], item) - newitem.value = itemdict["value"] - else: - newitem = BaseItem(self._gamecontroller, modeldict["model"], item) - - newitem.setMapPosition(float(itemdict["posx"]), float(itemdict["posy"])) + for item in self._objectsettings.get("items", "itemlist", []): + newitem = self.loadItem(item) self._objectlist[newitem.instance.getId()] = newitem def loadActors(self, mapfilename): - """ - @todo: create a new function "loadActor(self, actorname)" which takes care of - loading an individual actor in case at some point in the game you want to - load one at some point. - """ - mapname = os.path.splitext(os.path.basename(mapfilename)) - objectfile = "maps/" + mapname[0] + "_objects.xml" - modelfile = self._gamecontroller.settings.get("RPG", "AllObjectFile", "maps/allobjects.xml") - - objectsettings = Setting(app_name="",settings_file=objectfile) - modelsettings = Setting(app_name="", settings_file=modelfile) - - for npc in objectsettings.get("npcs", "npclist", []): - objdict = objectsettings.get("npcs", npc, {}) - modeldict = modelsettings.get("models", objdict["typename"], {}) - - loadImportFile(modeldict["file"], self._gamecontroller.engine) - - if modeldict["type"] == "QUESTGIVER": - actor = QuestGiver(self._gamecontroller, modeldict["model"], npc, True) - questcount = modelsettings.get(npc, "questcount", 0) - for x in range(1,questcount+1): - quest = "quest" + str(x) - questdict = modelsettings.get(npc, quest, {}) - quest = Quest(actor, questdict['name'], questdict['desc']) - - for ritem in questdict['items'].split(" , "): - if ritem == "GoldStack": - quest.addRequiredGold(int(questdict['value'])) - else: - quest.addRequiredItem(ritem) - - actor.addQuest(quest) - - elif modeldict["type"] == "NPC": - actor = Actor(self._gamecontroller, modeldict["model"], npc, True) - - actor.setMapPosition(float(objdict["posx"]), float(objdict["posy"])) + for npc in self._objectsettings.get("npcs", "npclist", []): + actor = self.loadActor(npc) self._objectlist[actor.instance.getId()] = actor def loadPlayer(self): @@ -135,6 +125,13 @@ self._map = loadMapFile(mapfilename, self._gamecontroller.engine) else: self.destroyScene() + + self._mapname = os.path.splitext(os.path.basename(mapfilename))[0] + objectfile = "maps/" + self._mapname + "_objects.xml" + modelfile = self._gamecontroller.settings.get("RPG", "AllObjectFile", "maps/allobjects.xml") + + self._objectsettings = Setting(app_name="",settings_file=objectfile) + self._modelsettings = Setting(app_name="", settings_file=modelfile) for cam in self._map.getCameras(): self._cameras[cam.getId()] = cam @@ -161,13 +158,19 @@ if self._map: self._gamecontroller.engine.getModel().deleteMap(self._map) - + self._map = None + self._mapname = None + self._actorlayer = None + self._itemlayer = None self._player = None self._objectlist.clear() + self._objectsettings = None + self._modelsettings = None + def getInstancesAt(self, clickpoint, layer): """ Query the main camera for instances on the specified layer.