comparison 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
comparison
equal deleted inserted replaced
518:e4cd18a179af 519:14f777be6b94
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 32 from scripts.objects.baseobject import ObjectActionListener, BaseGameObject
33 33
34 Actions = {'NONE':0,
35 'PICKUP':1,
36 'TALK':2,
37 'HIT':3}
38
39 class BaseAction(object):
40 def __init__(self):
41 self._actiontype = Actions['NONE']
42
43 def execute(self):
44 pass
45
46 class TalkAction(BaseAction):
47 def __init__(self, sourceobj, destobj):
48 self._actiontype = Actions['TALK']
49 self._source = sourceobj
50 self._dest = destobj
51
52 def execute(self):
53 print "talking"
54
34 ActorStates = {'STAND':0, 55 ActorStates = {'STAND':0,
35 'WALK':1, 56 'WALK':1,
36 'ATTACK':2} 57 'ATTACK':2}
37 58
38 class ActorActionListener(ObjectActionListener): 59 class ActorActionListener(ObjectActionListener):
40 super(ActorActionListener, self).__init__(gamecontroller, obj) 61 super(ActorActionListener, self).__init__(gamecontroller, obj)
41 62
42 def onInstanceActionFinished(self, instance, action): 63 def onInstanceActionFinished(self, instance, action):
43 if action.getId() == 'walk': 64 if action.getId() == 'walk':
44 self._object.stand() 65 self._object.stand()
66 self._object.performNextAction()
45 67
46 class Actor(BaseGameObject): 68 class Actor(BaseGameObject):
47 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False): 69 def __init__(self, gamecontroller, instancename, instanceid=None, createInstance=False):
48 super(Actor, self).__init__(gamecontroller, instancename, instanceid, createInstance) 70 super(Actor, self).__init__(gamecontroller, instancename, instanceid, createInstance)
49 71
50 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0) 72 self._walkspeed = self._gamecontroller.settings.get("RPG", "DefaultActorWalkSpeed", 4.0)
51 73
52 self._actionlistener = ActorActionListener(self._gamecontroller, self) 74 self._actionlistener = ActorActionListener(self._gamecontroller, self)
75
76 self._nextaction = None
53 77
54 self.stand() 78 self.stand()
55 79
56 def stand(self): 80 def stand(self):
57 self._state = ActorStates["STAND"] 81 self._state = ActorStates["STAND"]
59 83
60 def walk(self, location): 84 def walk(self, location):
61 self._state = ActorStates["WALK"] 85 self._state = ActorStates["WALK"]
62 self._instance.move('walk', location, self._walkspeed) 86 self._instance.move('walk', location, self._walkspeed)
63 87
88 def performNextAction(self):
89 if self._nextaction:
90 self._nextaction.execute()
91 self._nextaction = None
92
64 def _getState(self): 93 def _getState(self):
65 return self._state 94 return self._state
66 95
67 def _setState(self, state): 96 def _setState(self, state):
68 self._state = state 97 self._state = state
98
99 def _getNextAction(self):
100 return self._nextaction
101
102 def _setNextAction(self, action):
103 self._nextaction = action
69 104
70 state = property(_getState, _setState) 105 state = property(_getState, _setState)
106 nextaction = property(_getNextAction, _setNextAction)