comparison demos/rpg/scripts/actors/baseactor.py @ 563:f85762e634c5

- Added the AttackAction along with a test enemy on level 1. - Removed the getModuleByType() helper function.
author prock@33b003aa-7bff-0310-803a-e67f0ece8222
date Thu, 24 Jun 2010 21:27:11 +0000
parents 69d50e751c9a
children 872a7a94563e
comparison
equal deleted inserted replaced
562:e34b44afd428 563:f85762e634c5
60 else: 60 else:
61 self._dest.completeQuest() 61 self._dest.completeQuest()
62 else: 62 else:
63 self._dest.showNoQuestDialog() 63 self._dest.showNoQuestDialog()
64 else: 64 else:
65 self._dest.instance.say("Hello there!") 65 self._dest.say("Hello there!")
66
67 class AttackAction(BaseAction):
68 def __init__(self, attacker, defender):
69 self._actiontype = Actions['ATTACK']
70 self._attacker = attacker
71 self._defender = defender
72
73 def execute(self):
74 if self._defender.type == GameObjectTypes["ENEMY"]:
75 self._defender.say("Ouch")
66 76
67 class PickUpItemAction(BaseAction): 77 class PickUpItemAction(BaseAction):
68 def __init__(self, actor, item): 78 def __init__(self, actor, item):
69 self._actiontype = Actions['PICKUP'] 79 self._actiontype = Actions['PICKUP']
70 self._actor = actor 80 self._actor = actor
153 163
154 class Actor(BaseGameObject): 164 class Actor(BaseGameObject):
155 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False): 165 def __init__(self, gamecontroller, layer, typename, baseobjectname, instancename, instanceid=None, createInstance=False):
156 super(Actor, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance) 166 super(Actor, self).__init__(gamecontroller, layer, typename, baseobjectname, instancename, instanceid, createInstance)
157 167
158 self._type = GameObjectTypes["DEFAULT"]
159
160 self._nextaction = None 168 self._nextaction = None
161 self._inventory = [] 169 self._inventory = []
162 self._maxinventoryitems = 20 170 self._maxinventoryitems = 20
163 171
164 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) 172 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0)