- Timestamp:
- 10/11/09 10:34:47 (10 years ago)
- Location:
- trunk/game
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/game/maps/map.xml
r310 r314 1975 1975 <!-- A sample door --> 1976 1976 <i x="-2.0" o="shanty-door" z="0.0" y="6.0" r="0" id="shanty-door01" object_type="ShantyDoor" is_open="False" 1977 name="Shanty Door" text="Looks like the entrance to the building." target_map_name="ma in-map" target_map="maps/map.xml"1977 name="Shanty Door" text="Looks like the entrance to the building." target_map_name="map2" target_map="maps/map2.xml" 1978 1978 target_x="10.0" target_y="10.0"></i> 1979 1979 -
trunk/game/maps/map2.xml
r147 r314 1022 1022 <i x="7" o="windmilld" z="0.0" y="-2" r="0"></i> 1023 1023 <i x="8" o="windmille" z="0.0" y="-2" r="0"></i> 1024 </instances>1025 </layer>1026 1024 1025 <i x="-4" o="shantya" z="0.0" y="3" r="0"></i> 1026 <i x="-4" o="shantyb" z="0.0" y="4" r="0"></i> 1027 <i x="-4" o="shantyc" z="0.0" y="5" r="0"></i> 1028 <i x="-4" o="shantyd" z="0.0" y="6" r="0"></i> 1029 <i x="-3" o="shantye" z="0.0" y="6" r="0"></i> 1030 <i x="-2" o="shantyf" z="0.0" y="6" r="0"></i> 1031 <i x="-1" o="shantyg" z="0.0" y="6" r="0"></i> 1032 <i x="-0" o="shantyh" z="0.0" y="6" r="0"></i> 1033 <i x="1" o="shantyi" z="0.0" y="6" r="0"></i> 1034 1035 <!-- There must be one and one only PC character --> 1036 <i x="0.0" o="PC" z="0.0" y="0.0" r="0" id="PC" object_type="PlayerCharacter"></i> 1037 1038 <!-- A sample door --> 1039 <i x="-2.0" o="shanty-door" z="0.0" y="6.0" r="0" id="shanty-door01" object_type="ShantyDoor" is_open="False" 1040 name="Shanty Door" text="Looks like the entrance to the building." target_map_name="main-map" target_map="maps/map.xml" 1041 target_x="0.0" target_y="0.0"></i> 1042 1043 </instances> 1044 </layer> 1027 1045 <camera ref_cell_width="72" zoom="1.0" tilt="-60.0" id="main" ref_layer_id="ObjectLayer" ref_cell_height="38" rotation="45.0"> 1028 1046 </camera> -
trunk/game/scripts/engine.py
r313 r314 32 32 33 33 def __init__(self, view): 34 """Initiali se the instance.34 """Initialize the instance. 35 35 @type view: world 36 36 @param view: A world instance … … 42 42 self.pc_run = 1 43 43 self.target_position = None 44 self.target_map_name = None 45 self.target_map_file = None 44 46 def reset(self): 45 47 """Clears the data on a map reload so we don't have objects/npcs from … … 95 97 if self.game_state.current_map: 96 98 self.loadMap(self.game_state.current_map_name, \ 97 self.game_state.current_map )99 self.game_state.current_map_file) 98 100 99 101 def createObject (self, layer, attributes, instance): … … 131 133 @return: None 132 134 """ 133 # add to view data135 # If this map has already a PC 134 136 self.view.active_map.addObject(pc.ID, instance) 135 137 136 # sync with game data137 if self.game_state.PC is None:138 138 # For now we copy the PC, in the future we will need to copy 139 # PC specifics between the different PC's 140 self.game_state.PC = pc 139 141 140 142 self.game_state.PC.setup() 141 142 143 143 144 def addObject(self, layer, obj, instance): … … 149 150 @type instance: fife.Instance 150 151 @param instance: FIFE instance of object 151 @return: No thing152 @return: None 152 153 """ 153 154 ref = self.game_state.getObjectById(obj.ID) 154 155 ref = self.game_state.getObjectById(obj.ID, \ 156 self.game_state.current_map_name) 155 157 if ref is None: 156 158 # no, add it to the game state 157 obj.map_id = self.game_state.current_map 158 self.game_state.objects[obj.ID] = obj 159 self.game_state.objects[self.game_state.current_map_name][obj.ID] = obj 159 160 else: 160 161 # yes, use the current game state data … … 180 181 @rtype: boolean 181 182 @return: Status of result (True/False)""" 182 for i in self.game_state.getObjectsFromMap(self.game_state.current_map ):183 for i in self.game_state.getObjectsFromMap(self.game_state.current_map_name): 183 184 if (i.ID == ident): 184 185 # we found a match … … 195 196 actions=[] 196 197 # note: ALWAYS check NPC's first! 197 obj = self.game_state.getObjectById(obj_id) 198 obj = self.game_state.getObjectById(obj_id, \ 199 self.game_state.current_map_name) 198 200 199 201 if obj is not None: … … 232 234 # TODO: work more on this when we get NPCData and HeroData straightened 233 235 # out 234 npc = self.game_state.getObjectById(npcInfo.ID) 236 npc = self.game_state.getObjectById(npcInfo.ID, \ 237 self.game_state.current_map_name) 235 238 self.game_state.PC.approach([npc.getLocation().\ 236 239 getLayerCoordinates().x, \ … … 240 243 241 244 def loadMap(self, map_name, map_file): 242 """THIS FUNCTION IS BROKEN. DO NOT USE IT YET 243 Load a new map. 245 """Load a new map. 244 246 @type map_name: string 245 247 @param map_name: Name of the map to load … … 247 249 @param map_file: Filename of map file to load 248 250 @return: None""" 249 self.game_state.current_map = map_file250 self.game_state.current_map_name = map_name251 self.game_state.current_map_file = map_file 252 self.game_state.current_map_name = map_name 251 253 self.view.loadMap(map_name, str(map_file)) 252 254 self.view.setActiveMap(map_name) 253 254 255 self.reset() 255 256 … … 257 258 self.view.active_map.addPC(self.game_state.PC.behaviour.agent) 258 259 self.game_state.PC.start() 259 260 260 261 261 def handleMouseClick(self,position): … … 269 269 self.game_state.PC.walk(position) 270 270 271 def changeMap(self, map_name, map File, target_position):271 def changeMap(self, map_name, map_file, target_position): 272 272 """Registers for a map change on the next pump(). 273 @type name Name: String273 @type name_name: String 274 274 @param map_name: Id of the map to teleport to 275 @type map File: String276 @param map File: Filename of the map to teleport to275 @type map_file: String 276 @param map_file: Filename of the map to teleport to 277 277 @type target_position: Tuple 278 278 @param target_position: Position of PC on target map. 279 279 @return None""" 280 280 # set the parameters for the map change if moving to a new map 281 print self.game_state.current_map_name282 281 if map_name != self.game_state.current_map_name: 283 self. game_state.current_map_name = map_name284 self. game_state.current_map = mapFile282 self.target_map_name = map_name 283 self.target_map_file = map_file 285 284 self.target_position = target_position 286 285 # issue the map change … … 292 291 def handleCommands(self): 293 292 if self.map_change: 294 self.loadMap(self.game_state.current_map_name, \ 295 self.game_state.current_map) 293 self.loadMap(self.target_map_name, self.target_map_file) 296 294 self.view.teleport(self.target_position) 297 295 self.map_change = False -
trunk/game/scripts/gamestate.py
r313 r314 24 24 self.PC = None 25 25 self.objects = {} 26 self.current_map = None26 self.current_map_file = None 27 27 self.current_map_name = None 28 28 … … 32 32 @param map: The map name. 33 33 @returns: The list of objects on this map.""" 34 return [i for i in self.objects .values() if i.map_id == map_id]34 return [i for i in self.objects[map_id].values() if map_id in self.objects] 35 35 36 def getObjectById(self, id): 37 """Gets an object by it's id 38 @type id: String 39 @param id: The id of the object. 36 def getObjectById(self, obj_id, map_id): 37 """Gets an object by its object id and map id 38 @type obj_id: String 39 @param obj_id: The id of the object. 40 @type map_id: String 41 @param map_id: It id of the map containing the object. 40 42 @returns: The object or None.""" 41 if id in self.objects: 42 return self.objects[id] 43 if not map_id in self.objects: 44 self.objects[map_id] = {} 45 if obj_id in self.objects[map_id]: 46 return self.objects[map_id][obj_id] 43 47 -
trunk/game/scripts/map.py
r313 r314 113 113 @return: None""" 114 114 # actually this is real easy, we just have to 115 # attach the main camera to the PC 116 self.cameras['main'].attach(agent) 115 # attach the main camera to the PC, if a camera 116 # was already used, we simply recycle it. 117 if self.cameras['main'].getAttached() == None: 118 self.cameras['main'].attach(agent) 117 119 118 120 def addObject(self, name, obj): … … 132 134 renderer = self.cameras['main'].getRenderer(str(r_name)) 133 135 renderer.setEnabled(not renderer.isEnabled()) 136
Note: See TracChangeset
for help on using the changeset viewer.