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