Ignore:
Timestamp:
05/12/09 16:17:55 (11 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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 
Note: See TracChangeset for help on using the changeset viewer.