Changeset 340


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]

Location:
trunk/game
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/maps/map2.xml

    r318 r340  
    10331033            <i x="1" o="shantyi" z="0.0" y="6" r="0"></i> 
    10341034 
    1035             <!-- There must be one and one only PC character --> 
    1036             <i x="0.0" o="player" z="0.0" y="0.0" r="0" id="PC" object_type="PlayerCharacter"></i> 
    1037  
    10381035            <!-- A sample door --> 
    10391036            <i x="-2.0" o="shanty-door" z="0.0" y="6.0" r="0" id="shanty-door01" object_type="ShantyDoor" is_open="False" 
     
    10431040        </instances> 
    10441041    </layer> 
    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"> 
     1042        <camera ref_cell_width="72" zoom="1.0" tilt="-60.0" id="map2" ref_layer_id="ObjectLayer" ref_cell_height="38" rotation="45.0"> 
    10461043        </camera> 
    10471044</map> 
  • trunk/game/scripts/engine.py

    r323 r340  
    4646        self.target_map_name = None 
    4747        self.target_map_file = None 
    48          
    49     def reset(self): 
    50         """Clears the data on a map reload so we don't have objects/npcs from 
    51            other maps hanging around. 
    52            @return: None""" 
    5348 
    5449    def save(self, path, filename): 
     
    260255        self.game_state.current_map_name = map_name 
    261256        self.view.loadMap(map_name, str(map_file)) 
    262         self.view.setActiveMap(map_name) 
    263         self.reset() 
    264          
     257 
    265258        # If the map has been loaded, we might need to add some 
    266259        # agents to the PC and NPS 
     
    275268 
    276269        # create the PC agent 
    277         self.view.active_map.addPC(self.game_state.PC.behaviour.agent) 
     270        self.view.active_map.addPC() 
    278271        self.game_state.PC.start() 
    279272 
  • 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 
  • trunk/game/scripts/objects/actors.py

    r324 r340  
    9090        """Sets the agent onto the new layer. 
    9191        """ 
    92         self.agent = layer.getInstance(self.parent.name) 
     92        self.agent.removeActionListener(self) 
     93        self.agent = layer.getInstance(self.parent.ID) 
    9394        self.agent.addActionListener(self) 
    9495        self.state = _AGENT_STATE_NONE 
  • trunk/game/scripts/world.py

    r338 r340  
    9999    def loadMap(self, map_name, filename): 
    100100        """Loads a map and stores it under the given name in the maps list. 
    101            @type map_name: text 
     101           @type map_name: String 
    102102           @param map_name: The name of the map to load  
    103            @type filename: text 
     103           @type filename: String 
    104104           @param filename: File which contains the map to be loaded 
    105            @return: None 
    106         """ 
     105           @return: None""" 
    107106        if not map_name in self.maps: 
    108             """Need to set active map before we load it because the map  
    109             loader uses call backs that expect to find an active map.  
    110             This needs to be reworked. 
    111             """ 
    112107            map = Map(self.engine, self.data) 
    113108            self.maps[map_name] = map         
     109            map.load(filename) 
     110        else: 
    114111            self.setActiveMap(map_name) 
    115             map.load(filename) 
    116112     
    117113    def setActiveMap(self, map_name): 
    118114        """Sets the active map that is to be rendered. 
    119            @type map_name: text 
     115           @type map_name: String 
    120116           @param map_name: The name of the map to load  
    121            @return: None 
    122         """ 
     117           @return: None""" 
     118        # Turn off the camera on the old map before we turn on the camera 
     119        # on the new map. 
     120        self.active_map.cameras[self.active_map.my_cam_id].setEnabled(False) 
     121        # Make the new map active. 
    123122        self.active_map = self.maps[map_name] 
    124123        self.active_map.makeActive() 
     
    128127           @type obj: fife.instance 
    129128           @param obj: object to draw over 
    130            @type text: text 
     129           @type text: String 
    131130           @param text: text to display over object 
    132131           @return: None""" 
     
    193192        elif(evt.getButton() == fife.MouseEvent.RIGHT): 
    194193            # is there an object here? 
    195             instances = self.active_map.cameras['main'].\ 
     194            instances = self.active_map.cameras[self.active_map.my_cam_id].\ 
    196195                            getMatchingInstances(scr_point, \ 
    197196                                                 self.active_map.agent_layer) 
     
    224223           @return: fife.Location 
    225224        """ 
     225        print position 
    226226        coord = fife.DoublePoint3D(float(position[0]), float(position[1]), 0) 
    227227        location = fife.Location(self.active_map.agent_layer) 
     
    235235           @return: None""" 
    236236        click = fife.ScreenPoint(evt.getX(), evt.getY()) 
    237         i=self.active_map.cameras['main'].getMatchingInstances(click, \ 
     237        i=self.active_map.cameras[self.active_map.my_cam_id].getMatchingInstances(click, \ 
    238238                                                self.active_map.agent_layer) 
    239239        # no object returns an empty tuple 
     
    274274           @rtype: fife.Location 
    275275           @return: The map coordinates""" 
    276         coord = self.active_map.cameras["main"].toMapCoordinates(click, False) 
     276        coord = self.active_map.cameras[self.active_map.my_cam_id].toMapCoordinates(click, False) 
    277277        coord.z = 0 
    278278        location = fife.Location(self.active_map.agent_layer) 
Note: See TracChangeset for help on using the changeset viewer.