Changeset 58


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
Files:
8 edited

Legend:

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

    r55 r58  
    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                     <i x="0.0" o="boy" y="0.0" r="0" id="PC" z="0.0"></i> 
     1056                     
    10571057                <i x="8.0" o="block" z="0.0" y="-12.0" r="0"></i> 
    10581058                        <i x="9.0" o="block" z="0.0" y="-12.0" r="0"></i> 
  • trunk/PARPG/maps/map_objects.xml

    r55 r58  
    77    <PC xpos="0.0" ypos="0.0"></PC> 
    88    <!-- There can be any number of NPC characters --> 
    9     <NPC gfx="npc=woman" xpos="3.0" ypos="3.0"></NPC> 
     9    <NPC gfx="npc-woman" xpos="-4.0" ypos="-7.0"></NPC> 
    1010    <!-- There can be any number of objects --> 
    1111    <!-- Object blocking is set in the objects own xml file --> 
  • trunk/PARPG/objects/agents/player/player.xml

    r26 r58  
    11<?fife type="object"?> 
    2 <object id="boy" namespace="PARPG" blocking="1" static="0"> 
     2<object id="PC" namespace="PARPG" blocking="1" static="0"> 
    33        <action id="run"> 
    44                <animation source="stand/animation.xml" direction="0" /> 
  • trunk/PARPG/objects/agents/player/stand/animation.xml

    r43 r58  
    1 <animation delay="2000" namespace="PAPRG" id="boy:stand:000" x_offset="0" y_offset="-40"> 
     1<animation delay="2000" namespace="PAPRG" id="PC:stand:000" x_offset="0" y_offset="-40"> 
    22        <frame source="man.png" /> 
    33</animation> 
  • trunk/PARPG/run.py

    r54 r58  
    2121 
    2222import fife_compat 
    23 import fife, fifelog 
     23import fife,fifelog 
    2424from scripts import world 
    2525from scripts import engine 
     
    3030TDS = Setting() 
    3131 
     32# This folder holds the main meta-data for PARPG. This file should be 
     33# minimal, since folding code into the controller with MVC is usually bad 
     34# All game and logic and data is held held and referenced in /scripts/engine.py 
     35# All fife stuff goes in /scripts/world.py 
     36 
    3237class ApplicationListener(eventlistenerbase.EventListenerBase): 
    33     def __init__(self, engine, world): 
     38    def __init__(self,engine,world): 
    3439        super(ApplicationListener, self).__init__(engine, 
    35                                                   regKeys=True,regCmd=True, regMouse=False,  
    36                                                   regConsole=True, regWidget=True) 
    37         self.engine = engine 
    38         self.world = world 
     40                                                  regKeys=True,regCmd=True, 
     41                                                  regMouse=False,  
     42                                                  regConsole=True, 
     43                                                  regWidget=True) 
     44        self.engine=engine 
     45        self.world=world 
    3946        engine.getEventManager().setNonConsumableKeys([fife.Key.ESCAPE,]) 
    40         self.quit = False 
    41         self.aboutWindow = None 
     47        self.quit=False 
     48        self.aboutWindow=None 
    4249 
    43     def keyPressed(self, evt): 
    44         """Function to deal with keypress events 
    45            @param evt: The event that was captured""" 
    46         keyval = evt.getKey().getValue() 
    47         if keyval == fife.Key.ESCAPE: 
    48             self.quit = True 
    49         evt.consume() 
    50            
    51     def onCommand(self, command): 
     50    def quitGame(self): 
     51        """Forces a quit game on next cycle""" 
     52        self.quit=True 
     53 
     54    def onCommand(self,command): 
    5255        """Enables the game to be closed via the 'X' button on the window frame""" 
    53         self.quit = (command.getCommandType() == fife.CMD_QUIT_GAME) 
    54         if self.quit: 
     56        if(command.getCommandType()==fife.CMD_QUIT_GAME): 
     57            self.quit=True 
    5558            command.consume() 
    5659 
    5760class PARPG(ApplicationBase): 
    5861    """Main Application class 
    59        We use an MV data model. 
    60        self.world is our view 
    61        self.engine is our model""" 
     62       We use an MVC data model. 
     63       self.world is our view,self.engine is our model 
     64       This file is the minimal controller""" 
    6265    def __init__(self): 
    6366        super(PARPG,self).__init__() 
    64         self.world = world.World(self.engine) 
    65         self.model = engine.Engine(self.world) 
    66         self.listener = ApplicationListener(self.engine, self.world) 
     67        self.world=world.World(self.engine) 
     68        self.model=engine.Engine(self.world) 
     69        self.listener=ApplicationListener(self.engine,self.world) 
     70        self.world.quitFunction=self.listener.quitGame 
    6771        self.model.loadMap(str(TDS.readSetting("MapFile"))) 
    6872 
     
    7175           Called in the ApplicationBase constructor.""" 
    7276        import settings 
    73         self.settings = settings 
    74  
    75         eSet = self.engine.getSettings() 
     77        self.settings=settings 
     78        eSet=self.engine.getSettings() 
    7679        eSet.setDefaultFontGlyphs(str(TDS.readSetting("FontGlyphs",strip=False))) 
    7780        eSet.setDefaultFontPath(str(TDS.readSetting("Font"))) 
     
    9598    def initLogging(self): 
    9699        """Initialize the LogManager""" 
    97         LogModules = TDS.readSetting("LogModules",type='list') 
    98         self.log = fifelog.LogManager(self.engine, 
     100        LogModules=TDS.readSetting("LogModules",type='list') 
     101        self.log=fifelog.LogManager(self.engine, 
    99102                                      int(TDS.readSetting("LogToPrompt")), 
    100103                                      int(TDS.readSetting("LogToFile"))) 
    101         if LogModules: 
     104        if(LogModules): 
    102105            self.log.setVisibleModules(*LogModules) 
    103106 
     
    116119def main(): 
    117120    """Application code starts from here""" 
    118     app = PARPG() 
     121    app=PARPG() 
    119122    app.run() 
    120123 
  • 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 
  • trunk/PARPG/settings.xml

    r54 r58  
    11<Settings> 
     2    <!-- Runtime settings for PARPG --> 
    23        <FullScreen> 0 </FullScreen> 
    34        <PlaySounds> 1 </PlaySounds> 
Note: See TracChangeset for help on using the changeset viewer.