comparison src/parpg/behaviours/base.py @ 75:c3350fc9cd45

Added approach functionality to the BaseBehaviour
author KarstenBock@gmx.net
date Thu, 08 Sep 2011 14:20:31 +0200
parents 58661f5b2f6b
children 8a7bb62f9f5d
comparison
equal deleted inserted replaced
74:47e1345fbac2 75:c3350fc9cd45
62 def idle(self): 62 def idle(self):
63 """@return: None""" 63 """@return: None"""
64 self.state = _AGENT_STATE_IDLE 64 self.state = _AGENT_STATE_IDLE
65 self.agent.act('stand', self.agent.getFacingLocation()) 65 self.agent.act('stand', self.agent.getFacingLocation())
66 66
67 def approach(self, location, action=None):
68 """Approaches a location and then perform an action (if set).
69 @type loc: fife.Location
70 @param loc: the location to approach
71 @type action: Action
72 @param action: The action to schedule for execution after the approach.
73 @return: None"""
74 self.state = _AGENT_STATE_APPROACH
75 self.nextAction = action
76 boxLocation = tuple([int(float(i)) for i in location])
77 l = fife.Location(self.agent.getLocation())
78 l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation))
79 self.agent.move('run', l, self.speed + 1)
80
67 def onInstanceActionFinished(self, instance, action): 81 def onInstanceActionFinished(self, instance, action):
68 pass 82 """@type instance: ???
83 @param instance: ???
84 @type action: ???
85 @param action: ???
86 @return: None"""
87 # First we reset the next behavior
88 act = self.nextAction
89 self.nextAction = None
90 self.idle()
91
92 if act:
93 act.execute()
94
95 if(action.getId() != 'stand'):
96 self.idle_counter = 1
97 else:
98 self.idle_counter += 1