Ignore:
Timestamp:
05/11/09 07:54:38 (11 years ago)
Author:
maximinus_parpg
Message:

Objects now loaded from seperate XML file.
Cleaned up some small areas in various .py files
Added crate details.
Added some simple documentation in world.py
Removed some remaining RIO code that was not needed.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PARPG/scripts/world.py

    r54 r55  
    2424 
    2525TDS = Setting() 
     26 
     27# this file should be the meta-file for all FIFE-related code 
     28# engine.py handles is our data model, whilst this is our view 
     29# in order to not replicate data, some of our data model will naturally 
     30# reside on this side of the fence (PC xpos and ypos, for example). 
     31# we should aim to never replicate any data as this leads to maintainance 
     32# issues (and just looks plain bad). 
     33# however, any logic needed to resolve this should sit in engine.py 
    2634 
    2735class MapListener(fife.MapChangeListener): 
     
    5664    def __init__(self, engine): 
    5765        super(World, self).__init__(engine, regMouse=True, regKeys=True) 
    58         self.engine = engine 
    59         self.eventmanager = engine.getEventManager() 
    60         self.model = engine.getModel() 
    61         self.view = self.engine.getView() 
    62         self.filename = '' 
    63         self.instance_to_agent = {} 
    64         self.transitions = [] 
     66        self.engine=engine 
     67        self.eventmanager=engine.getEventManager() 
     68        self.model=engine.getModel() 
     69        self.view=self.engine.getView() 
     70        self.filename='' 
     71        self.transitions=[] 
    6572        self.PC=None 
    6673        self.npcs=[] 
     
    6875    def reset(self): 
    6976        """Rest the map to default settings""" 
    70         self.map, self.agentlayer = None, None 
    71         self.cameras = {} 
    72         self.PC = None 
     77        self.map,self.agent_layer=None,None 
     78        self.cameras={} 
     79        self.PC=None 
     80        self.npcs=[] 
    7381        self.cur_cam2_x,self.initial_cam2_x,self.cam2_scrolling_right=0,0,True 
    74         self.target_rotation = 0 
    75         self.instance_to_agent = {} 
     82        self.target_rotation=0 
    7683 
    77     def load(self, filename): 
     84    def load(self,filename): 
    7885        """Load a map given the filename 
    7986           TODO: a map should only contain static items and floor tiles 
    8087           Everything else should be loaded from the engine, because it 
    8188           is subject to change""" 
    82         self.filename = filename 
     89        self.filename=filename 
    8390        self.reset() 
    84         self.map = loadMapFile(filename, self.engine) 
    85         self.maplistener = MapListener(self.map) 
     91        self.map=loadMapFile(filename, self.engine) 
     92        self.maplistener=MapListener(self.map) 
    8693 
    8794        # there must be a PC object on the objects layer! 
    88         self.agentlayer = self.map.getLayer('ObjectLayer') 
     95        self.agent_layer=self.map.getLayer('ObjectLayer') 
    8996        # it's possible there's no transition layer 
    9097        size=len('TransitionLayer') 
     
    105112           The id we use is always is always PC""" 
    106113        # first we need to add the PC as an object on the map 
    107         self.PC = Hero(self.model,'PC',self.agentlayer) 
    108         self.instance_to_agent[self.PC.agent.getFifeId()] = self.PC 
     114        self.PC = Hero(self.model,'PC',self.agent_layer) 
    109115        # ensure the PC starts on a default action 
    110116        self.PC.start() 
     
    116122        pass 
    117123     
    118     def addObject(self): 
     124    def addObject(self,xpos,ypos,name): 
    119125        """Add an object to the map""" 
    120         pass 
     126        obj=self.agent_layer.createInstance( 
     127                self.model.getObject(str(name),"PARPG"), 
     128                fife.ExactModelCoordinate(xpos,ypos,0.0),str(name)) 
     129        obj.setRotation(0) 
     130        fife.InstanceVisual.create(obj) 
    121131 
    122132    # all key / mouse event handling routines go here 
     
    141151            target_mapcoord=self.cameras['main'].toMapCoordinates(clickpoint, False) 
    142152            target_mapcoord.z = 0 
    143             l = fife.Location(self.agentlayer) 
     153            l=fife.Location(self.agent_layer) 
    144154            l.setMapCoordinates(target_mapcoord) 
    145155            self.PC.run(l) 
Note: See TracChangeset for help on using the changeset viewer.