Changeset 55 for trunk/PARPG/scripts


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.

Location:
trunk/PARPG/scripts
Files:
2 edited

Legend:

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

    r54 r55  
    1717 
    1818# there should be NO references to FIFE here! 
    19 import fife 
    2019from xml.sax import make_parser 
    2120from xml.sax.handler import ContentHandler 
     
    2827# save us writing a bunch of new code. 
    2928# However, the objects and characters on a map are liable to change 
    30 # whilst the game is being changed, so when we change the map, we 
    31 # need to grab the objects and npc data EITHER from the engine state, 
    32 # or from another file if in their initial state 
     29# whilst the game is being run, so when we change the map, we need to 
     30# to grab the objects and npc data EITHER from the engine state, or grab 
     31# from another file if in their initial state 
    3332# This other file has the name AAA_objects.xml where AAA.xml is the name 
    3433# of the original mapfile. 
     
    4443     
    4544    def startElement(self,name,attrs): 
    46         """Called every time we meet a new element""" 
     45        """Called every time we meet a new element in the XML file""" 
    4746        # we are only looking for the 'layer' elements, the rest we ignore 
    4847        if(name=="PC"): 
     
    119118        return True 
    120119 
     120    def addObjects(self): 
     121        """Add all of the objects we found into the fife map""" 
     122        for i in self.objects: 
     123            self.view.addObject(float(i[0]),float(i[1]),i[2]) 
     124 
    121125    def loadMap(self,map_file): 
    122126        """Load a new map 
     
    128132        # finally, we update FIFE with the PC, NPC and object details 
    129133        self.view.addPC(self.pc[0],self.pc[1]) 
     134        self.addObjects() 
    130135 
  • 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.