Changeset 412 for trunk/game


Ignore:
Timestamp:
11/30/09 03:22:53 (10 years ago)
Author:
orlandov
Message:

Ticket #63 - patch by or1andov

  • Fade TopLayer? instances when the PC goes underneath them.
  • Unfade when the PC moves away. This can probably be optimized.
Location:
trunk/game
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/game/local_loaders/xmlmap.py

    r336 r412  
    293293                                        str(id)) 
    294294 
     295            if id: inst.setId(id) 
    295296            rotation = instance.get('r') 
    296297            if not rotation: 
  • trunk/game/maps/map.xml

    r411 r412  
    55635563        <layer grid_type="square" id="TopLayer" 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"> 
    55645564                <instances> 
    5565                         <i o="archway_gate" r="0" x="-27.0" y="-53.0" z="0.0" /> 
     5565                        <i id="archway" o="archway_gate" r="0" x="-27.0" y="-53.0" z="0.0" /> 
    55665566                        <i o="shadow_gate" r="0" x="-32.0" y="-46.0" z="0.0" /> 
    55675567                        </instances> 
  • trunk/game/scripts/map.py

    r359 r412  
    3737        self.cameras = {} 
    3838        self.agent_layer = None 
     39        self.top_layer = None 
    3940        self.model = engine.getModel() 
    4041        self.view = engine.getView() 
     
    5657        self.map = None 
    5758        self.agent_layer = None         
     59        self.top_layer = None 
    5860        # We have to clear the cameras in the view as well, or we can't reuse 
    5961        # camera names like 'main' 
     
    7981        self.map = loadMapFile(filename, self.engine, self.data) 
    8082        self.agent_layer = self.map.getLayer('ObjectLayer') 
     83        self.top_layer = self.map.getLayer('TopLayer') 
    8184         
    8285        #find out if a PC instance was created when the map was loaded 
  • trunk/game/scripts/world.py

    r372 r412  
    7777        # Last saved mouse coords 
    7878        self.last_mousecoords = None 
     79 
     80        # faded objects in top layer 
     81        self.faded_objects = set() 
    7982 
    8083    def initHud(self): 
     
    225228        self.data.game_state.PC.run(click) 
    226229 
     230    def refreshTopLayerInstanceTransparencies(self): 
     231        """Fade or unfade TopLayer instances if the PC is under them.""" 
     232 
     233        # get the PC's screen coordinates 
     234        camera = self.active_map.cameras[self.active_map.my_cam_id] 
     235        point = self.data.game_state.PC.behaviour.agent.getLocation() 
     236        scr_coords = camera.toScreenCoordinates(point.getMapCoordinates()) 
     237 
     238        # find all instances on TopLayer that fall on those coordinates 
     239        instances = camera.getMatchingInstances(scr_coords, 
     240                        self.active_map.top_layer) 
     241        instance_ids = [ instance.getId() for instance in instances ] 
     242        faded_objects = self.faded_objects 
     243 
     244        # fade instances 
     245        for instance_id in instance_ids: 
     246            if instance_id not in faded_objects: 
     247                faded_objects.add(instance_id) 
     248                instance.get2dGfxVisual().setTransparency(128) 
     249 
     250        # unfade previously faded instances 
     251        for instance_id in faded_objects.copy(): 
     252            if instance_id not in instance_ids: 
     253                faded_objects.remove(instance_id) 
     254                self.active_map.top_layer.getInstance(instance_id).\ 
     255                        get2dGfxVisual().setTransparency(0) 
     256 
    227257    def teleport(self, position): 
    228258        """Called when a door is used that moves a player to a new 
     
    326356    def pump(self): 
    327357        """Routine called during each frame. Our main loop is in ./run.py""" 
     358        # uncomment to instrument 
     359        # t0 = time.time() 
    328360        self.highlightFrontObject() 
     361        self.refreshTopLayerInstanceTransparencies() 
     362        # print "%05f" % (time.time()-t0,) 
Note: See TracChangeset for help on using the changeset viewer.