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):
|
||||
assert(self.debugPrint("useSwimControls()"))
|
||||
self.currentControls.disableAvatarControls()
|
||||
self.currentControls.collisionsOff()
|
||||
self.currentControls = self.swimControls
|
||||
self.currentControls.collisionsOn()
|
||||
if self.isEnabled:
|
||||
self.currentControls.enableAvatarControls()
|
||||
|
||||
@ -138,12 +140,10 @@ class ControlManager:
|
||||
def collisionsOn(self):
|
||||
assert(self.debugPrint("collisionsOn()"))
|
||||
self.currentControls.setCollisionsActive(1)
|
||||
#self.swimControls.collisionsOn()
|
||||
|
||||
def collisionsOff(self):
|
||||
assert(self.debugPrint("collisionsOff()"))
|
||||
self.currentControls.setCollisionsActive(0)
|
||||
#self.swimControls.collisionsOff()
|
||||
|
||||
def enable(self):
|
||||
assert(self.debugPrint("enable()"))
|
||||
@ -155,6 +155,18 @@ class ControlManager:
|
||||
self.isEnabled = 0
|
||||
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):
|
||||
#assert(self.debugPrint("monitor()"))
|
||||
if 1:
|
||||
|
@ -40,7 +40,9 @@ class GravityWalker(DirectObject.DirectObject):
|
||||
self.__standableGround=standableGround
|
||||
self.__hardLandingForce=hardLandingForce
|
||||
|
||||
self.jumping = 0
|
||||
self.mayJump = 1
|
||||
self.jumpDelayTask = None
|
||||
self.falling = 0
|
||||
self.needToDeltaPos = 0
|
||||
self.physVelocityIndicator=None
|
||||
self.avatarControlForwardSpeed=0
|
||||
@ -59,6 +61,12 @@ class GravityWalker(DirectObject.DirectObject):
|
||||
self.isAirborne = 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):
|
||||
assert(self.debugPrint("\n\nspawnTest()\n"))
|
||||
if not self.wantAvatarPhysicsIndicator:
|
||||
@ -239,6 +247,20 @@ class GravityWalker(DirectObject.DirectObject):
|
||||
tempCTrav.addCollider(self.cRayNodePath, self.lifter)
|
||||
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):
|
||||
"""
|
||||
Check on the arrow keys and update the avatar.
|
||||
@ -269,24 +291,26 @@ class GravityWalker(DirectObject.DirectObject):
|
||||
self.rotationSpeed = 0
|
||||
jump = 0
|
||||
|
||||
if 0:
|
||||
if 1:
|
||||
onScreenDebug.add("airborneHeight", self.lifter.getAirborneHeight()) #*#
|
||||
onScreenDebug.add("jumping", self.jumping) #*#
|
||||
onScreenDebug.add("falling", self.falling) #*#
|
||||
onScreenDebug.add("isOnGround", self.lifter.isOnGround()) #*#
|
||||
onScreenDebug.add("velocity", self.lifter.getVelocity()) #*#
|
||||
onScreenDebug.add("jump", jump) #*#
|
||||
if self.lifter.isOnGround():
|
||||
if self.jumping:
|
||||
self.jumping = 0
|
||||
if self.falling:
|
||||
self.falling = 0
|
||||
#messenger.send("jumpHardLand")
|
||||
messenger.send("jumpLand")
|
||||
if jump:
|
||||
self.startJumpDelay()
|
||||
if jump and self.mayJump:
|
||||
# ...the jump button is down and we're close
|
||||
# enough to the ground to jump.
|
||||
self.lifter.addVelocity(self.avatarControlJumpForce)
|
||||
messenger.send("jumpStart")
|
||||
self.jumping = 1
|
||||
#else:
|
||||
self.falling = 1
|
||||
else:
|
||||
self.falling = 1
|
||||
# if self.lifter.getAirborneHeight() > 10000.0:
|
||||
# assert(0)
|
||||
|
||||
@ -341,7 +365,7 @@ class GravityWalker(DirectObject.DirectObject):
|
||||
"""
|
||||
assert(self.debugPrint("enableAvatarControls()"))
|
||||
print id(self), "GW.enableAvatarControls()"
|
||||
self.setCollisionsActive(1)
|
||||
assert self.collisionsActive
|
||||
|
||||
if __debug__:
|
||||
self.accept("control-f3", self.spawnTest) #*#
|
||||
@ -366,8 +390,6 @@ class GravityWalker(DirectObject.DirectObject):
|
||||
taskName = "AvatarControlsIndicator%s"%(id(self),)
|
||||
taskMgr.remove(taskName)
|
||||
|
||||
self.setCollisionsActive(0)
|
||||
|
||||
if __debug__:
|
||||
self.ignore("control-f3") #*#
|
||||
|
||||
|
@ -206,7 +206,7 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
||||
"""
|
||||
assert(self.debugPrint("enableAvatarControls"))
|
||||
print id(self), "NPW.enableAvatarControls()"
|
||||
self.setCollisionsActive(1)
|
||||
assert self.collisionsActive
|
||||
|
||||
taskName = "AvatarControls%s"%(id(self),)
|
||||
# remove any old
|
||||
@ -223,8 +223,6 @@ class NonPhysicsWalker(DirectObject.DirectObject):
|
||||
taskName = "AvatarControls%s"%(id(self),)
|
||||
taskMgr.remove(taskName)
|
||||
|
||||
self.setCollisionsActive(0)
|
||||
|
||||
if __debug__:
|
||||
def debugPrint(self, message):
|
||||
"""for debugging"""
|
||||
|
@ -691,7 +691,7 @@ class PhysicsWalker(DirectObject.DirectObject):
|
||||
"""
|
||||
assert(self.debugPrint("enableAvatarControls()"))
|
||||
print id(self), "PW.enableAvatarControls()"
|
||||
self.setCollisionsActive(1)
|
||||
assert self.collisionsActive
|
||||
|
||||
if __debug__:
|
||||
self.accept("control-f3", self.spawnTest) #*#
|
||||
@ -717,24 +717,10 @@ class PhysicsWalker(DirectObject.DirectObject):
|
||||
taskName = "AvatarControlsIndicator%s"%(id(self),)
|
||||
taskMgr.remove(taskName)
|
||||
|
||||
self.setCollisionsActive(0)
|
||||
|
||||
if __debug__:
|
||||
self.ignore("control-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__:
|
||||
def debugPrint(self, message):
|
||||
|
Loading…
x
Reference in New Issue
Block a user