diff src/parpg/behaviours/moving.py @ 133:ecac92680bef

Added animation queue and method the base behaviour class.
author KarstenBock@gmx.net
date Fri, 30 Sep 2011 14:04:29 +0200
parents d89e88a90c9e
children a22e92090018
line wrap: on
line diff
--- a/src/parpg/behaviours/moving.py	Thu Sep 29 18:15:12 2011 +0200
+++ b/src/parpg/behaviours/moving.py	Fri Sep 30 14:04:29 2011 +0200
@@ -1,82 +1,84 @@
-#   This file is part of PARPG.
-
-#   PARPG is free software: you can redistribute it and/or modify
-#   it under the terms of the GNU General Public License as published by
-#   the Free Software Foundation, either version 3 of the License, or
-#   (at your option) any later version.
-
-#   PARPG is distributed in the hope that it will be useful,
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#   GNU General Public License for more details.
-
-#   You should have received a copy of the GNU General Public License
-#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
-
-from fife import fife
-import base
-from base import BaseBehaviour
-
-class MovingAgentBehaviour (BaseBehaviour):
-    """Fife agent listener"""
-    def __init__(self):
-        BaseBehaviour.__init__(self)
-        self.speed = 0
-        self.idle_counter = 1
-        
-    def onNewMap(self, layer):
-        """Sets the agent onto the new layer."""
-        BaseBehaviour.onNewMap(self, layer)
-        self.idle_counter = 1
-
-
-    def approach(self, location, action=None):
-        """Approaches a location and then perform an action (if set).
-           @type loc: fife.Location
-           @param loc: the location to approach
-           @type action: Action
-           @param action: The action to schedule for execution after the approach.
-           @return: None"""
-        self.state = base._AGENT_STATE_APPROACH
-        self.nextAction = action
-        boxLocation = tuple([int(float(i)) for i in location])
-        l = fife.Location(self.agent.getLocation())
-        l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation))
-        self.agent.move('run', l, self.speed + 1)        
-        
-    def onInstanceActionFinished(self, instance, action):
-        """@type instance: ???
-           @param instance: ???
-           @type action: ???
-           @param action: ???
-           @return: None"""
-        BaseBehaviour.onInstanceActionFinished(self, instance, action)
-            
-        if(action.getId() != 'stand'):
-            self.idle_counter = 1
-        else:
-            self.idle_counter += 1 
-        
-    def idle(self):
-        """@return: None"""
-        BaseBehaviour.idle(self)
-        self.agent.act('stand', self.agent.getFacingLocation())    
-        
-    def run(self, location):
-        """Makes the PC run to a certain location
-           @type location: fife.ScreenPoint
-           @param location: Screen position to run to.
-           @return: None"""
-        self.state = base._AGENT_STATE_RUN
-        self.nextAction = None
-        self.agent.move('run', location, self.speed + 1)
-
-    def walk(self, location):
-        """Makes the PC walk to a certain location.
-           @type location: fife.ScreenPoint
-           @param location: Screen position to walk to.
-           @return: None"""
-        self.state = base._AGENT_STATE_RUN
-        self.nextAction = None 
-        self.agent.move('walk', location, self.speed - 1)
+#   This file is part of PARPG.
+
+#   PARPG is free software: you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation, either version 3 of the License, or
+#   (at your option) any later version.
+
+#   PARPG is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+
+#   You should have received a copy of the GNU General Public License
+#   along with PARPG.  If not, see <http://www.gnu.org/licenses/>.
+
+from fife import fife
+import base
+from base import BaseBehaviour
+
+class MovingAgentBehaviour (BaseBehaviour):
+    """Fife agent listener"""
+    def __init__(self):
+        BaseBehaviour.__init__(self)
+        self.speed = 0
+        self.idle_counter = 1
+        
+    def onNewMap(self, layer):
+        """Sets the agent onto the new layer."""
+        BaseBehaviour.onNewMap(self, layer)
+        self.idle_counter = 1
+
+
+    def approach(self, location, action=None):
+        """Approaches a location and then perform an action (if set).
+           @type loc: fife.Location
+           @param loc: the location to approach
+           @type action: Action
+           @param action: The action to schedule for execution after the approach.
+           @return: None"""
+        self.state = base._AGENT_STATE_APPROACH
+        self.nextAction = action
+        boxLocation = tuple([int(float(i)) for i in location])
+        l = fife.Location(self.agent.getLocation())
+        l.setLayerCoordinates(fife.ModelCoordinate(*boxLocation))
+        self.agent.move('run', l, self.speed + 1)        
+        
+    def onInstanceActionFinished(self, instance, action):
+        """@type instance: ???
+           @param instance: ???
+           @type action: ???
+           @param action: ???
+           @return: None"""
+        BaseBehaviour.onInstanceActionFinished(self, instance, action)
+            
+        if(action.getId() != 'stand'):
+            self.idle_counter = 1
+        else:
+            self.idle_counter += 1 
+        
+    def idle(self):
+        """@return: None"""
+        BaseBehaviour.idle(self)
+        self.animate('stand')    
+        
+    def run(self, location):
+        """Makes the PC run to a certain location
+           @type location: fife.ScreenPoint
+           @param location: Screen position to run to.
+           @return: None"""
+        self.state = base._AGENT_STATE_RUN
+        self.clear_animations()
+        self.nextAction = None
+        self.agent.move('run', location, self.speed + 1)
+
+    def walk(self, location):
+        """Makes the PC walk to a certain location.
+           @type location: fife.ScreenPoint
+           @param location: Screen position to walk to.
+           @return: None"""
+        self.state = base._AGENT_STATE_RUN
+        self.clear_animations()
+        self.nextAction = None
+        self.agent.move('walk', location, self.speed - 1)
         
\ No newline at end of file