Mercurial > parpg-core
annotate src/parpg/behaviours/base.py @ 73:58661f5b2f6b
Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
author | KarstenBock@gmx.net |
---|---|
date | Wed, 07 Sep 2011 13:54:02 +0200 |
parents | ad75fa042b99 |
children | c3350fc9cd45 |
rev | line source |
---|---|
55
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
1 # This file is part of PARPG. |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
2 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
3 # PARPG is free software: you can redistribute it and/or modify |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
4 # it under the terms of the GNU General Public License as published by |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
5 # the Free Software Foundation, either version 3 of the License, or |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
6 # (at your option) any later version. |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
7 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
8 # PARPG is distributed in the hope that it will be useful, |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
11 # GNU General Public License for more details. |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
12 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
13 # You should have received a copy of the GNU General Public License |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
14 # along with PARPG. If not, see <http://www.gnu.org/licenses/>. |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
15 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
16 from fife import fife |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
17 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
18 _AGENT_STATE_NONE, _AGENT_STATE_IDLE, _AGENT_STATE_APPROACH, _AGENT_STATE_RUN, _AGENT_STATE_WANDER, _AGENT_STATE_TALK = xrange(6) |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
19 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
20 class BaseBehaviour (fife.InstanceActionListener): |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
21 """Fife agent listener""" |
73
58661f5b2f6b
Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
KarstenBock@gmx.net
parents:
69
diff
changeset
|
22 def __init__(self): |
55
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
23 fife.InstanceActionListener.__init__(self) |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
24 self.agent = None |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
25 self.state = None |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
26 self.speed = 0 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
27 self.idle_counter = 1 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
28 |
73
58661f5b2f6b
Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
KarstenBock@gmx.net
parents:
69
diff
changeset
|
29 def attachToLayer(self, agent_ID, layer): |
55
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
30 """Attaches to a certain layer |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
31 @type agent_ID: String |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
32 @param agent_ID: ID of the layer to attach to. |
73
58661f5b2f6b
Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
KarstenBock@gmx.net
parents:
69
diff
changeset
|
33 @type layer: Fife layer |
58661f5b2f6b
Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
KarstenBock@gmx.net
parents:
69
diff
changeset
|
34 @param layer: Layer of the agent to attach the behaviour to |
55
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
35 @return: None""" |
73
58661f5b2f6b
Removed layer as attribute of BaseBehaviour and added it as a parameter to the attachToLayer method.
KarstenBock@gmx.net
parents:
69
diff
changeset
|
36 self.agent = layer.getInstance(agent_ID) |
55
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
37 self.agent.addActionListener(self) |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
38 self.state = _AGENT_STATE_NONE |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
39 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
40 def getX(self): |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
41 """Get the NPC's x position on the map. |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
42 @rtype: integer" |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
43 @return: the x coordinate of the NPC's location""" |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
44 return self.agent.getLocation().getLayerCoordinates().x |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
45 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
46 def getY(self): |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
47 """Get the NPC's y position on the map. |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
48 @rtype: integer |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
49 @return: the y coordinate of the NPC's location""" |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
50 return self.agent.getLocation().getLayerCoordinates().y |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
51 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
52 def onNewMap(self, layer): |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
53 """Sets the agent onto the new layer.""" |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
54 if self.agent is not None: |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
55 self.agent.removeActionListener(self) |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
56 |
69
ad75fa042b99
Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents:
58
diff
changeset
|
57 self.agent = layer.getInstance(self.parent.fifeagent.identifier) |
55
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
58 self.agent.addActionListener(self) |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
59 self.state = _AGENT_STATE_NONE |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
60 self.idle_counter = 1 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
61 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
62 def idle(self): |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
63 """@return: None""" |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
64 self.state = _AGENT_STATE_IDLE |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
65 self.agent.act('stand', self.agent.getFacingLocation()) |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
66 |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
67 def onInstanceActionFinished(self, instance, action): |
4311a0a5378c
Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff
changeset
|
68 pass |