comparison demos/rpg/scripts/actors/baseactor.py @ 575:872a7a94563e

- Updated the soundmanager extension to reflect changes made in last commit. - Made actor walk speed part of the ActorAttributes class. - The ActorAttributes class now gets serialized correctly.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Fri, 02 Jul 2010 14:41:27 +0000
parents f85762e634c5
children
comparison
equal deleted inserted replaced
574:58c0bbeeeb35 575:872a7a94563e
104 if action.getId() == 'walk': 104 if action.getId() == 'walk':
105 self._object.stand() 105 self._object.stand()
106 self._object.performNextAction() 106 self._object.performNextAction()
107 107
108 class ActorAttributes(Serializer): 108 class ActorAttributes(Serializer):
109 def __init__(self, strength=0, dexterity=0, intelligence=0, health=0): 109 def __init__(self, strength=0, dexterity=0, intelligence=0, health=0, walkspeed=0):
110 self._str = strength 110 self._str = strength
111 self._dex = dexterity 111 self._dex = dexterity
112 self._int = intelligence 112 self._int = intelligence
113 self._hp = health 113 self._hp = health
114 self._walkspeed = walkspeed
114 115
115 def serialize(self): 116 def serialize(self):
117 lvars = {}
118
116 lvars['str'] = self._str 119 lvars['str'] = self._str
117 lvars['dex'] = self._dex 120 lvars['dex'] = self._dex
118 lvars['int'] = self._int 121 lvars['int'] = self._int
119 lvars['hp'] = self._hp 122 lvars['hp'] = self._hp
123 lvars['walk_speed'] = self._walkspeed
120 124
121 return lvars 125 return lvars
122 126
123 def deserialize(self, valuedict): 127 def deserialize(self, valuedict):
124 if valuedict.has_key("str"): 128 if valuedict.has_key("str"):
127 self._dex = int(valuedict['dex']) 131 self._dex = int(valuedict['dex'])
128 if valuedict.has_key("int"): 132 if valuedict.has_key("int"):
129 self._int = int(valuedict['int']) 133 self._int = int(valuedict['int'])
130 if valuedict.has_key("hp"): 134 if valuedict.has_key("hp"):
131 self._hp = int(valuedict['hp']) 135 self._hp = int(valuedict['hp'])
136 if valuedict.has_key("walk_speed"):
137 self._walkspeed = float(valuedict['walk_speed'])
132 138
133 def _getStrength(self): 139 def _getStrength(self):
134 return self._str 140 return self._str
135 141
136 def _setStrength(self, strength): 142 def _setStrength(self, strength):
151 def _getHealth(self): 157 def _getHealth(self):
152 return self._hp 158 return self._hp
153 159
154 def _setHealth(self, health): 160 def _setHealth(self, health):
155 self._hp = health 161 self._hp = health
162
163 def _getWalkSpeed(self):
164 return self._walkspeed
165
166 def _setWalkSpeed(self, walkspeed):
167 self._walkspeed = walkspeed
156 168
157 169
158 strength = property(_getStrength, _setStrength) 170 strength = property(_getStrength, _setStrength)
159 dexterity = property(_getDexterity, _setDexterity) 171 dexterity = property(_getDexterity, _setDexterity)
160 intelligence = property(_getIntelligence, _setIntelligence) 172 intelligence = property(_getIntelligence, _setIntelligence)
161 health = property(_getHealth, _setHealth) 173 health = property(_getHealth, _setHealth)
174 walkspeed = property(_getWalkSpeed, _setWalkSpeed)
162 175
163 176
164 class Actor(BaseGameObject): 177 class Actor(BaseGameObject):
165 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False): 178 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False):
166 super(Actor, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance) 179 super(Actor, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance)
167 180
168 self._nextaction = None 181 self._nextaction = None
169 self._inventory = [] 182 self._inventory = []
170 self._maxinventoryitems = 20 183 self._maxinventoryitems = 20
171 184
172 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0)
173
174 self._gold = 0 185 self._gold = 0
175 self._attributes = ActorAttributes() 186 self._attributes = ActorAttributes()
176 187
188 #set the default walkspeed
189 self._attributes.walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0)
190
177 self.stand() 191 self.stand()
178 192
179 def stand(self): 193 def stand(self):
180 self._state = ActorStates["STAND"] 194 self._state = ActorStates["STAND"]
181 self._instance.act('stand', self._instance.getFacingLocation()) 195 self._instance.act('stand', self._instance.getFacingLocation())
182 196
183 def walk(self, location): 197 def walk(self, location):
184 self._state = ActorStates["WALK"] 198 self._state = ActorStates["WALK"]
185 self._instance.move('walk', location, self._walkspeed) 199 self._instance.move('walk', location, self._attributes.walkspeed)
186 200
187 def say(self, text): 201 def say(self, text):
188 self._instance.say(text, 2500) 202 self._instance.say(text, 2500)
189 203
190 def performNextAction(self): 204 def performNextAction(self):
228 def serialize(self): 242 def serialize(self):
229 lvars = super(Actor, self).serialize() 243 lvars = super(Actor, self).serialize()
230 244
231 lvars['gold'] = self._gold 245 lvars['gold'] = self._gold
232 246
247 att_vars = self._attributes.serialize()
248 for key, value in att_vars.items():
249 lvars[key] = value
250
233 return lvars 251 return lvars
234 252
235 def deserialize(self, valuedict): 253 def deserialize(self, valuedict):
236 super(Actor, self).deserialize(valuedict) 254 super(Actor, self).deserialize(valuedict)
237 255
238 if valuedict.has_key("gold"): 256 if valuedict.has_key("gold"):
239 self._gold = int(valuedict['gold']) 257 self._gold = int(valuedict['gold'])
240 else: 258 else:
241 self._gold = 0 259 self._gold = 0
242 260
243 if valuedict.has_key("walk_speed"): 261 self._attributes.deserialize(valuedict)
244 self._walkspeed = float(valuedict['walk_speed'])
245 262
246 def _getState(self): 263 def _getState(self):
247 return self._state 264 return self._state
248 265
249 def _setState(self, state): 266 def _setState(self, state):