comparison demos/rpg/scripts/actors/baseactor.py @ 543:cb7ec12214a9

Items can now be serialized/deserialized to/from disk. I haven't finished actors yet. This allows for persistent states when you enter/leave maps.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Wed, 02 Jun 2010 21:43:03 +0000
parents 2e739ae9a8bc
children 8fee2d2286e9
comparison
equal deleted inserted replaced
542:67f6f3538e88 543:cb7ec12214a9
28 28
29 from fife import fife 29 from fife import fife
30 from fife.extensions.loaders import loadMapFile 30 from fife.extensions.loaders import loadMapFile
31 31
32 from scripts.objects.baseobject import ObjectActionListener, BaseGameObject, GameObjectTypes 32 from scripts.objects.baseobject import ObjectActionListener, BaseGameObject, GameObjectTypes
33 from scripts.objects.items import GoldStack
33 34
34 Actions = {'NONE':0, 35 Actions = {'NONE':0,
35 'PICKUP':1, 36 'PICKUP':1,
36 'TALK':2, 37 'TALK':2,
37 'ATTACK':3, 38 'ATTACK':3,
93 if action.getId() == 'walk': 94 if action.getId() == 'walk':
94 self._object.stand() 95 self._object.stand()
95 self._object.performNextAction() 96 self._object.performNextAction()
96 97
97 class Actor(BaseGameObject): 98 class Actor(BaseGameObject):
98 def __init__(self, gamecontroller, actortype, instancename, instanceid=None, createInstance=False): 99 def __init__(self, gamecontroller, layer, typename, instancename, instanceid=None, createInstance=False):
99 super(Actor, self).__init__(gamecontroller, actortype, instancename, instanceid, createInstance) 100 super(Actor, self).__init__(gamecontroller, layer, typename, instancename, instanceid, createInstance)
101
102 self._type = GameObjectTypes["DEFAULT"]
100 103
101 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) 104 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0)
102 105
103 self._nextaction = None 106 self._nextaction = None
104 self._inventory = [] 107 self._inventory = []
126 129
127 def pickUpItem(self, item): 130 def pickUpItem(self, item):
128 if len(self._inventory) >= self._maxinventoryitems: 131 if len(self._inventory) >= self._maxinventoryitems:
129 return 132 return
130 else: 133 else:
131 if item.modelname == "goldstack": 134 if type(item) == GoldStack:
132 self._gold += item.value 135 self._gold += item.value
133 else: 136 else:
134 self._inventory.append(item) 137 self._inventory.append(item)
135 138
136 item.onLeftClick() 139 item.onPickUp()
137 140
138 def enterPortal(self, portal): 141 def enterPortal(self, portal):
139 if self._id == "player": 142 if self._id == "player":
140 self._gamecontroller.switchMap(portal.dest) 143 self._gamecontroller.switchMap(portal.dest)
141 else: 144 else: