comparison demos/rpg/scripts/scene.py @ 520:b6bd314df28a

Added a quest dialog. Added QuestGiver class. Moved level specific settings to another file. Added BaseItem class.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 27 May 2010 16:29:07 +0000
parents 14f777be6b94
children 494c60cf61cf
comparison
equal deleted inserted replaced
519:14f777be6b94 520:b6bd314df28a
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 from fife.extensions.loaders import loadMapFile 30 from fife.extensions.loaders import loadMapFile
31 from fife.extensions.fife_settings import Setting
31 32
32 from scripts.actors.baseactor import Actor 33 from scripts.actors.baseactor import Actor
34 from scripts.actors.baseactor import QuestGiver
33 from scripts.actors.player import Player 35 from scripts.actors.player import Player
36 from scripts.objects.baseobject import GameObjectTypes
34 37
35 class Scene(object): 38 class Scene(object):
36 def __init__(self, gamecontroller): 39 def __init__(self, gamecontroller):
37 self._gamecontroller = gamecontroller 40 self._gamecontroller = gamecontroller
38 41
41 self._cameras = {} 44 self._cameras = {}
42 45
43 self._actorlayer = None 46 self._actorlayer = None
44 47
45 self._player = None 48 self._player = None
46 self._npclist = [] 49 self._objectlist = {}
47 50
48 def createScene(self, mapfilename): 51 def createScene(self, mapfilename):
49 if not self._map: 52 if not self._map:
50 self._map = loadMapFile(mapfilename, self._gamecontroller.engine) 53 self._map = loadMapFile(mapfilename, self._gamecontroller.engine)
51 else: 54 else:
59 self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer")) 62 self._actorlayer = self._map.getLayer(self._gamecontroller.settings.get("RPG", "ActorLayer", "actor_layer"))
60 63
61 self._player = Player(self._gamecontroller, "warrior") 64 self._player = Player(self._gamecontroller, "warrior")
62 65
63 mapname = os.path.splitext(os.path.basename(mapfilename)) 66 mapname = os.path.splitext(os.path.basename(mapfilename))
64 for npc in self._gamecontroller.settings.get(mapname[0], "npclist", []): 67 objectfile = "maps/" + mapname[0] + "_objects.xml"
65 (modelname, posx, posy) = self._gamecontroller.settings.get(mapname[0], npc, ["warrior", "0", "0"]) 68 objectsettings = Setting(app_name="",settings_file=objectfile)
66 actor = Actor(self._gamecontroller, modelname, npc, True) 69
70 for npc in objectsettings.get(mapname[0], "npclist", []):
71 (objtype, modelname, posx, posy) = objectsettings.get(mapname[0], npc, ["NPC", "warrior", "0", "0"])
72 if objtype == "QUESTGIVER":
73 actor = QuestGiver(self._gamecontroller, modelname, npc, True)
74 elif objtype == "NPC":
75 actor = Actor(self._gamecontroller, modelname, npc, True)
76
67 actor.setMapPosition(float(posx), float(posy)) 77 actor.setMapPosition(float(posx), float(posy))
68 self._npclist.append(actor) 78 self._objectlist[actor.instance.getId()] = actor
69 79
70 80
71 def destroyScene(self): 81 def destroyScene(self):
72 self._cameras.clear() 82 self._cameras.clear()
73 83
74 self._player.destroy() 84 self._player.destroy()
75 85
76 for npc in self._npclist: 86 for obj in self._objectlist.values():
77 npc.destroy() 87 obj.destroy()
78 88
79 if self._map: 89 if self._map:
80 self._gamecontroller.engine.getModel().deleteMap(self._map) 90 self._gamecontroller.engine.getModel().deleteMap(self._map)
81 91
82 self._map = None 92 self._map = None
83 self._actorlayer = None 93 self._actorlayer = None
84 94
85 self._player = None 95 self._player = None
86 self._npclist = [] 96 self._objectlist.clear()
87 97
88 def getInstancesAt(self, clickpoint): 98 def getInstancesAt(self, clickpoint):
89 """ 99 """
90 Query the main camera for instances on the actor layer. 100 Query the main camera for instances on the actor layer.
91 """ 101 """
112 return self._cameras 122 return self._cameras
113 123
114 def _getPlayer(self): 124 def _getPlayer(self):
115 return self._player 125 return self._player
116 126
127 def _getObjectList(self):
128 return self._objectlist
129
117 actorlayer = property(_getActorLayer) 130 actorlayer = property(_getActorLayer)
118 cameras = property(_getCameras) 131 cameras = property(_getCameras)
119 player = property(_getPlayer) 132 player = property(_getPlayer)
133 objectlist = property(_getObjectList)
120 134