Changeset 58 for trunk/PARPG/scripts


Ignore:
Timestamp:
05/11/09 13:42:45 (11 years ago)
Author:
maximinus_parpg
Message:

Made it so we only have one keycheck function (sanity at last!)
A few more Rio oddities removed.
Some minor script clean-up.

Location:
trunk/PARPG/scripts
Files:
2 edited

Legend:

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

    r55 r58  
    123123            self.view.addObject(float(i[0]),float(i[1]),i[2]) 
    124124 
     125    def addNPCs(self): 
     126        """Add all of the NPCs we found into the fife map""" 
     127        for i in self.npcs: 
     128            self.view.addObject(float(i[0]),float(i[1]),i[2]) 
     129 
    125130    def loadMap(self,map_file): 
    126131        """Load a new map 
     
    131136        self.view.load(map_file) 
    132137        # finally, we update FIFE with the PC, NPC and object details 
    133         self.view.addPC(self.pc[0],self.pc[1]) 
     138        self.view.addPC(float(self.pc[0]),float(self.pc[1])) 
     139        self.addNPCs() 
    134140        self.addObjects() 
    135141 
  • trunk/PARPG/scripts/world.py

    r56 r58  
    6969        self.model=engine.getModel() 
    7070        self.view=self.engine.getView() 
    71         self.rend_backend=self.engine.getRenderBackend() 
    72         self.filename='' 
     71        self.quitFunction=None 
     72 
     73    def reset(self): 
     74        """Rest the map to default settings""" 
    7375        self.transitions=[] 
    7476        self.PC=None 
    7577        self.npcs=[] 
    76  
    77     def reset(self): 
    78         """Rest the map to default settings""" 
    7978        self.map,self.agent_layer=None,None 
    8079        self.cameras={} 
     
    8988           Everything else should be loaded from the engine, because it 
    9089           is subject to change""" 
    91         self.filename=filename 
    9290        self.reset() 
    93         self.map=loadMapFile(filename, self.engine) 
     91        self.map=loadMapFile(filename,self.engine) 
    9492        self.maplistener=MapListener(self.map) 
    9593 
     
    114112           The id we use is always is always PC""" 
    115113        # first we need to add the PC as an object on the map 
    116         self.PC = Hero(self.model,'PC',self.agent_layer) 
     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) 
    117119        # ensure the PC starts on a default action 
    118120        self.PC.start() 
     
    120122        self.cameras['main'].attach(self.PC.agent) 
    121123     
    122     def addNPC(self): 
    123         """Add a non=player character to the map""" 
    124         pass 
    125      
    126124    def addObject(self,xpos,ypos,name): 
    127         """Add an object to the map""" 
     125        """Add an object or an NPC to the map 
     126           It makes no difference to fife which is which""" 
    128127        obj=self.agent_layer.createInstance( 
    129128                self.model.getObject(str(name),"PARPG"), 
     
    138137        keyval = key.getValue() 
    139138 
    140         if keyval == key.T: 
     139        if(keyval==key.Q): 
     140            # we need to quit the game 
     141            self.quitGame() 
     142        if(keyval==key.T): 
    141143            self.toggle_renderer('GridRenderer') 
    142         if keyval == key.F5: 
     144        if(keyval==key.F1): 
     145            # display the help screen and pause the game 
     146            self.displayHelp() 
     147        if(keyval==key.F5): 
    143148            # logic would say we use similar code to above and toggle 
    144149            # logic here does not work, my friend :-( 
    145150            self.cord_render.setEnabled(not self.cord_render.isEnabled()) 
    146         if keyval == key.F7: 
     151        if(keyval==key.F7): 
    147152            # F7 saves a screenshot to fife/clients/parpg/screenshots 
    148             self.rend_backend.captureScreen("screenshots/screen-%s.png" %  
    149                                              date.today().strftime('%Y-%m-%d')) 
     153            # TODO: add a time stamp as well as a date stamp 
     154            t="screenshots/screen-%s.png" % date.today().strftime('%Y-%m-%d') 
     155            self.engine.getRenderBackend().captureScreen(t) 
    150156 
    151157    def mousePressed(self, evt): 
     
    167173        renderer.setEnabled(not renderer.isEnabled()) 
    168174 
     175    def displayHelp(self): 
     176        """Displays the pop-up info and help screen""" 
     177        print "Help not yet coded" 
     178 
     179    def quitGame(self): 
     180        """Called when user requests to quit game 
     181           Just calls the ApplicationListener to do the quit""" 
     182        if(self.quitFunction!=None): 
     183            self.quitFunction() 
     184 
    169185    def pump(self): 
    170186        """Routine called during each frame. Our main loop is in ./run.py 
Note: See TracChangeset for help on using the changeset viewer.