Mercurial > parpg-source
diff behaviours/moving.py @ 158:04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
author | KarstenBock@gmx.net |
---|---|
date | Sat, 12 Nov 2011 20:54:25 +0100 |
parents | 57f1cff9a75d |
children |
line wrap: on
line diff
--- a/behaviours/moving.py Sat Nov 12 16:27:39 2011 +0100 +++ b/behaviours/moving.py Sat Nov 12 20:54:25 2011 +0100 @@ -30,26 +30,34 @@ self.idle_counter = 1 - def approach(self, location, action=None): - """Approaches a location and then perform an action (if set). - @type loc: fife.Location - @param loc: the location to approach - @type action: Action - @param action: The action to schedule for execution after the approach. - @return: None""" + def approach(self, location_or_agent, action=None): + """Approaches a location or another agent and then perform an action + (if set). + @type loc: fife.Location + @param loc: the location or agent to approach + @type action: Action + @param action: The action to schedule for execution after the + approach. + @return: None""" + self.state = base._AGENT_STATE_APPROACH self.nextAction = action - boxLocation = tuple([int(float(i)) for i in location]) - l = fife.Location(self.agent.getLocation()) - l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation)) - self.agent.move('run', l, self.speed + 1) + if isinstance(location_or_agent, fife.Instance): + agent = location_or_agent + self.agent.follow('run', agent, self.speed + 1) + else: + location = location_or_agent + boxLocation = tuple([int(float(i)) for i in location]) + l = fife.Location(self.getLocation()) + l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation)) + self.agent.move('run', l, self.speed + 1) def onInstanceActionFinished(self, instance, action): """@type instance: ??? - @param instance: ??? - @type action: ??? - @param action: ??? - @return: None""" + @param instance: ??? + @type action: ??? + @param action: ??? + @return: None""" BaseBehaviour.onInstanceActionFinished(self, instance, action) if(action.getId() != 'stand'): @@ -64,9 +72,9 @@ def run(self, location): """Makes the PC run to a certain location - @type location: fife.ScreenPoint - @param location: Screen position to run to. - @return: None""" + @type location: fife.ScreenPoint + @param location: Screen position to run to. + @return: None""" self.state = base._AGENT_STATE_RUN self.clear_animations() self.nextAction = None @@ -74,9 +82,9 @@ def walk(self, location): """Makes the PC walk to a certain location. - @type location: fife.ScreenPoint - @param location: Screen position to walk to. - @return: None""" + @type location: fife.ScreenPoint + @param location: Screen position to walk to. + @return: None""" self.state = base._AGENT_STATE_RUN self.clear_animations() self.nextAction = None