示例#1
0
 def load(self, filename):
     """Load a map given the filename.
        @type filename: string
        @param filename: Name of map to load
        @return: None"""
     self.reset()
     self.map = loadMapFile(filename, self.engine, self.data)
      
     # there must be a PC object on the objects layer!
     self.agent_layer = self.map.getLayer('ObjectLayer')
     
     # it's possible there's no transition layer
     size = len('TransitionLayer')
     for layer in self.map.getLayers():
         # could be many layers, but hopefully no more than 3
         if(layer.getId()[:size] == 'TransitionLayer'):
             self.transitions.append(self.map.getLayer(layer.getId()))
             
     # init the camera
     for cam in self.view.getCameras():
         self.cameras[cam.getId()] = cam
     self.view.resetRenderers()
     self.target_rotation = self.cameras['main'].getRotation()
     
     self.outline_render = fife.InstanceRenderer.getInstance(self.cameras['main'])
     
     # set the render text
     rend = fife.FloatingTextRenderer.getInstance(self.cameras['main'])
     text = self.engine.getGuiManager().createFont('fonts/rpgfont.png',
                                                    0, str(TDS.readSetting("FontGlyphs", strip=False)))
     rend.changeDefaultFont(text)
示例#2
0
文件: map.py 项目: m64/PEG
    def load(self, filename):
        """Load a map given the filename.
           @type filename: String
           @param filename: Name of map to load
           @return: None"""
        self.reset()
        self.map = loadMapFile(filename, self.engine, self.data)
        self.agent_layer = self.map.getLayer('ObjectLayer')
        self.top_layer = self.map.getLayer('TopLayer')
        
        #find out if a PC instance was created when the map was loaded
        found = False
        for inst in self.agent_layer.getInstances():
            if inst.getId() == "PC":
                found = True
                break
                
        #If there is not a PC instance created yet than we construct the PC
        #instance from what we have saved in the PC Game Object
        if not found:
            x = float(self.data.target_position[0])
            y = float(self.data.target_position[1])
            z = 0
            pc_obj = self.model.getObject("player", "PARPG")
            inst = self.agent_layer.createInstance(pc_obj,\
                                            fife.ExactModelCoordinate(x,y,z),\
                                            "PC")
            fife.InstanceVisual.create(inst)
        #If the PC instance exists already then make sure it's set to correct
        #location for this new map
        elif self.data.target_position is not None:
            pos = self.data.target_position
            coord = fife.DoublePoint3D(float(pos[0]), float(pos[1]), 0)
            location = fife.Location(self.agent_layer)
            location.setMapCoordinates(coord)
            inst.setLocation(location)
        #else we are loading the first map and the PC position were set by
        #the coordinates in the Map file
            
        # it's possible there's no transition layer
        size = len('TransitionLayer')
        for layer in self.map.getLayers():
            # could be many layers, but hopefully no more than 3
            if(layer.getId()[:size] == 'TransitionLayer'):
                self.transitions.append(self.map.getLayer(layer.getId()))

        """ Initialize the camera.
        Note that if we have more than one camera in a map file
        we will have to rework how self.my_cam_id works. To make sure
        the proper camera is set as the 'main' camera.
        At this point we also set the viewport to the current resolution."""
        for cam in self.view.getCameras():
            width = int(TDS.readSetting(name="ScreenWidth"))
            height = int(TDS.readSetting(name="ScreenHeight"))
            viewport = fife.Rect(0,0,width,height)
            cam.setViewPort(viewport)
            self.my_cam_id = cam.getId()
            self.cameras[self.my_cam_id] = cam
        self.view.resetRenderers()
        self.target_rotation = self.cameras[self.my_cam_id].getRotation()

        self.outline_render = fife.InstanceRenderer.\
                                        getInstance(self.cameras[self.my_cam_id])

        # set the render text
        rend = fife.FloatingTextRenderer.getInstance(self.cameras[self.my_cam_id])
        text = self.engine.getGuiManager().\
                        createFont('fonts/rpgfont.png', 0, \
                                   str(TDS.readSetting("FontGlyphs", \
                                                       strip=False)))
        rend.changeDefaultFont(text)
        
        # Make World aware that this is now the active map.
        self.data.view.active_map = self