DevWalker
This commit is contained in:
parent
e5def67abb
commit
71a1623c11
|
|
@ -5,6 +5,7 @@ from ShowBaseGlobal import *
|
|||
#from IntervalGlobal import *
|
||||
|
||||
import Avatar
|
||||
import DevWalker
|
||||
import DirectNotifyGlobal
|
||||
import GhostWalker
|
||||
import GravityWalker
|
||||
|
|
@ -26,6 +27,7 @@ class ControlManager:
|
|||
gravity = -32.1740 * 2.0)
|
||||
#self.swimControls=NonPhysicsWalker.NonPhysicsWalker()
|
||||
self.ghostControls=GhostWalker.GhostWalker()
|
||||
self.devControls=DevWalker.DevWalker()
|
||||
if self.wantAvatarPhysics:
|
||||
self.walkControls=GravityWalker.GravityWalker(
|
||||
gravity = -32.1740 * 2.0) # * 2.0 is a hack;
|
||||
|
|
@ -61,6 +63,8 @@ class ControlManager:
|
|||
inputState.watch("jump", "alt-control", "alt-control-up")
|
||||
inputState.watch("jump", "shift-control", "shift-control-up")
|
||||
|
||||
inputState.watch("shift", "shift", "shift-up")
|
||||
|
||||
# FYI, ghost mode uses jump for slide.
|
||||
inputState.watch("slide", "slide-is-disabled", "slide-is-disabled")
|
||||
|
||||
|
|
@ -76,6 +80,7 @@ class ControlManager:
|
|||
#inputState.watch("slideRight", "shift-arrow_right", "shift-arrow_right-up")
|
||||
inputState.watch("slideRight", "slide-is-disabled", "slide-is-disabled")
|
||||
|
||||
|
||||
def add(self, controls, name="basic"):
|
||||
controls = self.controls.get(name)
|
||||
if controls is not None:
|
||||
|
|
@ -93,7 +98,21 @@ class ControlManager:
|
|||
self.currentControls.setCollisionsActive(1)
|
||||
else:
|
||||
print "Unkown controls:", name
|
||||
|
||||
def setSpeeds_new(self, toonForwardSpeed, toonJumpForce,
|
||||
toonReverseSpeed, toonRotateSpeed):
|
||||
assert(self.debugPrint(
|
||||
"setSpeeds(toonForwardSpeed=%s, toonJumpForce=%s, toonReverseSpeed=%s, toonRotateSpeed=%s)"%(
|
||||
toonForwardSpeed, toonJumpForce,
|
||||
toonReverseSpeed, toonRotateSpeed)))
|
||||
for controls in self.controls.values():
|
||||
controls.setWalkSpeed(
|
||||
toonForwardSpeed,
|
||||
toonJumpForce,
|
||||
toonReverseSpeed,
|
||||
toonRotateSpeed)
|
||||
|
||||
|
||||
def useSwimControls(self):
|
||||
assert(self.debugPrint("useSwimControls()"))
|
||||
if self.currentControls is not self.swimControls:
|
||||
|
|
@ -124,6 +143,16 @@ class ControlManager:
|
|||
if self.isEnabled:
|
||||
self.currentControls.enableAvatarControls()
|
||||
|
||||
def useDevControls(self):
|
||||
assert(self.debugPrint("useDevControls()"))
|
||||
if self.currentControls is not self.devControls:
|
||||
self.currentControls.disableAvatarControls()
|
||||
self.currentControls.setCollisionsActive(0)
|
||||
self.devControls.setCollisionsActive(1)
|
||||
self.currentControls = self.devControls
|
||||
if self.isEnabled:
|
||||
self.currentControls.enableAvatarControls()
|
||||
|
||||
def delete(self):
|
||||
self.disable()
|
||||
#self.monitorTask.remove()
|
||||
|
|
@ -149,12 +178,17 @@ class ControlManager:
|
|||
toonJumpForce,
|
||||
toonReverseSpeed,
|
||||
toonRotateSpeed)
|
||||
self.devControls.setWalkSpeed(
|
||||
toonForwardSpeed,
|
||||
toonJumpForce,
|
||||
toonReverseSpeed,
|
||||
toonRotateSpeed)
|
||||
|
||||
def getSpeeds(self):
|
||||
return self.currentControls.getSpeeds()
|
||||
|
||||
def initializeCollisions(self, cTrav,
|
||||
wallBitmask, floorBitmask, ghostBitMask, avatarRadius, floorOffset):
|
||||
wallBitmask, floorBitmask, ghostBitmask, avatarRadius, floorOffset):
|
||||
assert(self.debugPrint("initializeCollisions()"))
|
||||
|
||||
self.walkControls.initializeCollisions(cTrav, self.avatar,
|
||||
|
|
@ -170,10 +204,16 @@ class ControlManager:
|
|||
self.swimControls.setCollisionsActive(0)
|
||||
|
||||
self.ghostControls.initializeCollisions(cTrav, self.avatar,
|
||||
ghostBitMask, floorBitmask, avatarRadius, floorOffset)
|
||||
ghostBitmask, floorBitmask, avatarRadius, floorOffset)
|
||||
self.ghostControls.setAirborneHeightFunc(self.avatar.getAirborneHeight)
|
||||
self.ghostControls.disableAvatarControls()
|
||||
self.ghostControls.setCollisionsActive(0)
|
||||
|
||||
self.devControls.initializeCollisions(cTrav, self.avatar,
|
||||
wallBitmask, floorBitmask, avatarRadius, floorOffset)
|
||||
self.devControls.setAirborneHeightFunc(self.avatar.getAirborneHeight)
|
||||
self.devControls.disableAvatarControls()
|
||||
self.devControls.setCollisionsActive(0)
|
||||
|
||||
self.walkControls.setCollisionsActive(1)
|
||||
self.walkControls.enableAvatarControls()
|
||||
|
|
@ -183,6 +223,7 @@ class ControlManager:
|
|||
self.walkControls.deleteCollisions()
|
||||
self.swimControls.deleteCollisions()
|
||||
self.ghostControls.deleteCollisions()
|
||||
self.devControls.deleteCollisions()
|
||||
|
||||
def collisionsOn(self):
|
||||
assert(self.debugPrint("collisionsOn()"))
|
||||
|
|
|
|||
|
|
@ -135,8 +135,9 @@ class DevWalker(DirectObject.DirectObject):
|
|||
"""
|
||||
assert(self.debugPrint("disableAvatarControls"))
|
||||
print id(self), "DW.disableAvatarControls()"
|
||||
self.task.remove()
|
||||
self.task = None
|
||||
if self.task:
|
||||
self.task.remove()
|
||||
self.task = None
|
||||
|
||||
if __debug__:
|
||||
def debugPrint(self, message):
|
||||
|
|
|
|||
|
|
@ -416,6 +416,10 @@ class GravityWalker(DirectObject.DirectObject):
|
|||
if __debug__:
|
||||
if self.wantDebugIndicator:
|
||||
onScreenDebug.add("velocity", velocity.pPrintValues())
|
||||
|
||||
def reset(self):
|
||||
assert(self.debugPrint("reset()"))
|
||||
self.lifter.setVelocity(0.0)
|
||||
|
||||
def enableAvatarControls(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ class InputState(DirectObject.DirectObject):
|
|||
def set(self, name, isSet):
|
||||
assert(self.debugPrint("set(name=%s, isSet=%s)"%(name, isSet)))
|
||||
self.state[name] = isSet
|
||||
messenger.send(name, [isSet])
|
||||
#*#messenger.send(name, [isSet])
|
||||
|
||||
def isSet(self, name):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -195,6 +195,10 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
|||
else:
|
||||
self.vel.set(0.0, 0.0, 0.0)
|
||||
return Task.cont
|
||||
|
||||
def reset(self):
|
||||
assert(self.debugPrint("reset()"))
|
||||
pass
|
||||
|
||||
def enableAvatarControls(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -401,10 +401,9 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||
|
||||
# hack fix for falling through the floor:
|
||||
if contact==Vec3.zero() and self.avatarNodePath.getZ()<-50.0:
|
||||
# reset:
|
||||
# DCR: don't reset X and Y; allow player to move
|
||||
self.reset()
|
||||
self.avatarNodePath.setZ(50.0)
|
||||
self.resetPhys()
|
||||
|
||||
# get the button states:
|
||||
forward = inputState.isSet("forward")
|
||||
|
|
@ -664,8 +663,8 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||
if self.wantAvatarPhysicsIndicator:
|
||||
onScreenDebug.add("velocity", velocity.pPrintValues())
|
||||
|
||||
def resetPhys(self):
|
||||
assert(self.debugPrint("resetPhys()"))
|
||||
def reset(self):
|
||||
assert(self.debugPrint("reset()"))
|
||||
self.actorNode.getPhysicsObject().resetPosition(self.avatarNodePath.getPos())
|
||||
self.priorParent.setVector(Vec3.zero())
|
||||
self.highMark = 0
|
||||
|
|
@ -687,7 +686,7 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||
|
||||
if __debug__:
|
||||
self.accept("control-f3", self.spawnTest) #*#
|
||||
self.accept("f3", self.resetPhys) # for debugging only.
|
||||
self.accept("f3", self.reset) # for debugging only.
|
||||
|
||||
taskName = "AvatarControls%s"%(id(self),)
|
||||
# remove any old
|
||||
|
|
|
|||
Loading…
Reference in New Issue