Ejemplo n.º 1
0
    def handleKeyboardEvent(self, task):
        keys = self.keys

        dt = globalClock.getDt()
        impulse = Vec3(0, 0, 0)
        increment = self._impulseIncrement * dt

        above_limit = self.is_above_limit

        for key, vec in (("left", Vec3.left()), ("right", Vec3.right()),
                         ("up", Vec3.forward()), ("down", Vec3.back())):
            if keys[key] and (not above_limit or self.is_braking(vec)):
                impulse += vec * increment

        self.addImpulse(impulse)

        # If Equismo was not hit by an enemy look at the movement direction.
        # Otherwise look at the enemy until Equismo turns around.
        if not self._hit:
            self.face(self.velocity)

        elif ((impulse.length() > 0) and (self.velocity.length() > 0.5)
              and (not self.is_braking(impulse))):
            self._hit = False

        self.doWalkAnimation(impulse)

        return task.cont
Ejemplo n.º 2
0
 def handleKeyboardEvent(self, task):
     keys = self.keys
     
     dt = globalClock.getDt()
     impulse = Vec3(0, 0, 0)
     increment = self._impulseIncrement * dt
     
     above_limit = self.is_above_limit
     
     for key, vec in (("left", Vec3.left()),
                      ("right", Vec3.right()),
                      ("up", Vec3.forward()),
                      ("down", Vec3.back())):
         if keys[key] and (not above_limit or self.is_braking(vec)):
             impulse += vec * increment
     
     self.addImpulse(impulse)
     
     # If Equismo was not hit by an enemy look at the movement direction.
     # Otherwise look at the enemy until Equismo turns around.
     if not self._hit:
         self.face(self.velocity)
     
     elif ((impulse.length() > 0) and
           (self.velocity.length() > 0.5) and
           (not self.is_braking(impulse))):
                 self._hit = False
     
     self.doWalkAnimation(impulse)
     
     return task.cont
Ejemplo n.º 3
0
    def moveLeft(self):
        vp = base.viewportMgr.activeViewport
        if not vp or not vp.is2D():
            return

        self.updatePos(self.pos + self.getMoveDelta(Vec3.left(), vp))