comparison 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
comparison
equal deleted inserted replaced
157:79d6b17b80a3 158:04854cf6e1ac
28 """Sets the agent onto the new layer.""" 28 """Sets the agent onto the new layer."""
29 BaseBehaviour.onNewMap(self, layer) 29 BaseBehaviour.onNewMap(self, layer)
30 self.idle_counter = 1 30 self.idle_counter = 1
31 31
32 32
33 def approach(self, location, action=None): 33 def approach(self, location_or_agent, action=None):
34 """Approaches a location and then perform an action (if set). 34 """Approaches a location or another agent and then perform an action
35 @type loc: fife.Location 35 (if set).
36 @param loc: the location to approach 36 @type loc: fife.Location
37 @type action: Action 37 @param loc: the location or agent to approach
38 @param action: The action to schedule for execution after the approach. 38 @type action: Action
39 @return: None""" 39 @param action: The action to schedule for execution after the
40 approach.
41 @return: None"""
42
40 self.state = base._AGENT_STATE_APPROACH 43 self.state = base._AGENT_STATE_APPROACH
41 self.nextAction = action 44 self.nextAction = action
42 boxLocation = tuple([int(float(i)) for i in location]) 45 if isinstance(location_or_agent, fife.Instance):
43 l = fife.Location(self.agent.getLocation()) 46 agent = location_or_agent
44 l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation)) 47 self.agent.follow('run', agent, self.speed + 1)
45 self.agent.move('run', l, self.speed + 1) 48 else:
49 location = location_or_agent
50 boxLocation = tuple([int(float(i)) for i in location])
51 l = fife.Location(self.getLocation())
52 l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation))
53 self.agent.move('run', l, self.speed + 1)
46 54
47 def onInstanceActionFinished(self, instance, action): 55 def onInstanceActionFinished(self, instance, action):
48 """@type instance: ??? 56 """@type instance: ???
49 @param instance: ??? 57 @param instance: ???
50 @type action: ??? 58 @type action: ???
51 @param action: ??? 59 @param action: ???
52 @return: None""" 60 @return: None"""
53 BaseBehaviour.onInstanceActionFinished(self, instance, action) 61 BaseBehaviour.onInstanceActionFinished(self, instance, action)
54 62
55 if(action.getId() != 'stand'): 63 if(action.getId() != 'stand'):
56 self.idle_counter = 1 64 self.idle_counter = 1
57 else: 65 else:
62 BaseBehaviour.idle(self) 70 BaseBehaviour.idle(self)
63 self.animate('stand') 71 self.animate('stand')
64 72
65 def run(self, location): 73 def run(self, location):
66 """Makes the PC run to a certain location 74 """Makes the PC run to a certain location
67 @type location: fife.ScreenPoint 75 @type location: fife.ScreenPoint
68 @param location: Screen position to run to. 76 @param location: Screen position to run to.
69 @return: None""" 77 @return: None"""
70 self.state = base._AGENT_STATE_RUN 78 self.state = base._AGENT_STATE_RUN
71 self.clear_animations() 79 self.clear_animations()
72 self.nextAction = None 80 self.nextAction = None
73 self.agent.move('run', location, self.speed + 1) 81 self.agent.move('run', location, self.speed + 1)
74 82
75 def walk(self, location): 83 def walk(self, location):
76 """Makes the PC walk to a certain location. 84 """Makes the PC walk to a certain location.
77 @type location: fife.ScreenPoint 85 @type location: fife.ScreenPoint
78 @param location: Screen position to walk to. 86 @param location: Screen position to walk to.
79 @return: None""" 87 @return: None"""
80 self.state = base._AGENT_STATE_RUN 88 self.state = base._AGENT_STATE_RUN
81 self.clear_animations() 89 self.clear_animations()
82 self.nextAction = None 90 self.nextAction = None
83 self.agent.move('walk', location, self.speed - 1) 91 self.agent.move('walk', location, self.speed - 1)
84 92