- Timestamp:
- 10/31/09 15:11:33 (10 years ago)
- Location:
- trunk/game
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/game/maps/map.xml
r355 r356 14 14 <import file="../objects/agents/player/player.xml" /> 15 15 <import file="../objects/buildings/container_house/container_house.xml" /> 16 <import file="../objects/buildings/shanty/shanty-door.xml" /> 16 17 <layer grid_type="square" id="GroundLayer" pathing="cell_edges_only" rotation="0.0" transparency="0" x_offset="0.0" x_scale="1.0" y_offset="0.0" y_scale="1.0"> 17 18 <instances> … … 1869 1870 <i o="block" r="0" x="-1.0" y="-3.0" z="0.0" /> 1870 1871 <i o="container_house" r="0" x="0.0" y="0.0" z="0.0" /> 1872 <i gfx="shanty-door" id="shanty-door01" is_open="False" name="Shanty Door" o="shanty-door" object_type="ShantyDoor" r="0" target_map="maps/map2.xml" target_map_name="map2" target_x="10.0" target_y="10.0" text="Looks like the entrance to the building." x="-2.0" xpos="-2.0" y="6.0" ypos="6.0" z="0.0" /> 1871 1873 </instances> 1872 1874 </layer> -
trunk/game/maps/map2.xml
r340 r356 11 11 <import file="../objects/buildings/windmill/windmilld.xml"></import> 12 12 <import file="../objects/buildings/windmill/windmille.xml"></import> 13 13 14 <import file="../objects/buildings/shanty/shanty-door.xml" /> 15 14 16 <layer grid_type="square" id="GroundLayer" x_scale="1.0" pathing="cell_edges_only" y_scale="1.0" rotation="0.0" x_offset="0.0" y_offset="0.0"> 15 17 <instances> … … 1023 1025 <i x="8" o="windmille" z="0.0" y="-2" r="0"></i> 1024 1026 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 1027 <!-- A sample door --> 1036 1028 <i x="-2.0" o="shanty-door" z="0.0" y="6.0" r="0" id="shanty-door01" object_type="ShantyDoor" is_open="False" 1037 1029 name="Shanty Door" text="Looks like the entrance to the building." target_map_name="main-map" target_map="maps/map.xml" 1038 target_x=" 0.0" target_y="0.0"></i>1030 target_x="5.0" target_y="5.0"></i> 1039 1031 1040 1032 </instances> -
trunk/game/scripts/engine.py
r341 r356 54 54 fname = '/'.join([path, filename]) 55 55 try: 56 f = open(fname, 'w ')56 f = open(fname, 'wb') 57 57 except(IOError): 58 58 sys.stderr.write("Error: Can't find save game: " + fname + "\n") 59 59 return 60 61 # save the PC coordinates before we destroy the behaviour 62 coords = self.game_state.PC.behaviour.agent.getLocation().\ 63 getMapCoordinates() 64 self.game_state.saved_pc_coordinates = (coords.x, coords.y) 60 65 61 66 # can't pickle SwigPyObjects … … 84 89 self.game_state.PC.behaviour = behaviour_player 85 90 86 def load(self, filename):91 def load(self, path, filename): 87 92 """Loads a saver from a file. 88 93 @type filename: string 89 94 @param filename: the name of the file (including path) to load from 90 95 @return: None""" 91 92 # TODO 93 # Remove what we are currently working with 94 print "TODO: load" 95 self.view.active_map.view.clearCameras() 96 self.view.active_map.model.deleteMaps() 97 96 97 fname = '/'.join([path, filename]) 98 98 99 try: 99 f = open(f ilename, 'r')100 f = open(fname, 'rb') 100 101 except(IOError): 101 102 sys.stderr.write("Error: Can't find save game file\n") 102 103 return 104 105 #Remove all currently loaded maps so we can start fresh 106 self.view.deleteMaps(); 107 103 108 self.game_state = pickle.load(f) 104 109 f.close() 105 110 106 # Make sure we're on the right map 111 # Recreate all the behaviours. These can't be saved because FIFE 112 # objects cannot be pickled 113 for map_id in self.game_state.objects: 114 for (object_id, npc) in self.game_state.objects[map_id].items(): 115 if npc.trueAttr("NPC"): 116 npc.createBehaviour(self.view.active_map.agent_layer) 117 118 # Fix the player behaviour 119 self.game_state.PC.createBehaviour(self.view.active_map.agent_layer) 120 121 #In most maps we'll create the PC Instance internally. In these 122 #cases we need a target position 123 self.target_position = self.game_state.saved_pc_coordinates 124 125 #Load the current map 107 126 if self.game_state.current_map_file: 108 127 self.loadMap(self.game_state.current_map_name, \ 109 128 self.game_state.current_map_file) 110 129 111 130 def createObject (self, layer, attributes, instance): 112 131 """Create an object and add it to the current map. … … 258 277 self.view.loadMap(map_name, str(map_file)) 259 278 260 # If the map has been loaded, we might need to add some261 # agents to the PC and NPS262 for map_id in self.game_state.objects:263 for (object_id, npc) in self.game_state.objects[map_id].items():264 if npc.trueAttr("NPC") and npc.behaviour == None:265 npc.createBehaviour(self.view.active_map.agent_layer)266 267 # Fix the player behaviour268 if self.game_state.PC.behaviour == None:269 self.game_state.PC.createBehaviour(self.view.active_map.agent_layer)270 271 279 # create the PC agent 272 280 self.view.active_map.addPC() -
trunk/game/scripts/filebrowser.py
r313 r356 113 113 self._widget.hide() 114 114 selection = self._widget.collectData('fileList') 115 data = self._widget.collectData('saveField')116 115 117 116 if self.save_file: 117 data = self._widget.collectData('saveField') 118 118 if data: 119 119 if (data.split('.')[1] == 'dat'): -
trunk/game/scripts/gamestate.py
r314 r356 26 26 self.current_map_file = None 27 27 self.current_map_name = None 28 #these coordinates are only used for saving and loading the game. 29 #They do not represent the pc's active location 30 self.saved_pc_coordinates = (0,0) 28 31 29 32 def getObjectsFromMap(self, map_id): … … 45 48 if obj_id in self.objects[map_id]: 46 49 return self.objects[map_id][obj_id] 47 50 -
trunk/game/scripts/map.py
r340 r356 80 80 self.map = loadMapFile(filename, self.engine, self.data) 81 81 self.agent_layer = self.map.getLayer('ObjectLayer') 82 83 # if this is not the very first map load in the game carry over the PC instance 84 if self.data.target_position: 82 83 #find out if a PC instance was created when the map was loaded 84 found = False 85 for inst in self.agent_layer.getInstances(): 86 if inst.getId() == "PC": 87 found = True 88 break 89 90 #If there is not a PC instance created yet than we construct the PC 91 #instance from what we have saved in the PC Game Object 92 if not found: 85 93 x = float(self.data.target_position[0]) 86 94 y = float(self.data.target_position[1]) … … 90 98 fife.ExactModelCoordinate(x,y,z),\ 91 99 "PC") 92 inst.setRotation(self.data.game_state.PC.behaviour.agent.getRotation())93 100 fife.InstanceVisual.create(inst) 94 101 #If the PC instance exists already then make sure it's set to correct 102 #location for this new map 103 elif self.data.target_position is not None: 104 pos = self.data.target_position 105 coord = fife.DoublePoint3D(float(pos[0]), float(pos[1]), 0) 106 location = fife.Location(self.agent_layer) 107 location.setMapCoordinates(coord) 108 inst.setLocation(location) 109 #else we are loading the first map and the PC position were set by 110 #the coordinates in the Map file 111 95 112 # it's possible there's no transition layer 96 113 size = len('TransitionLayer') … … 120 137 strip=False))) 121 138 rend.changeDefaultFont(text) 122 139 123 140 # Make World aware that this is now the active map. 124 141 self.data.view.active_map = self -
trunk/game/scripts/objects/actors.py
r340 r356 68 68 self.speed = float(TDS.readSetting("PCSpeed")) # TODO: rework/improve 69 69 self.nextAction = None 70 self.agent = None 70 71 71 72 def onInstanceActionFinished(self, instance, action): … … 90 91 """Sets the agent onto the new layer. 91 92 """ 92 self.agent.removeActionListener(self) 93 if self.agent is not None: 94 self.agent.removeActionListener(self) 95 93 96 self.agent = layer.getInstance(self.parent.ID) 94 97 self.agent.addActionListener(self) -
trunk/game/scripts/world.py
r340 r356 235 235 @return: None""" 236 236 click = fife.ScreenPoint(evt.getX(), evt.getY()) 237 i=self.active_map.cameras[self.active_map.my_cam_id]. getMatchingInstances(click,\238 237 i=self.active_map.cameras[self.active_map.my_cam_id].\ 238 getMatchingInstances(click, self.active_map.agent_layer) 239 239 # no object returns an empty tuple 240 240 if(i != ()): … … 248 248 obj_map_coords = \ 249 249 obj.getLocation().getMapCoordinates() 250 obj_screen_coords = self.active_map.cameras["main"]\ 251 .toScreenCoordinates(obj_map_coords) 250 obj_screen_coords = self.active_map.\ 251 cameras[self.active_map.my_cam_id]\ 252 .toScreenCoordinates(obj_map_coords) 252 253 253 254 if obj_screen_coords.y > front_y: … … 274 275 @rtype: fife.Location 275 276 @return: The map coordinates""" 276 coord = self.active_map.cameras[self.active_map.my_cam_id].toMapCoordinates(click, False) 277 coord = self.active_map.cameras[self.active_map.my_cam_id].\ 278 toMapCoordinates(click, False) 277 279 coord.z = 0 278 280 location = fife.Location(self.active_map.agent_layer) 279 281 location.setMapCoordinates(coord) 280 282 return location 283 284 def deleteMaps(self): 285 """Clear all currently loaded maps from FIFE as well as clear our 286 local map cache 287 @return: nothing""" 288 self.engine.getView().clearCameras() 289 self.engine.getModel().deleteMaps() 290 self.engine.getModel().deleteObjects() 291 292 self.maps = {} 281 293 282 294 def pump(self):
Note: See TracChangeset
for help on using the changeset viewer.