comparison src/parpg/behaviours/base.py @ 55:4311a0a5378c

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