Changeset 142 for trunk/PARPG/scripts/engine.py
- Timestamp:
- 06/15/09 12:36:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/PARPG/scripts/engine.py
r138 r142 36 36 """A MapDoor is an item that when clicked transports the player to 37 37 another map""" 38 def __init__(self, name, new_map, targ_tup): 38 def __init__(self, name, new_map, location): 39 """@type name: string 40 @param name: name of fife object 41 @type new_map: string 42 @param new_map: name of new map 43 @type location: tuple 44 @param location: where to put the PC when map is loaded 45 @return: None""" 39 46 self.id = name 40 47 self.map = "maps/"+new_map+".xml" 41 # self.targ_coord: a(int, int) which stores the intended location48 # location is an (int, int) which stores the intended location 42 49 # of the PC on the new map 43 self.targ_coords = targ_tup50 self.targ_coords = location 44 51 45 52 class Engine: 46 """Engine holds the logic for the game 53 """Engine holds the logic for the game. 47 54 Since some data (object position and so forth) is held in the 48 55 fife, and would be pointless to replicate, we hold a instance of 49 56 the fife view here. This also prevents us from just having a 50 function heavy controller """57 function heavy controller.""" 51 58 def __init__(self, view): 59 """Initialise the instance. 60 @type engine: world 61 @param engine: A world instance 62 @return: None""" 52 63 # a World object 53 64 self.view = view … … 60 71 def reset(self): 61 72 """Clears the data on a map reload so we don't have objects/npcs from 62 other maps hanging around.""" 73 other maps hanging around. 74 @return: None""" 63 75 self.PC = None 64 76 self.npcs = [] … … 68 80 def loadObjects(self, filename): 69 81 """Load objects from the XML file 70 Returns True if it worked, False otherwise""" 82 Returns True if it worked, False otherwise. 83 @type filename: string 84 @param filename: The XML file to read. 85 @rtype: boolean 86 @return: Status of result (True/False)""" 71 87 try: 72 88 objects_file = open(filename, 'rt') … … 93 109 94 110 def addPC(self,pc): 95 """Add the PC to the world""" 111 """Add the PC to the world 112 @type pc: list 113 @param pc: List of data for PC attributes 114 @return: None""" 96 115 if self.PC_targLoc: 97 116 self.view.addObject(float(self.PC_targLoc[0]), \ … … 107 126 def addObjects(self,objects): 108 127 """Add all of the objects we found into the fife map 109 and into our class 110 An NPC is just an object to FIFE""" 128 and into our class. An NPC is just an object to FIFE 129 @type objects: list 130 @param objects: List of objects to add 131 @return: None""" 111 132 for i in objects: 112 133 # is it visible? … … 117 138 118 139 def addNPCs(self,npcs): 119 """Add all of the NPCs we found into the fife map 120 and into this class""" 140 """Add all of the NPCs we found into the fife map to FIFE. 141 @type npcs: list 142 @param npcs: List of NPC's to add 143 @return: None""" 121 144 for i in npcs: 122 145 self.view.addObject(float(i[0]), float(i[1]), i[2], i[3]) … … 126 149 127 150 def addDoors(self, doors): 128 """Add all the doors to the map as well 129 As an object they have already been added""" 151 """Add all the doors to the map as well. 152 As an object they will have already been added. 153 @type engine: list 154 @param engine: List of doors 155 @return: None""" 130 156 for i in doors: 131 157 self.doors.append(MapDoor(i[0], i[1], i[2])) … … 133 159 def objectActive(self, ident): 134 160 """Given the objects ID, pass back the object if it is active, 135 False if it doesn't exist or not displayed""" 161 False if it doesn't exist or not displayed 162 @type ident: string 163 @param ident: ID of object 164 @rtype: boolean 165 @return: Status of result (True/False)""" 136 166 for i in self.objects: 137 167 if((i.display == True)and(i.id == ident)): … … 147 177 148 178 def getItemActions(self, obj_id): 149 """Given the objects ID, return the text strings and callbacks""" 179 """Given the objects ID, return the text strings and callbacks. 180 @type obj_id: string 181 @param obj_id: ID of object 182 @rtype: list 183 @return: List of text and callbacks""" 150 184 actions=[] 151 185 # note: ALWAYS check NPC's first! … … 177 211 178 212 def loadMap(self,map_file): 179 """Load a new map 180 TODO: needs some error checking""" 213 """Load a new map. TODO: needs some error checking 214 @type map_file: string 215 @param map_file: Name of map file to load 216 @return: None""" 181 217 # first we let FIFE load the rest of the map 182 218 self.view.load(map_file) … … 186 222 187 223 def handleMouseClick(self,position): 224 """Code called when user left clicks the screen. 225 @type position: fife.ScreenPoint 226 @param position: Screen position of click 227 @return: None""" 188 228 self.PC.run(position) 189 229
Note: See TracChangeset
for help on using the changeset viewer.