Ignore:
Timestamp:
10/23/09 18:13:26 (10 years ago)
Author:
eliedebrauwer
Message:

Ticket #66: Patch by Saritor, This patch implements Kaydeth's camera fix as well as a fix for letting us be able to remove the PC entry on individual map files. However the very first map a player starts the game on will need such an entry. fixes[s:trac, t:66]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/scripts/map.py

    r323 r340  
    3232        self.engine = engine 
    3333        self.data = data 
    34          
     34 
    3535        # init map attributes 
     36        self.my_cam_id = None 
    3637        self.cameras = {} 
    3738        self.agent_layer = None 
     
    4950           @return: None""" 
    5051        # We have to delete the map in Fife. 
    51         # TODO: We're killing the PC now, but later we will have to save the PC 
    5252        if self.map: 
    5353            self.model.deleteObjects() 
     
    5555        self.transitions = [] 
    5656        self.map = None 
    57         self.agent_layer = None 
     57        self.agent_layer = None         
    5858        # We have to clear the cameras in the view as well, or we can't reuse 
    5959        # camera names like 'main' 
    60         self.view.clearCameras() 
    61         self.cameras = {} 
    62         self.cur_cam2_x = 0 
     60        #self.view.clearCameras() 
    6361        self.initial_cam2_x = 0 
    6462        self.cam2_scrolling_right = True 
     63        #self.cameras = {} 
     64        self.cur_cam2_x = 0 
    6565        self.target_rotation = 0 
    6666        self.outline_renderer = None 
     
    6969        """Makes this map the active one. 
    7070        """ 
    71         pass 
     71        self.cameras[self.my_cam_id].setEnabled(True) 
     72 
    7273         
    7374    def load(self, filename): 
    7475        """Load a map given the filename. 
    75            @type filename: string 
     76           @type filename: String 
    7677           @param filename: Name of map to load 
    7778           @return: None""" 
    7879        self.reset() 
    7980        self.map = loadMapFile(filename, self.engine, self.data) 
    80           
    81         # there must be a PC object on the objects layer! 
    8281        self.agent_layer = self.map.getLayer('ObjectLayer') 
    83          
     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: 
     85            x = float(self.data.target_position[0]) 
     86            y = float(self.data.target_position[1]) 
     87            z = 0 
     88            pc_obj = self.model.getObject("player", "PARPG") 
     89            inst = self.agent_layer.createInstance(pc_obj,\ 
     90                                            fife.ExactModelCoordinate(x,y,z),\ 
     91                                            "PC") 
     92            inst.setRotation(self.data.game_state.PC.behaviour.agent.getRotation()) 
     93            fife.InstanceVisual.create(inst) 
     94 
    8495        # it's possible there's no transition layer 
    8596        size = len('TransitionLayer') 
     
    8899            if(layer.getId()[:size] == 'TransitionLayer'): 
    89100                self.transitions.append(self.map.getLayer(layer.getId())) 
    90                  
    91         # init the camera 
     101 
     102        """ Initialize the camera. 
     103        Note that if we have more than one camera in a map file 
     104        we will have to rework how self.my_cam_id works. To make sure 
     105        the proper camera is set as the 'main' camera.""" 
    92106        for cam in self.view.getCameras(): 
    93             self.cameras[cam.getId()] = cam 
     107            self.my_cam_id = cam.getId() 
     108            self.cameras[self.my_cam_id] = cam 
    94109        self.view.resetRenderers() 
    95         self.target_rotation = self.cameras['main'].getRotation() 
    96          
     110        self.target_rotation = self.cameras[self.my_cam_id].getRotation() 
     111 
    97112        self.outline_render = fife.InstanceRenderer.\ 
    98                                         getInstance(self.cameras['main']) 
    99          
     113                                        getInstance(self.cameras[self.my_cam_id]) 
     114 
    100115        # set the render text 
    101         rend = fife.FloatingTextRenderer.getInstance(self.cameras['main']) 
     116        rend = fife.FloatingTextRenderer.getInstance(self.cameras[self.my_cam_id]) 
    102117        text = self.engine.getGuiManager().\ 
    103118                        createFont('fonts/rpgfont.png', 0, \ 
     
    105120                                                       strip=False))) 
    106121        rend.changeDefaultFont(text) 
     122 
     123        # Make World aware that this is now the active map. 
     124        self.data.view.active_map = self 
    107125                 
    108     def addPC(self, agent): 
     126    def addPC(self): 
    109127        """Add the player character to the map 
    110            @type agent: Fife.instance of PC 
    111128           @return: None""" 
     129 
     130        # Update gamestate.PC 
     131        self.data.game_state.PC.behaviour.onNewMap(self.agent_layer) 
     132 
    112133        # actually this is real easy, we just have to 
    113134        # attach the main camera to the PC, if a camera 
    114135        # was already used, we simply recycle it.  
    115         if self.cameras['main'].getAttached() == None: 
    116             self.cameras['main'].attach(agent) 
     136        if self.cameras[self.my_cam_id].getAttached() == None: 
     137            self.cameras[self.my_cam_id].attach(self.data.game_state.PC.behaviour.agent) 
    117138 
    118139         
     
    120141        """Enable or disable a renderer. 
    121142           @return: None""" 
    122         renderer = self.cameras['main'].getRenderer(str(r_name)) 
     143        renderer = self.cameras[self.my_cam_id].getRenderer(str(r_name)) 
    123144        renderer.setEnabled(not renderer.isEnabled()) 
    124145 
Note: See TracChangeset for help on using the changeset viewer.