Changeset 68
- Timestamp:
- 05/13/09 16:21:58 (11 years ago)
- Location:
- trunk/PARPG
- Files:
-
- 1 added
- 1 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/PARPG/maps/map_objects.xml
r58 r68 7 7 <PC xpos="0.0" ypos="0.0"></PC> 8 8 <!-- There can be any number of NPC characters --> 9 <NPC gfx="npc-woman" xpos="-4.0" ypos="-7.0"></NPC> 9 <NPC gfx="npc-woman" xpos="-4.0" ypos="-7.0" id="women01" 10 text="A friendly woman"></NPC> 10 11 <!-- There can be any number of objects --> 11 12 <!-- Object blocking is set in the objects own xml file --> 12 <object gfx="crate" xpos="-3.0" ypos="-4.0"></object> 13 <object gfx="crate" xpos="-4.0" ypos="-6.0"></object> 13 <object gfx="crate" xpos="-3.0" ypos="-4.0" id="crate01" 14 text="Just a crate"></object> 15 <object gfx="crate" xpos="-4.0" ypos="-6.0" id="crate02" 16 text="A dirty old crate"></object> 14 17 </objects> 15 18 -
trunk/PARPG/run.py
r66 r68 67 67 self.world = world.World(self.engine) 68 68 self.model = engine.Engine(self.world) 69 self.world.data = self.model 69 70 self.listener = ApplicationListener(self.engine,self.world) 70 71 self.world.quitFunction = self.listener.quitGame -
trunk/PARPG/scripts/agents/hero.py
r67 r68 1 from agent import Agent 1 #!/usr/bin/python 2 3 # This program is free software: you can redistribute it and/or modify 4 # it under the terms of the GNU General Public License as published by 5 # the Free Software Foundation, either version 3 of the License, or 6 # (at your option) any later version. 7 8 # This program is distributed in the hope that it will be useful, 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # GNU General Public License for more details. 12 13 # You should have received a copy of the GNU General Public License 14 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 16 import fife 2 17 from settings import Setting 3 18 … … 5 20 _STATE_NONE, _STATE_IDLE, _STATE_RUN = xrange(3) 6 21 7 class Hero( Agent):22 class Hero(fife.InstanceActionListener): 8 23 """This is the class we use for the PC character""" 9 24 def __init__(self, agentName, layer): 10 super(Hero, self).__init__(agentName, layer) 25 # add this class for callbacks from fife itself 26 fife.InstanceActionListener.__init__(self) 27 self.agentName = agentName 28 self.agent = layer.getInstance(agentName) 29 self.agent.addActionListener(self) 11 30 self.state = _STATE_NONE 12 31 self.idlecounter = 1 -
trunk/PARPG/scripts/agents/npc.py
r54 r68 17 17 18 18 from agent import Agent 19 from settings import Setting20 19 21 TDS = Setting() 22 _STATE_NONE, _STATE_IDLE, _STATE_RUN = xrange(3) 20 class NPC: 21 """This is the class we use for all NPCs""" 22 def __init__(self, xpos, ypos, ident, text): 23 self.xpos = xpos 24 self.ypos = ypos 25 self.id = ident 26 self.text = text 23 27 24 class NPC(Agent):25 """This is the class we use for all NPCs"""26 def __init__(self, model, agentName, layer, uniqInMap=True):27 super(NPC, self).__init__(model, agentName, layer, uniqInMap)28 self.state = _STATE_NONE29 self.idlecounter = 130 #self.speed=float(TDS.readSetting("PCSpeed"))31 32 def onInstanceActionFinished(self, instance, action):33 self.idle()34 if action.getId() != 'stand':35 self.idlecounter = 136 else:37 self.idlecounter += 138 39 def start(self):40 self.idle()41 42 def idle(self):43 self.state = _STATE_IDLE44 self.agent.act('stand', self.agent.getFacingLocation())45 46 def run(self, location):47 self.state = _STATE_RUN48 self.agent.move('run',location,self.speed)49 -
trunk/PARPG/scripts/engine.py
r66 r68 21 21 from agents.hero import Hero 22 22 from agents.npc import NPC 23 from objects import GameObject 23 24 24 25 # design note: … … 65 66 ypos = attrs.getValue("ypos") 66 67 gfx = attrs.getValue("gfx") 68 ident = attrs.getValue("id") 69 text = attrs.getValue("text") 67 70 except(KeyError): 68 71 sys.stderr.write("Error: Data missing in NPC definition\n") 69 72 sys.exit(False) 70 73 # now we have the data, save it for later 71 self.npcs.append([xpos, ypos,gfx])74 self.npcs.append([xpos, ypos, gfx, ident, text]) 72 75 elif(name == "object"): 73 76 # same old same old … … 76 79 ypos = attrs.getValue("ypos") 77 80 gfx = attrs.getValue("gfx") 81 ident = attrs.getValue("id") 82 text = attrs.getValue("text") 78 83 except(KeyError): 79 84 sys.stderr.write("Error: Data missing in object definition\n") 80 85 sys.exit(False) 81 86 # now we have the data, save it for later 82 self.objects.append([xpos, ypos, gfx ])87 self.objects.append([xpos, ypos, gfx, ident, text]) 83 88 84 89 class Engine: … … 132 137 for i in objects: 133 138 self.view.addObject(float(i[0]), float(i[1]), i[2]) 139 # now add it as an engine object 140 self.objects.append(GameObject(int(float(i[0])), 141 int(float(i[1])), i[3], i[4])) 134 142 135 143 def addNPCs(self,npcs): … … 137 145 and into this class""" 138 146 for i in npcs: 139 self.view.addObject(float(i[0]), float(i[1]),i[2]) 147 self.view.addObject(float(i[0]), float(i[1]), i[2]) 148 # now add as engine data 149 self.npcs.append(NPC(int(float(i[0])), int(float(i[1])), 150 i[3], i[4])) 151 152 def getObjectString(self, xpos, ypos): 153 """Get the objects description of itself""" 154 # cycle through all of the objects; do we have something there? 155 for i in self.objects: 156 if((xpos == i.xpos)and(ypos == i.ypos)): 157 # yes, we have a match, so return the text 158 return i.text 159 for i in self.npcs: 160 if((xpos == i.xpos)and(ypos == i.ypos)): 161 # yes, we have a match, so return the text 162 return i.text 163 # nothing, but return the empty string in case we print it 164 return "" 140 165 141 166 def loadMap(self,map_file): … … 146 171 # then we update FIFE with the PC, NPC and object details 147 172 self.loadObjects(map_file[:-4]+"_objects.xml") 148 # add a callbacks routine to handle mouse clicks149 # TODO: not totally happy about this code150 self.view.mouseCallback=self.handleMouseClick151 173 152 174 def handleMouseClick(self,position): -
trunk/PARPG/scripts/world.py
r66 r68 67 67 self.inventoryShown = False 68 68 self.firstInventory = True 69 self.data = None 69 70 self.mouseCallback = None 70 71 … … 121 122 fife.InstanceVisual.create(obj) 122 123 124 def displayInventory(self): 125 """Pause the game and enter the inventory screen""" 126 123 127 # all key / mouse event handling routines go here 124 128 def keyPressed(self, evt): 125 """When a key is depressed, fife calls this routine."""129 """When a key is pressed, fife calls this routine.""" 126 130 key = evt.getKey() 127 131 keyval = key.getValue() … … 159 163 self.inventoryShown = True 160 164 165 def getCoords(self, click): 166 """Get the map location x, y cords that have been clicked""" 167 coord = self.cameras["main"].toMapCoordinates(click, False) 168 coord.z = 0 169 location = fife.Location(self.agent_layer) 170 location.setMapCoordinates(coord) 171 return location 172 161 173 def mousePressed(self, evt): 162 174 """If a mouse button is pressed down, fife cals this routine 163 175 Currently we only check for a left click, and we assume this is on 164 176 the map""" 165 clickpoint = fife.ScreenPoint(evt.getX(), evt.getY()) 166 if (evt.getButton() == fife.MouseEvent.LEFT): 167 target_mapcoord = self.cameras['main'].toMapCoordinates(clickpoint, 168 False) 169 target_mapcoord.z = 0 170 l = fife.Location(self.agent_layer) 171 l.setMapCoordinates(target_mapcoord) 172 self.mouseCallback(l) 173 177 click = fife.ScreenPoint(evt.getX(), evt.getY()) 178 if(evt.getButton() == fife.MouseEvent.LEFT): 179 self.data.handleMouseClick(self.getCoords(click)) 180 elif(evt.getButton() == fife.MouseEvent.RIGHT): 181 # there's no need to query fife about what things are where, 182 # the engine code should know.... 183 coords = self.getCoords(click).getLayerCoordinates() 184 obj = self.data.getObjectString(coords.x, coords.y) 185 if(obj != ""): 186 print obj 187 174 188 def toggle_renderer (self, r_name): 175 189 """Enable or disable the renderer named `r_name`"""
Note: See TracChangeset
for help on using the changeset viewer.