Mercurial > parpg-source
annotate behaviours/moving.py @ 179:90b2545f7459
This fixes the director exception when running a command in the console.
author | Beliar <KarstenBock@gmx.net> |
---|---|
date | Wed, 07 Mar 2012 20:04:48 +0100 |
parents | 04854cf6e1ac |
children |
rev | line source |
---|---|
103
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
1 # This file is part of PARPG. |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
2 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
3 # PARPG is free software: you can redistribute it and/or modify |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
4 # it under the terms of the GNU General Public License as published by |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
5 # the Free Software Foundation, either version 3 of the License, or |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
6 # (at your option) any later version. |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
7 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
8 # PARPG is distributed in the hope that it will be useful, |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
11 # GNU General Public License for more details. |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
12 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
13 # You should have received a copy of the GNU General Public License |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
15 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
16 from fife import fife |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
17 import base |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
18 from base import BaseBehaviour |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
19 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
20 class MovingAgentBehaviour (BaseBehaviour): |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
21 """Fife agent listener""" |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
22 def __init__(self): |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
23 BaseBehaviour.__init__(self) |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
24 self.speed = 0 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
25 self.idle_counter = 1 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
26 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
27 def onNewMap(self, layer): |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
28 """Sets the agent onto the new layer.""" |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
29 BaseBehaviour.onNewMap(self, layer) |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
30 self.idle_counter = 1 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
31 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
32 |
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.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
33 def approach(self, location_or_agent, action=None): |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
34 """Approaches a location or another agent and then perform an action |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
35 (if set). |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
36 @type loc: fife.Location |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
37 @param loc: the location or agent to approach |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
38 @type action: Action |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
39 @param action: The action to schedule for execution after the |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
40 approach. |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
41 @return: None""" |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
42 |
103
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
43 self.state = base._AGENT_STATE_APPROACH |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
44 self.nextAction = action |
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.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
45 if isinstance(location_or_agent, fife.Instance): |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
46 agent = location_or_agent |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
47 self.agent.follow('run', agent, self.speed + 1) |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
48 else: |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
49 location = location_or_agent |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
50 boxLocation = tuple([int(float(i)) for i in location]) |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
51 l = fife.Location(self.getLocation()) |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
52 l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation)) |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
53 self.agent.move('run', l, self.speed + 1) |
103
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
54 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
55 def onInstanceActionFinished(self, instance, action): |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
56 """@type instance: ??? |
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.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
57 @param instance: ??? |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
58 @type action: ??? |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
59 @param action: ??? |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
60 @return: None""" |
103
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
61 BaseBehaviour.onInstanceActionFinished(self, instance, action) |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
62 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
63 if(action.getId() != 'stand'): |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
64 self.idle_counter = 1 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
65 else: |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
66 self.idle_counter += 1 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
67 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
68 def idle(self): |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
69 """@return: None""" |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
70 BaseBehaviour.idle(self) |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
71 self.animate('stand') |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
72 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
73 def run(self, location): |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
74 """Makes the PC run to a certain location |
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.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
75 @type location: fife.ScreenPoint |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
76 @param location: Screen position to run to. |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
77 @return: None""" |
103
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
78 self.state = base._AGENT_STATE_RUN |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
79 self.clear_animations() |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
80 self.nextAction = None |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
81 self.agent.move('run', location, self.speed + 1) |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
82 |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
83 def walk(self, location): |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
84 """Makes the PC walk to a certain location. |
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.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
85 @type location: fife.ScreenPoint |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
86 @param location: Screen position to walk to. |
04854cf6e1ac
The approach method of MovingAgentBehaviour now accepts a locatior or another instance, and uses the follow method to move to the instance position.
KarstenBock@gmx.net
parents:
103
diff
changeset
|
87 @return: None""" |
103
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
88 self.state = base._AGENT_STATE_RUN |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
89 self.clear_animations() |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
90 self.nextAction = None |
57f1cff9a75d
Added animation queue and method the base behaviour class.
KarstenBock@gmx.net
parents:
61
diff
changeset
|
91 self.agent.move('walk', location, self.speed - 1) |
55
8b1ad2d342d8
Renamed BaseBehaviour to MovingAgentBehaviour
KarstenBock@gmx.net
parents:
diff
changeset
|
92 |