Changeset 62


Ignore:
Timestamp:
05/12/09 16:17:55 (10 years ago)
Author:
maximinus_parpg
Message:

Large restructure of PC and NPC classes.
Data seperation is a lot cleaner.
Again some old Rio code removed.

Location:
trunk/PARPG
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/PARPG/maps/map.xml

    r58 r62  
    10541054        <layer x_offset="0.0" pathing="cell_edges_and_diagonals" y_offset="0.0" grid_type="square" id="ObjectLayer" x_scale="1" y_scale="1" rotation="0.0"> 
    10551055                <instances> 
    1056                      
    10571056                <i x="8.0" o="block" z="0.0" y="-12.0" r="0"></i> 
    10581057                        <i x="9.0" o="block" z="0.0" y="-12.0" r="0"></i> 
  • trunk/PARPG/run.py

    r58 r62  
    6969        self.listener=ApplicationListener(self.engine,self.world) 
    7070        self.world.quitFunction=self.listener.quitGame 
    71         self.model.loadMap(str(TDS.readSetting("MapFile"))) 
     71        self.model.loadMap(str(TDS.readSetting("MapFile")))    
    7272 
    7373    def loadSettings(self): 
  • trunk/PARPG/scripts/agents/agent.py

    r54 r62  
    2020class Agent(fife.InstanceActionListener): 
    2121    """Base class for all NPC's and the main character""" 
    22     def __init__(self, model, agentName, layer, uniqInMap=True): 
     22    # self.model,'PC',self.agent_layer 
     23    def __init__(self,agentName,layer): 
     24        # add this class for callbacks from fife itself 
    2325        fife.InstanceActionListener.__init__(self) 
    24         self.model = model 
    25         self.agentName = agentName 
    26         self.layer = layer 
    27         if(uniqInMap==True): 
    28             self.agent = layer.getInstance(agentName) 
    29             self.agent.addActionListener(self) 
     26        self.agentName=agentName 
     27        self.agent=layer.getInstance(agentName) 
     28        self.agent.addActionListener(self) 
    3029 
    3130    def onInstanceActionFinished(self, instance, action): 
    3231        """Called when an action is finished - normally overridden""" 
    33         print "No OnActionFinished defined for Agent" 
     32        raise CodeError("No OnActionFinished defined for Agent") 
    3433 
    3534    def start(self): 
    3635        """Called when agent first used - normally overridden""" 
    37         print "No start defined for Agent" 
     36        raise CodeError("No start defined for Agent") 
    3837 
  • trunk/PARPG/scripts/agents/hero.py

    r26 r62  
    77class Hero(Agent): 
    88    """This is the class we use for the PC character""" 
    9     def __init__(self, model, agentName, layer, uniqInMap=True): 
    10         super(Hero, self).__init__(model, agentName, layer, uniqInMap) 
    11         self.state = _STATE_NONE 
    12         self.idlecounter = 1 
     9    def __init__(self,agentName,layer): 
     10        super(Hero, self).__init__(agentName,layer) 
     11        self.state=_STATE_NONE 
     12        self.idlecounter=1 
    1313        self.speed=float(TDS.readSetting("PCSpeed")) 
    1414 
  • trunk/PARPG/scripts/engine.py

    r58 r62  
    112112            sys.stderr.write("Error: No PC defined\n") 
    113113            sys.exit(False) 
    114         # transfer the data 
    115         self.pc=cur_handler.pc 
    116         self.npcs=cur_handler.npcs 
    117         self.objects=cur_handler.objects 
     114        # now add to the map and the engine 
     115        self.addPC(cur_handler.pc) 
     116        self.addNPCs(cur_handler.npcs) 
     117        self.addObjects(cur_handler.objects) 
    118118        return True 
    119119 
    120     def addObjects(self): 
    121         """Add all of the objects we found into the fife map""" 
    122         for i in self.objects: 
     120    def addPC(self,pc): 
     121        """Add the PC to the world""" 
     122        self.view.addObject(float(pc[0]),float(pc[1]),"PC") 
     123        self.PC=Hero("PC",self.view.agent_layer) 
     124        # ensure the PC starts on a default action 
     125        self.PC.start() 
     126        self.view.addPC(self.PC.agent) 
     127 
     128    def addObjects(self,objects): 
     129        """Add all of the objects we found into the fife map 
     130           and into our class 
     131           An NPC is just an object to FIFE""" 
     132        for i in objects: 
    123133            self.view.addObject(float(i[0]),float(i[1]),i[2]) 
    124134 
    125     def addNPCs(self): 
    126         """Add all of the NPCs we found into the fife map""" 
    127         for i in self.npcs: 
     135    def addNPCs(self,npcs): 
     136        """Add all of the NPCs we found into the fife map 
     137           and into this class""" 
     138        for i in npcs: 
    128139            self.view.addObject(float(i[0]),float(i[1]),i[2]) 
    129140 
     
    131142        """Load a new map 
    132143           TODO: needs some error checking""" 
    133         # first we go and grab the character details 
     144        # first we let FIFE load the rest of the map 
     145        self.view.load(map_file) 
     146        # then we update FIFE with the PC, NPC and object details 
    134147        self.loadObjects(map_file[:-4]+"_objects.xml") 
    135         # then we let FIFE load the rest of the map 
    136         self.view.load(map_file) 
    137         # finally, we update FIFE with the PC, NPC and object details 
    138         self.view.addPC(float(self.pc[0]),float(self.pc[1])) 
    139         self.addNPCs() 
    140         self.addObjects() 
     148        # add a callbacks routine to handle mouse clicks 
     149        # TODO: not totally happy about this code 
     150        self.view.mouseCallback=self.handleMouseClick 
    141151 
     152    def handleMouseClick(self,position): 
     153        self.PC.run(position) 
     154 
  • trunk/PARPG/scripts/world.py

    r58 r62  
    5353        self.listener=MapListener 
    5454        self.map=fife_map 
    55      
    56     def addPC(self,pc): 
    57         pass 
    58      
    59     def addNPC(self,pc): 
    60         pass 
    6155 
    6256class World(EventListenerBase): 
     
    7064        self.view=self.engine.getView() 
    7165        self.quitFunction=None 
     66        self.mouseCallback=None 
    7267 
    7368    def reset(self): 
     
    108103        self.cord_render=self.cameras['main'].getRenderer('CoordinateRenderer') 
    109104 
    110     def addPC(self,xpos,ypos): 
    111         """Add the player character to the map 
    112            The id we use is always is always PC""" 
    113         # first we need to add the PC as an object on the map 
    114         self.addObject(xpos,ypos,"PC") 
    115         # add it as an object we can deal with 
    116         # TODO: this is not that good. We should reference the PC gfx 
    117         # via fife and export this object to engine.py 
    118         self.PC=Hero(self.model,'PC',self.agent_layer) 
    119         # ensure the PC starts on a default action 
    120         self.PC.start() 
     105    def addPC(self,agent): 
     106        """Add the player character to the map""" 
     107        # actually this is real easy, we just have to 
    121108        # attach the main camera to the PC 
    122         self.cameras['main'].attach(self.PC.agent) 
     109        self.cameras['main'].attach(agent) 
    123110     
    124111    def addObject(self,xpos,ypos,name): 
     
    166153            l=fife.Location(self.agent_layer) 
    167154            l.setMapCoordinates(target_mapcoord) 
    168             self.PC.run(l) 
     155            self.mouseCallback(l) 
    169156             
    170157    def toggle_renderer (self,r_name): 
Note: See TracChangeset for help on using the changeset viewer.