Changeset 128


Ignore:
Timestamp:
06/13/09 04:28:48 (10 years ago)
Author:
maximinus_parpg
Message:

Added meggies map changing code.

Location:
trunk/PARPG
Files:
1 added
7 edited

Legend:

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

    r119 r128  
    11<?xml version="1.0" encoding="ascii"?> 
    2 <map id="my-map" format="1.0"> 
     2<map id="map2" format="1.0"> 
    33    <!-- Firstly import all the gfx objects we need for this map --> 
    44        <import file="../objects/agents/player/player.xml"></import> 
    55        <import file="../objects/ground/grass/grass-a.xml"></import> 
    66        <import file="../objects/objects/crate/crate.xml"></import> 
     7 
     8        <import file="../objects/buildings/windmill/windmilla.xml"></import> 
     9        <import file="../objects/buildings/windmill/windmillb.xml"></import> 
     10        <import file="../objects/buildings/windmill/windmillc.xml"></import> 
     11        <import file="../objects/buildings/windmill/windmilld.xml"></import> 
     12        <import file="../objects/buildings/windmill/windmille.xml"></import> 
    713 
    814        <layer grid_type="square" id="GroundLayer" x_scale="1.0" pathing="cell_edges_only" y_scale="1.0" rotation="0.0" x_offset="0.0" y_offset="0.0"> 
     
    10081014                </instances> 
    10091015        </layer> 
     1016         
     1017        <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"> 
     1018                <instances>      
     1019            <i x="6" o="windmilla" z="0.0" y="-4" r="0"></i> 
     1020            <i x="6" o="windmillb" z="0.0" y="-3" r="0"></i> 
     1021            <i x="6" o="windmillc" z="0.0" y="-2" r="0"></i> 
     1022            <i x="7" o="windmilld" z="0.0" y="-2" r="0"></i> 
     1023            <i x="8" o="windmille" z="0.0" y="-2" r="0"></i> 
     1024                </instances> 
     1025        </layer> 
    10101026 
    10111027        <camera ref_cell_width="72" zoom="1.0" tilt="-60.0" id="main" ref_layer_id="ObjectLayer" ref_cell_height="38" rotation="45.0"> 
  • trunk/PARPG/maps/map2_objects.xml

    r119 r128  
    99    <!-- There can be any number of objects --> 
    1010    <!-- Object blocking is set in the objects own xml file --> 
    11     <object display="True" gfx="crate" xpos="0.0" ypos="0.0" id="crate03" 
     11    <object display="True" gfx="crate" xpos="1.0" ypos="1.0" id="crate03" 
    1212            carry="0" contain="1" text="Yet another crate!"></object> 
    1313</objects> 
  • trunk/PARPG/maps/map_objects.xml

    r111 r128  
    1919    <object display="False" gfx="NONE" owner="crate02" id="battery" 
    2020            carry="1" contain="0" text="An old battery"></object> 
     21                <!-- There can be any number of 'trasition tiles', or tiles that move the 
     22                PC around --> 
     23                <tele_tile target="map2" xpos="-14" ypos="10" txpos="-14" typos="-17"> 
     24                                                </tele_tile> 
    2125</objects> 
    2226 
  • trunk/PARPG/scripts/agents/npc.py

    r122 r128  
    1818import fife 
    1919from settings import Setting 
    20 from random import randint 
     20from random import randrange 
    2121 
    2222TDS = Setting() 
    23 _STATE_NONE, _STATE_IDLE, _STATE_WANDER = xrange(3) 
     23_STATE_NONE, _STATE_IDLE, _STATE_WANDER, _STATE_TALK = xrange(4) 
    2424 
    2525class NPC(fife.InstanceActionListener): 
     
    3939        self.state = _STATE_NONE 
    4040        self.speed = float(TDS.readSetting("PCSpeed"))-1 
    41         self.target_loc = self.getTargetLocation()  
     41        # hard code this for now 
     42        self.distRange = (2, 4) 
     43        self.targetLoc = self.getTargetLocation()  
    4244        self.text = text 
     45        # good to have the pc in case we ever need to follow it 
     46        self.pc = layer.getInstance('PC') 
    4347 
    4448    def getX(self): 
     
    5660        y = self.getY() 
    5761        if self.state == _STATE_WANDER: 
     62            """ Random Target Location """ 
     63            l = [0, 0] 
     64            for i in range(len(l)): 
     65                sign = randrange(0, 2) 
     66                dist = randrange(self.distRange[0], self.distRange[1]) 
     67                if sign == 0: 
     68                    dist *= -1 
     69                l[i] = dist 
     70            x += l[0] 
     71            y += l[1] 
    5872            """ Random Walk """ 
     73            """ 
    5974            rl = randint(-1, 1) 
    6075            ud = randint(-1, 1) 
    6176            x += rl 
    6277            y += ud 
     78            """ 
    6379        l = fife.Location(self.agent.getLocation()) 
    6480        l.setLayerCoordinates(fife.ModelCoordinate(*tuple([x, y]))) 
     
    6783    def onInstanceActionFinished(self, instance, action): 
    6884        """What the NPC does when it has finished an action. 
    69            Called somewhere else (TODO: where?)""" 
     85           Called by the engine and required for InstanceActionListeners""" 
    7086        if self.state == _STATE_WANDER: 
    71             self.target_loc = self.getTargetLocation() 
     87            self.targetLoc = self.getTargetLocation() 
    7288        self.idle() 
    7389 
     
    8298            self.agent.act('stand', self.agent.getFacingLocation()) 
    8399        elif self.state == _STATE_IDLE: 
    84             self.target_loc = self.getTargetLocation() 
     100            self.targetLoc = self.getTargetLocation() 
    85101            self.state = _STATE_WANDER 
    86102            self.agent.act('stand', self.agent.getFacingLocation()) 
    87103        elif self.state == _STATE_WANDER: 
    88             self.wander(self.target_loc) 
     104            self.wander(self.targetLoc) 
     105            self.state = _STATE_NONE 
     106        elif self.state == _STATE_TALK: 
     107            self.agent.act('stand', self.pc.getLocation()) 
    89108 
    90109    def wander(self, location): 
     
    98117           @param location: a fife.Location object, where the NPC will run to""" 
    99118        self.agent.move('run', location, self.speed+1) 
    100  
  • trunk/PARPG/scripts/engine.py

    r122 r128  
    2020from agents.npc import NPC 
    2121from objects import GameObject 
     22from tele_tiles import TeleTile 
    2223from objLoader import LocalXMLParser 
    2324 
     
    4546        self.npcs = [] 
    4647        self.objects = [] 
     48        self.tele_tiles = [] 
     49 
     50    def reset(self): 
     51        """Clears the data on a map reload so we don't have objects/npcs from 
     52           other maps hanging around. Right now I'm clearing the PC, but we'll 
     53           have to evaluate that when we get more details on how the stepping  
     54           on tiles works.""" 
     55        self.PC = None 
     56        self.npcs = [] 
     57        self.objects = [] 
     58        self.tele_tiles = [] 
    4759 
    4860    def loadObjects(self, filename): 
     
    6880        self.addNPCs(cur_handler.npcs) 
    6981        self.addObjects(cur_handler.objects) 
     82        self.addTeleTiles(cur_handler.tele_tiles) 
    7083        return True 
    7184 
     
    97110            self.npcs.append(NPC(i[4], str(i[3]), self.view.agent_layer)) 
    98111            self.npcs[-1].start() 
     112 
     113    def addTeleTiles(self, tiles): 
     114        """Add all of the teleportation tiles we found into this class""" 
     115        # we want to use the ground layer for now 
     116        layer = self.view.map.getLayer('GroundLayer') 
     117        for i in tiles: 
     118            self.tele_tiles.append(TeleTile(i[0], i[1], i[2], layer)) 
    99119 
    100120    def objectActive(self, ident): 
     
    142162        self.view.load(map_file) 
    143163        # then we update FIFE with the PC, NPC and object details 
     164        self.reset() 
    144165        self.loadObjects(map_file[:-4]+"_objects.xml") 
     166 
     167    def checkTeleTiles(self, location): 
     168        """Iterates through the possible teleportation tiles to see if the  
     169            given location is a teleportation tile 
     170        @param location: a fife.Location to check against the tiles 
     171        @return: the TeleTile if a tile is matched or False""" 
     172        for tile in self.tele_tiles: 
     173            if tile.matchLocation(location): 
     174                return tile 
     175        return False 
    145176 
    146177    def handleMouseClick(self,position): 
  • trunk/PARPG/scripts/objLoader.py

    r111 r128  
    2828        self.objects = [] 
    2929        self.npcs = [] 
     30        self.tele_tiles = [] 
    3031     
    3132    def getParser(self): 
     
    8788                self.objects.append([False, gfx, ident, text, 
    8889                                     owner, contain, carry]) 
     90        elif name == "tele_tile": 
     91            try: 
     92                target = attrs.getValue("target") 
     93                xpos = attrs.getValue("xpos") 
     94                ypos = attrs.getValue("ypos") 
     95                txpos = attrs.getValue("txpos") 
     96                typos = attrs.getValue("typos") 
     97            except(KeyError): 
     98                sys.stderr.write("Error: Data missing in \ 
     99                        tele_tile definition\n") 
     100                sys.exit(False) 
     101            self.tele_tiles.append([target, tuple([int(xpos), int(ypos)]), \ 
     102                    tuple([int(txpos), int(typos)])]) 
    89103 
  • trunk/PARPG/scripts/world.py

    r125 r128  
    5151           TODO: Comment these variables""" 
    5252        super(World, self).__init__(engine, regMouse = True, regKeys = True) 
     53        # self.engine is a fife.Engine object, not an Engine object 
    5354        self.engine = engine 
    5455        self.eventmanager = engine.getEventManager() 
     
    5758        self.quitFunction = None 
    5859        self.inventoryShown = False 
     60        # self.data is an engine.Engine object, but is set in run.py 
    5961        self.data = None 
    6062        self.mouseCallback = None 
    6163        self.obj_hash={} 
    62  
     64        # self.map is a Map object, set to none here 
     65        self.map = None 
    6366        self.hud = hud.Hud(self.engine, TDS) 
    6467        self.hud.events_to_map["inventoryButton"] = cbwa(self.displayInventory, True) 
     
    7578    def reset(self): 
    7679        """Reset the map to default settings""" 
     80        # We have to delete the map in Fife. 
     81        # TODO: I'm killing the PC now, but later we will have to save the PC 
     82        if self.map: 
     83            self.model.deleteMap(self.map) 
    7784        self.transitions = [] 
    78         self.PC = None 
    79         self.npcs = [] 
     85        """ self.PC and self.npcs are never used, and can be accessed through 
     86            the self.data object...commented out for the time being 
     87            Also, why are there duplicated lines?""" 
     88        #self.PC = None 
     89        #self.npcs = [] 
    8090        self.map,self.agent_layer = None,None 
     91        # We have to clear the cameras in the view as well, or we can't reuse 
     92        # camera names like 'main' 
     93        self.view.clearCameras() 
    8194        self.cameras = {} 
    82         self.PC = None 
    83         self.npcs = [] 
     95        #self.PC = None 
     96        #self.npcs = [] 
    8497        self.cur_cam2_x,self.initial_cam2_x,self.cam2_scrolling_right = 0,0,True 
    8598        self.target_rotation = 0 
     
    91104           is subject to change""" 
    92105        self.reset() 
     106 
    93107        self.map = loadMapFile(filename, self.engine) 
    94108        self.maplistener = Map(self.map) 
     
    208222            self.hud.addAction("Action " + str(self.action_number)) 
    209223            self.action_number += 1 
     224        if(keyval == key.C): 
     225            # C changes the map 
     226            if self.map.getId() == "my-map": 
     227                self.data.loadMap(str(TDS.readSetting("map2"))) 
     228            elif self.map.getId() == "map2": 
     229                self.data.loadMap(str(TDS.readSetting("MapFile"))) 
    210230        if(keyval == key.ESCAPE): 
    211231            # Escape brings up the main menu 
     
    222242    def mousePressed(self, evt): 
    223243        """If a mouse button is pressed down, fife cals this routine 
    224            Currently we only check for a left click, and we assume this is on 
    225            the map""" 
     244           Currently we assume this is on the map""" 
    226245        click = fife.ScreenPoint(evt.getX(), evt.getY()) 
    227246        if(evt.getButton() == fife.MouseEvent.LEFT): 
     
    255274    def placeHolderFunction(self): 
    256275        """Just a simple function to make the PC say "Place Holder Function!" 
    257            It's in here because we needed some sort of function to test the context 
     276           It's in here because we needed some sort of function to test the context  
    258277           menu with""" 
    259278        self.agent_layer.getInstance("PC").say("Place Holder Function!", 1000) 
Note: See TracChangeset for help on using the changeset viewer.