Mercurial > fife-parpg
comparison demos/rpg/scripts/scene.py @ 524:6037f79b0dcf
Multiple quests now work.
Added the item layer.
Made movement more like diablo by allowing you to hold and drag the left mouse button.
All objects are now loaded from a separate "allobjects" file. Specific item attributes are loaded from the map objects file (like position). This allows for the possibility of multiple instances using the same FIFE model.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 27 May 2010 21:11:37 +0000 |
parents | d01eb65b2726 |
children | 19db5a8619a4 |
comparison
equal
deleted
inserted
replaced
523:d01eb65b2726 | 524:6037f79b0dcf |
---|---|
32 | 32 |
33 from scripts.actors.baseactor import Actor | 33 from scripts.actors.baseactor import Actor |
34 from scripts.actors.baseactor import QuestGiver, Quest | 34 from scripts.actors.baseactor import QuestGiver, Quest |
35 from scripts.actors.player import Player | 35 from scripts.actors.player import Player |
36 from scripts.objects.baseobject import GameObjectTypes | 36 from scripts.objects.baseobject import GameObjectTypes |
37 from scripts.objects.items import BaseItem | |
37 | 38 |
38 class Scene(object): | 39 class Scene(object): |
39 def __init__(self, gamecontroller): | 40 def __init__(self, gamecontroller): |
40 self._gamecontroller = gamecontroller | 41 self._gamecontroller = gamecontroller |
41 | 42 |
45 | 46 |
46 self._actorlayer = None | 47 self._actorlayer = None |
47 | 48 |
48 self._player = None | 49 self._player = None |
49 self._objectlist = {} | 50 self._objectlist = {} |
50 | 51 |
51 def createScene(self, mapfilename): | 52 def createScene(self, mapfilename): |
52 if not self._map: | 53 if not self._map: |
53 self._map = loadMapFile(mapfilename, self._gamecontroller.engine) | 54 self._map = loadMapFile(mapfilename, self._gamecontroller.engine) |
54 else: | 55 else: |
55 self.destroyScene() | 56 self.destroyScene() |
58 self._cameras[cam.getId()] = cam | 59 self._cameras[cam.getId()] = cam |
59 | 60 |
60 self._cameras[self._maincameraname].setZoom(self._gamecontroller.settings.get("RPG", "DefaultZoom", 2.0)) | 61 self._cameras[self._maincameraname].setZoom(self._gamecontroller.settings.get("RPG", "DefaultZoom", 2.0)) |
61 | 62 |
62 self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer")) | 63 self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer")) |
64 self._itemlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ItemLayer", "item_layer")) | |
63 | 65 |
64 self._player = Player(self._gamecontroller, "warrior") | 66 self._player = Player(self._gamecontroller, "warrior") |
65 | 67 |
66 mapname = os.path.splitext(os.path.basename(mapfilename)) | 68 mapname = os.path.splitext(os.path.basename(mapfilename)) |
67 objectfile = "maps/" + mapname[0] + "_objects.xml" | 69 objectfile = "maps/" + mapname[0] + "_objects.xml" |
70 itemfile = "maps/allobjects.xml" | |
68 objectsettings = Setting(app_name="",settings_file=objectfile) | 71 objectsettings = Setting(app_name="",settings_file=objectfile) |
72 itemsettings = Setting(app_name="", settings_file=itemfile) | |
69 | 73 |
70 for npc in objectsettings.get(mapname[0], "npclist", []): | 74 for item in objectsettings.get("items", "itemlist", []): |
71 (objtype, modelname, posx, posy) = objectsettings.get(mapname[0], npc, ["NPC", "warrior", "0", "0"]) | 75 itemdict = objectsettings.get("items", item, {}) |
72 if objtype == "QUESTGIVER": | 76 modeldict = itemsettings.get("models", itemdict["typename"]) |
73 actor = QuestGiver(self._gamecontroller, modelname, npc, True) | 77 |
74 questcount = objectsettings.get(npc, "questcount", 0) | 78 newitem = BaseItem(self._gamecontroller, item, modeldict["model"]) |
79 | |
80 for npc in objectsettings.get("npcs", "npclist", []): | |
81 objdict = objectsettings.get("npcs", npc, {}) | |
82 modeldict = itemsettings.get("models", objdict["typename"]) | |
83 | |
84 if modeldict["type"] == "QUESTGIVER": | |
85 actor = QuestGiver(self._gamecontroller, modeldict["model"], npc, True) | |
86 questcount = itemsettings.get(npc, "questcount", 0) | |
75 for x in range(1,questcount+1): | 87 for x in range(1,questcount+1): |
76 quest = "quest" + str(x) | 88 quest = "quest" + str(x) |
77 (qname, qtext) = objectsettings.get(npc, quest, []) | 89 (qname, qtext) = itemsettings.get(npc, quest, []) |
78 actor.addQuest(Quest(actor, qname, qtext)) | 90 actor.addQuest(Quest(actor, qname, qtext)) |
79 | 91 |
80 elif objtype == "NPC": | 92 elif modeldict["type"] == "NPC": |
81 actor = Actor(self._gamecontroller, modelname, npc, True) | 93 actor = Actor(self._gamecontroller, modeldict["model"], npc, True) |
82 | 94 |
83 actor.setMapPosition(float(posx), float(posy)) | 95 actor.setMapPosition(float(objdict["posx"]), float(objdict["posy"])) |
84 self._objectlist[actor.instance.getId()] = actor | 96 self._objectlist[actor.instance.getId()] = actor |
85 | 97 |
86 | 98 |
87 def destroyScene(self): | 99 def destroyScene(self): |
88 self._cameras.clear() | 100 self._cameras.clear() |
121 def updateScene(self): | 133 def updateScene(self): |
122 pass | 134 pass |
123 | 135 |
124 def _getActorLayer(self): | 136 def _getActorLayer(self): |
125 return self._actorlayer | 137 return self._actorlayer |
138 | |
139 def _getItemLayer(self): | |
140 return self._itemlayer | |
126 | 141 |
127 def _getCameras(self): | 142 def _getCameras(self): |
128 return self._cameras | 143 return self._cameras |
129 | 144 |
130 def _getPlayer(self): | 145 def _getPlayer(self): |
135 | 150 |
136 def _getMap(self): | 151 def _getMap(self): |
137 return self._map | 152 return self._map |
138 | 153 |
139 actorlayer = property(_getActorLayer) | 154 actorlayer = property(_getActorLayer) |
155 itemlayer = property(_getItemLayer) | |
140 cameras = property(_getCameras) | 156 cameras = property(_getCameras) |
141 player = property(_getPlayer) | 157 player = property(_getPlayer) |
142 objectlist = property(_getObjectList) | 158 objectlist = property(_getObjectList) |
143 map = property(_getMap) | 159 map = property(_getMap) |
144 | 160 |