mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
added jump delay; moved jump enable code
This commit is contained in:
parent
875d17c52a
commit
b4041cd018
@ -75,7 +75,9 @@ class ControlManager:
|
|||||||
def useSwimControls(self):
|
def useSwimControls(self):
|
||||||
assert(self.debugPrint("useSwimControls()"))
|
assert(self.debugPrint("useSwimControls()"))
|
||||||
self.currentControls.disableAvatarControls()
|
self.currentControls.disableAvatarControls()
|
||||||
|
self.currentControls.collisionsOff()
|
||||||
self.currentControls = self.swimControls
|
self.currentControls = self.swimControls
|
||||||
|
self.currentControls.collisionsOn()
|
||||||
if self.isEnabled:
|
if self.isEnabled:
|
||||||
self.currentControls.enableAvatarControls()
|
self.currentControls.enableAvatarControls()
|
||||||
|
|
||||||
@ -138,12 +140,10 @@ class ControlManager:
|
|||||||
def collisionsOn(self):
|
def collisionsOn(self):
|
||||||
assert(self.debugPrint("collisionsOn()"))
|
assert(self.debugPrint("collisionsOn()"))
|
||||||
self.currentControls.setCollisionsActive(1)
|
self.currentControls.setCollisionsActive(1)
|
||||||
#self.swimControls.collisionsOn()
|
|
||||||
|
|
||||||
def collisionsOff(self):
|
def collisionsOff(self):
|
||||||
assert(self.debugPrint("collisionsOff()"))
|
assert(self.debugPrint("collisionsOff()"))
|
||||||
self.currentControls.setCollisionsActive(0)
|
self.currentControls.setCollisionsActive(0)
|
||||||
#self.swimControls.collisionsOff()
|
|
||||||
|
|
||||||
def enable(self):
|
def enable(self):
|
||||||
assert(self.debugPrint("enable()"))
|
assert(self.debugPrint("enable()"))
|
||||||
@ -154,6 +154,18 @@ class ControlManager:
|
|||||||
assert(self.debugPrint("disable()"))
|
assert(self.debugPrint("disable()"))
|
||||||
self.isEnabled = 0
|
self.isEnabled = 0
|
||||||
self.currentControls.disableAvatarControls()
|
self.currentControls.disableAvatarControls()
|
||||||
|
|
||||||
|
def enableAvatarJump(self):
|
||||||
|
"""
|
||||||
|
Stop forcing the ctrl key to return 0's
|
||||||
|
"""
|
||||||
|
inputState.unforce("jump")
|
||||||
|
|
||||||
|
def disableAvatarJump(self):
|
||||||
|
"""
|
||||||
|
Force the ctrl key to return 0's
|
||||||
|
"""
|
||||||
|
inputState.force("jump", 0)
|
||||||
|
|
||||||
def monitor(self, foo):
|
def monitor(self, foo):
|
||||||
#assert(self.debugPrint("monitor()"))
|
#assert(self.debugPrint("monitor()"))
|
||||||
|
@ -40,7 +40,9 @@ class GravityWalker(DirectObject.DirectObject):
|
|||||||
self.__standableGround=standableGround
|
self.__standableGround=standableGround
|
||||||
self.__hardLandingForce=hardLandingForce
|
self.__hardLandingForce=hardLandingForce
|
||||||
|
|
||||||
self.jumping = 0
|
self.mayJump = 1
|
||||||
|
self.jumpDelayTask = None
|
||||||
|
self.falling = 0
|
||||||
self.needToDeltaPos = 0
|
self.needToDeltaPos = 0
|
||||||
self.physVelocityIndicator=None
|
self.physVelocityIndicator=None
|
||||||
self.avatarControlForwardSpeed=0
|
self.avatarControlForwardSpeed=0
|
||||||
@ -59,6 +61,12 @@ class GravityWalker(DirectObject.DirectObject):
|
|||||||
self.isAirborne = 0
|
self.isAirborne = 0
|
||||||
self.highMark = 0
|
self.highMark = 0
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
if self.doLaterTask is not None:
|
||||||
|
self.doLaterTask.remove()
|
||||||
|
del self.doLaterTask
|
||||||
|
#DirectObject.DirectObject.delete(self)
|
||||||
|
|
||||||
def spawnTest(self):
|
def spawnTest(self):
|
||||||
assert(self.debugPrint("\n\nspawnTest()\n"))
|
assert(self.debugPrint("\n\nspawnTest()\n"))
|
||||||
if not self.wantAvatarPhysicsIndicator:
|
if not self.wantAvatarPhysicsIndicator:
|
||||||
@ -238,6 +246,20 @@ class GravityWalker(DirectObject.DirectObject):
|
|||||||
tempCTrav.addCollider(self.cSphereNodePath, self.pusher)
|
tempCTrav.addCollider(self.cSphereNodePath, self.pusher)
|
||||||
tempCTrav.addCollider(self.cRayNodePath, self.lifter)
|
tempCTrav.addCollider(self.cRayNodePath, self.lifter)
|
||||||
tempCTrav.traverse(render)
|
tempCTrav.traverse(render)
|
||||||
|
|
||||||
|
def setMayJump(self, task):
|
||||||
|
self.mayJump = 1
|
||||||
|
return Task.done
|
||||||
|
|
||||||
|
def startJumpDelay(self):
|
||||||
|
assert(self.debugPrint("startJumpDelay()"))
|
||||||
|
if self.jumpDelayTask:
|
||||||
|
self.jumpDelayTask.remove()
|
||||||
|
self.mayJump = 0
|
||||||
|
self.jumpDelayTask=taskMgr.doMethodLater(
|
||||||
|
0.1,
|
||||||
|
self.setMayJump,
|
||||||
|
"jumpDelay-%s"%id(self))
|
||||||
|
|
||||||
def handleAvatarControls(self, task):
|
def handleAvatarControls(self, task):
|
||||||
"""
|
"""
|
||||||
@ -269,24 +291,26 @@ class GravityWalker(DirectObject.DirectObject):
|
|||||||
self.rotationSpeed = 0
|
self.rotationSpeed = 0
|
||||||
jump = 0
|
jump = 0
|
||||||
|
|
||||||
if 0:
|
if 1:
|
||||||
onScreenDebug.add("airborneHeight", self.lifter.getAirborneHeight()) #*#
|
onScreenDebug.add("airborneHeight", self.lifter.getAirborneHeight()) #*#
|
||||||
onScreenDebug.add("jumping", self.jumping) #*#
|
onScreenDebug.add("falling", self.falling) #*#
|
||||||
onScreenDebug.add("isOnGround", self.lifter.isOnGround()) #*#
|
onScreenDebug.add("isOnGround", self.lifter.isOnGround()) #*#
|
||||||
onScreenDebug.add("velocity", self.lifter.getVelocity()) #*#
|
onScreenDebug.add("velocity", self.lifter.getVelocity()) #*#
|
||||||
onScreenDebug.add("jump", jump) #*#
|
onScreenDebug.add("jump", jump) #*#
|
||||||
if self.lifter.isOnGround():
|
if self.lifter.isOnGround():
|
||||||
if self.jumping:
|
if self.falling:
|
||||||
self.jumping = 0
|
self.falling = 0
|
||||||
#messenger.send("jumpHardLand")
|
#messenger.send("jumpHardLand")
|
||||||
messenger.send("jumpLand")
|
messenger.send("jumpLand")
|
||||||
if jump:
|
self.startJumpDelay()
|
||||||
|
if jump and self.mayJump:
|
||||||
# ...the jump button is down and we're close
|
# ...the jump button is down and we're close
|
||||||
# enough to the ground to jump.
|
# enough to the ground to jump.
|
||||||
self.lifter.addVelocity(self.avatarControlJumpForce)
|
self.lifter.addVelocity(self.avatarControlJumpForce)
|
||||||
messenger.send("jumpStart")
|
messenger.send("jumpStart")
|
||||||
self.jumping = 1
|
self.falling = 1
|
||||||
#else:
|
else:
|
||||||
|
self.falling = 1
|
||||||
# if self.lifter.getAirborneHeight() > 10000.0:
|
# if self.lifter.getAirborneHeight() > 10000.0:
|
||||||
# assert(0)
|
# assert(0)
|
||||||
|
|
||||||
@ -341,7 +365,7 @@ class GravityWalker(DirectObject.DirectObject):
|
|||||||
"""
|
"""
|
||||||
assert(self.debugPrint("enableAvatarControls()"))
|
assert(self.debugPrint("enableAvatarControls()"))
|
||||||
print id(self), "GW.enableAvatarControls()"
|
print id(self), "GW.enableAvatarControls()"
|
||||||
self.setCollisionsActive(1)
|
assert self.collisionsActive
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self.accept("control-f3", self.spawnTest) #*#
|
self.accept("control-f3", self.spawnTest) #*#
|
||||||
@ -365,8 +389,6 @@ class GravityWalker(DirectObject.DirectObject):
|
|||||||
|
|
||||||
taskName = "AvatarControlsIndicator%s"%(id(self),)
|
taskName = "AvatarControlsIndicator%s"%(id(self),)
|
||||||
taskMgr.remove(taskName)
|
taskMgr.remove(taskName)
|
||||||
|
|
||||||
self.setCollisionsActive(0)
|
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self.ignore("control-f3") #*#
|
self.ignore("control-f3") #*#
|
||||||
|
@ -206,7 +206,7 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
|||||||
"""
|
"""
|
||||||
assert(self.debugPrint("enableAvatarControls"))
|
assert(self.debugPrint("enableAvatarControls"))
|
||||||
print id(self), "NPW.enableAvatarControls()"
|
print id(self), "NPW.enableAvatarControls()"
|
||||||
self.setCollisionsActive(1)
|
assert self.collisionsActive
|
||||||
|
|
||||||
taskName = "AvatarControls%s"%(id(self),)
|
taskName = "AvatarControls%s"%(id(self),)
|
||||||
# remove any old
|
# remove any old
|
||||||
@ -222,8 +222,6 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
|||||||
print id(self), "NPW.disableAvatarControls()"
|
print id(self), "NPW.disableAvatarControls()"
|
||||||
taskName = "AvatarControls%s"%(id(self),)
|
taskName = "AvatarControls%s"%(id(self),)
|
||||||
taskMgr.remove(taskName)
|
taskMgr.remove(taskName)
|
||||||
|
|
||||||
self.setCollisionsActive(0)
|
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
def debugPrint(self, message):
|
def debugPrint(self, message):
|
||||||
|
@ -691,7 +691,7 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
"""
|
"""
|
||||||
assert(self.debugPrint("enableAvatarControls()"))
|
assert(self.debugPrint("enableAvatarControls()"))
|
||||||
print id(self), "PW.enableAvatarControls()"
|
print id(self), "PW.enableAvatarControls()"
|
||||||
self.setCollisionsActive(1)
|
assert self.collisionsActive
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self.accept("control-f3", self.spawnTest) #*#
|
self.accept("control-f3", self.spawnTest) #*#
|
||||||
@ -716,25 +716,11 @@ class PhysicsWalker(DirectObject.DirectObject):
|
|||||||
|
|
||||||
taskName = "AvatarControlsIndicator%s"%(id(self),)
|
taskName = "AvatarControlsIndicator%s"%(id(self),)
|
||||||
taskMgr.remove(taskName)
|
taskMgr.remove(taskName)
|
||||||
|
|
||||||
self.setCollisionsActive(0)
|
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self.ignore("control-f3") #*#
|
self.ignore("control-f3") #*#
|
||||||
self.ignore("f3")
|
self.ignore("f3")
|
||||||
|
|
||||||
def enableAvatarJump(self):
|
|
||||||
"""
|
|
||||||
Stop forcing the ctrl key to return 0's
|
|
||||||
"""
|
|
||||||
inputState.unforce("jump")
|
|
||||||
|
|
||||||
def disableAvatarJump(self):
|
|
||||||
"""
|
|
||||||
Force the ctrl key to return 0's
|
|
||||||
"""
|
|
||||||
inputState.force("jump", 0)
|
|
||||||
|
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
def debugPrint(self, message):
|
def debugPrint(self, message):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user