Mercurial > fife-parpg
diff demos/rpg/scripts/actors/baseactor.py @ 519:14f777be6b94
Added a rudimentary Action class.
author | prock@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Thu, 27 May 2010 04:36:09 +0000 |
parents | c3a026cdd91b |
children | b6bd314df28a |
line wrap: on
line diff
--- a/demos/rpg/scripts/actors/baseactor.py Wed May 26 21:29:46 2010 +0000 +++ b/demos/rpg/scripts/actors/baseactor.py Thu May 27 04:36:09 2010 +0000 @@ -31,6 +31,27 @@ from scripts.objects.baseobject import ObjectActionListener, BaseGameObject +Actions = {'NONE':0, + 'PICKUP':1, + 'TALK':2, + 'HIT':3} + +class BaseAction(object): + def __init__(self): + self._actiontype = Actions['NONE'] + + def execute(self): + pass + +class TalkAction(BaseAction): + def __init__(self, sourceobj, destobj): + self._actiontype = Actions['TALK'] + self._source = sourceobj + self._dest = destobj + + def execute(self): + print "talking" + ActorStates = {'STAND':0, 'WALK':1, 'ATTACK':2} @@ -42,6 +63,7 @@ def onInstanceActionFinished(self, instance, action): if action.getId() == 'walk': self._object.stand() + self._object.performNextAction() class Actor(BaseGameObject): def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False): @@ -51,6 +73,8 @@ self._actionlistener = ActorActionListener(self._gamecontroller, self) + self._nextaction = None + self.stand() def stand(self): @@ -61,10 +85,22 @@ self._state = ActorStates["WALK"] self._instance.move('walk', location, self._walkspeed) + def performNextAction(self): + if self._nextaction: + self._nextaction.execute() + self._nextaction = None + def _getState(self): return self._state def _setState(self, state): self._state = state + + def _getNextAction(self): + return self._nextaction + + def _setNextAction(self, action): + self._nextaction = action state = property(_getState, _setState) + nextaction = property(_getNextAction, _setNextAction)