Browse Source

added SwimWalker; strafe turns

Darren Ranalli 20 years ago
parent
commit
81edb9fc7d
2 changed files with 32 additions and 9 deletions
  1. 12 9
      direct/src/controls/NonPhysicsWalker.py
  2. 20 0
      direct/src/controls/SwimWalker.py

+ 12 - 9
direct/src/controls/NonPhysicsWalker.py

@@ -184,14 +184,7 @@ class NonPhysicsWalker(DirectObject.DirectObject):
         """
         onScreenDebug.add("controls", "NonPhysicsWalker")
 
-    def handleAvatarControls(self, task):
-        """
-        Check on the arrow keys and update the avatar.
-        """
-        if not self.lifter.hasContact():
-            # hack fix for falling through the floor:
-            messenger.send("walkerIsOutOfWorld", [self.avatarNodePath])
-
+    def _calcSpeeds(self):
         # get the button states:
         forward = inputState.isSet("forward")
         reverse = inputState.isSet("reverse")
@@ -209,7 +202,17 @@ class NonPhysicsWalker(DirectObject.DirectObject):
         self.rotationSpeed=not slide and (
                 (turnLeft and self.avatarControlRotateSpeed) or
                 (turnRight and -self.avatarControlRotateSpeed))
-         
+
+    def handleAvatarControls(self, task):
+        """
+        Check on the arrow keys and update the avatar.
+        """
+        if not self.lifter.hasContact():
+            # hack fix for falling through the floor:
+            messenger.send("walkerIsOutOfWorld", [self.avatarNodePath])
+
+        self._calcSpeeds()
+            
         if __debug__:
             debugRunning = inputState.isSet("debugRunning")
             if debugRunning:

+ 20 - 0
direct/src/controls/SwimWalker.py

@@ -0,0 +1,20 @@
+from direct.showbase.ShowBaseGlobal import *
+from direct.directnotify import DirectNotifyGlobal
+from direct.controls import NonPhysicsWalker
+
+class SwimWalker(NonPhysicsWalker.NonPhysicsWalker):
+    notify = DirectNotifyGlobal.directNotify.newCategory("SwimWalker")
+
+    def _calcSpeeds(self):
+        # get the button states:
+        forward = inputState.isSet("forward")
+        reverse = inputState.isSet("reverse")
+        turnLeft = inputState.isSet("turnLeft") or inputState.isSet("slideLeft")
+        turnRight = inputState.isSet("turnRight") or inputState.isSet("slideRight")
+        # Determine what the speeds are based on the buttons:
+        self.speed=(forward and self.avatarControlForwardSpeed or
+                    reverse and -self.avatarControlReverseSpeed)
+        self.slideSpeed=0.
+        self.rotationSpeed=(
+            (turnLeft and self.avatarControlRotateSpeed) or
+            (turnRight and -self.avatarControlRotateSpeed))