strafe left and right support

This commit is contained in:
Joe Shochet 2005-10-05 21:58:22 +00:00
parent dc8916d350
commit 71f3a958a1
3 changed files with 190 additions and 105 deletions

View File

@ -19,15 +19,101 @@ class BattleWalker(GravityWalker.GravityWalker):
self.advanceSpeed = 0 self.advanceSpeed = 0
def getSpeeds(self): def getSpeeds(self):
#assert(self.debugPrint("getSpeeds()"))
return (self.speed, self.rotationSpeed, self.slideSpeed, self.advanceSpeed) return (self.speed, self.rotationSpeed, self.slideSpeed, self.advanceSpeed)
def handleAvatarControls(self, task): def handleAvatarControls(self, task):
""" """
Check on the arrow keys and update the avatar. Check on the arrow keys and update the avatar.
""" """
# get the button states:
run = inputState.isSet("run")
forward = inputState.isSet("forward")
reverse = inputState.isSet("reverse")
turnLeft = inputState.isSet("turnLeft")
turnRight = inputState.isSet("turnRight")
slideLeft = inputState.isSet("slideLeft")
slideRight = inputState.isSet("slideRight")
jump = inputState.isSet("jump")
# Determine what the speeds are based on the buttons:
self.speed=(forward and self.avatarControlForwardSpeed or
reverse and -self.avatarControlReverseSpeed)
# Use reverse speed for strafe - that should be about what you want
self.slideSpeed=(slideLeft and -self.avatarControlReverseSpeed or
slideRight and self.avatarControlReverseSpeed)
self.rotationSpeed=not (slideLeft or slideRight) and (
(turnLeft and self.avatarControlRotateSpeed) or
(turnRight and -self.avatarControlRotateSpeed))
if __debug__:
debugRunning = inputState.isSet("debugRunning")
if debugRunning:
self.speed*=4.0
self.slideSpeed*=4.0
self.rotationSpeed*=1.25
if self.needToDeltaPos:
self.setPriorParentVector()
self.needToDeltaPos = 0
if self.wantDebugIndicator:
self.displayDebugInfo()
if self.lifter.isOnGround():
if self.isAirborne:
self.isAirborne = 0
assert(self.debugPrint("isAirborne 0 due to isOnGround() true"))
impact = self.lifter.getImpactVelocity()
if impact < -30.0:
messenger.send("jumpHardLand")
self.startJumpDelay(0.3)
else:
messenger.send("jumpLand")
if impact < -5.0:
self.startJumpDelay(0.2)
# else, ignore the little potholes.
assert(self.isAirborne == 0)
self.priorParent = Vec3.zero()
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.isAirborne = 1
assert(self.debugPrint("isAirborne 1 due to jump"))
else:
if self.isAirborne == 0:
assert(self.debugPrint("isAirborne 1 due to isOnGround() false"))
self.isAirborne = 1
self.__oldPosDelta = self.avatarNodePath.getPosDelta(render)
# How far did we move based on the amount of time elapsed?
self.__oldDt = ClockObject.getGlobalClock().getDt()
dt=self.__oldDt
# Check to see if we're moving at all:
self.moving = self.speed or self.slideSpeed or self.rotationSpeed or (self.priorParent!=Vec3.zero())
if self.moving:
distance = dt * self.speed
slideDistance = dt * self.slideSpeed
rotation = dt * self.rotationSpeed
# Take a step in the direction of our previous heading.
self.vel=Vec3(Vec3.forward() * distance +
Vec3.right() * slideDistance)
if self.vel != Vec3.zero() or self.priorParent != Vec3.zero():
# rotMat is the rotation matrix corresponding to
# our previous heading.
rotMat=Mat3.rotateMatNormaxis(self.avatarNodePath.getH(), Vec3.up())
step=(self.priorParent * dt) + rotMat.xform(self.vel)
self.avatarNodePath.setFluidPos(Point3(
self.avatarNodePath.getPos()+step))
self.avatarNodePath.setH(self.avatarNodePath.getH()+rotation)
else:
self.vel.set(0.0, 0.0, 0.0)
if self.moving or jump:
messenger.send("avatarMoving")
return Task.cont
if 0:
def handleAvatarControls(self, task):
# If targetNp is not available, revert back to GravityWalker.handleAvatarControls. # If targetNp is not available, revert back to GravityWalker.handleAvatarControls.
# This situation occurs when the target dies, but we aren't switched out of # This situation occurs when the target dies, but we aren't switched out of
# battle walker control mode. # battle walker control mode.

View File

@ -72,6 +72,7 @@ class ControlManager:
inputState.watch("jump", "control", "control-up") inputState.watch("jump", "control", "control-up")
if __dev__:
inputState.watch("slideLeft", "home", "home-up") inputState.watch("slideLeft", "home", "home-up")
inputState.watch("slideRight", "end", "end-up") inputState.watch("slideRight", "end", "end-up")
inputState.watch("levitateUp", "page_up", "page_up-up") inputState.watch("levitateUp", "page_up", "page_up-up")

View File

@ -165,7 +165,7 @@ class GravityWalker(DirectObject.DirectObject):
def getSpeeds(self): def getSpeeds(self):
#assert(self.debugPrint("getSpeeds()")) #assert(self.debugPrint("getSpeeds()"))
return (self.speed, self.rotationSpeed) return (self.speed, self.rotationSpeed, self.slideSpeed)
def setAvatar(self, avatar): def setAvatar(self, avatar):
self.avatar = avatar self.avatar = avatar
@ -448,18 +448,16 @@ class GravityWalker(DirectObject.DirectObject):
reverse = inputState.isSet("reverse") reverse = inputState.isSet("reverse")
turnLeft = inputState.isSet("turnLeft") turnLeft = inputState.isSet("turnLeft")
turnRight = inputState.isSet("turnRight") turnRight = inputState.isSet("turnRight")
slide = 0 #hack -- was: inputState.isSet("slide") slideLeft = inputState.isSet("slideLeft")
slideRight = inputState.isSet("slideRight")
jump = inputState.isSet("jump") jump = inputState.isSet("jump")
# Determine what the speeds are based on the buttons: # Determine what the speeds are based on the buttons:
self.speed=(forward and self.avatarControlForwardSpeed or self.speed=(forward and self.avatarControlForwardSpeed or
reverse and -self.avatarControlReverseSpeed) reverse and -self.avatarControlReverseSpeed)
#if run and self.speed>0.0: # Use reverse speed for strafe - that should be about what you want
# self.speed*=2.0 #*# self.slideSpeed=(slideLeft and -self.avatarControlReverseSpeed or
# Should fSlide be renamed slideButton? slideRight and self.avatarControlReverseSpeed)
self.slideSpeed=slide and ( self.rotationSpeed=not (slideLeft or slideRight) and (
(turnLeft and -self.avatarControlForwardSpeed) or
(turnRight and self.avatarControlForwardSpeed))
self.rotationSpeed=not slide and (
(turnLeft and self.avatarControlRotateSpeed) or (turnLeft and self.avatarControlRotateSpeed) or
(turnRight and -self.avatarControlRotateSpeed)) (turnRight and -self.avatarControlRotateSpeed))