annotate behaviours/base.py @ 44:98f26f7636d8

Changes to make PARPG "runable" with grease. (With the correct modified assets)
author KarstenBock@gmx.net
date Tue, 06 Sep 2011 15:22:51 +0200
parents 77dfe4a917b5
children bf506f739322
rev   line source
30
ec5a55266f6a 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.
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
2
ec5a55266f6a 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
ec5a55266f6a 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
ec5a55266f6a 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
ec5a55266f6a 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.
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
7
ec5a55266f6a 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,
ec5a55266f6a 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
ec5a55266f6a 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
ec5a55266f6a 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.
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
12
ec5a55266f6a 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
ec5a55266f6a 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/>.
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
15
ec5a55266f6a 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
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
17
ec5a55266f6a 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)
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
19
ec5a55266f6a 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):
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
21 """Fife agent listener"""
33
77dfe4a917b5 Set default value of layer parameter of BaseBehaviour to None
KarstenBock@gmx.net
parents: 30
diff changeset
22 def __init__(self, layer=None):
30
ec5a55266f6a 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)
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
24 self.layer = layer
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
25 self.agent = None
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
26 self.state = None
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
27 self.speed = 0
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
28 self.idle_counter = 1
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
29
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
30 def attachToLayer(self, agent_ID):
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
31 """Attaches to a certain layer
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
32 @type agent_ID: String
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
33 @param agent_ID: ID of the layer to attach to.
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
34 @return: None"""
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
35 self.agent = self.layer.getInstance(agent_ID)
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
36 self.agent.addActionListener(self)
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
37 self.state = _AGENT_STATE_NONE
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
38
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
39 def getX(self):
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
40 """Get the NPC's x position on the map.
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
41 @rtype: integer"
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
42 @return: the x coordinate of the NPC's location"""
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
43 return self.agent.getLocation().getLayerCoordinates().x
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
44
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
45 def getY(self):
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
46 """Get the NPC's y position on the map.
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
47 @rtype: integer
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
48 @return: the y coordinate of the NPC's location"""
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
49 return self.agent.getLocation().getLayerCoordinates().y
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
50
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
51 def onNewMap(self, layer):
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
52 """Sets the agent onto the new layer."""
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
53 if self.agent is not None:
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
54 self.agent.removeActionListener(self)
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
55
44
98f26f7636d8 Changes to make PARPG "runable" with grease. (With the correct modified assets)
KarstenBock@gmx.net
parents: 33
diff changeset
56 self.agent = layer.getInstance(self.parent.fifeagent.identifier)
30
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
57 self.agent.addActionListener(self)
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
58 self.state = _AGENT_STATE_NONE
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
59 self.idle_counter = 1
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
60
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
61 def idle(self):
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
62 """@return: None"""
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
63 self.state = _AGENT_STATE_IDLE
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
64 self.agent.act('stand', self.agent.getFacingLocation())
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
65
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
66 def onInstanceActionFinished(self, instance, action):
ec5a55266f6a Moved behaviours from objects/actors.py to files seperate files inside a behaviours directory.
KarstenBock@gmx.net
parents:
diff changeset
67 pass