Beispiel #1
0
 def do_move_body(self):
     map = self.manager.map
     bpos = self.angle_to_pos(0)
     if not bpos in self.manager.bodies:
         return
     body = self.manager.bodies[bpos]
     if not body.check_poses(bpos, self.actor_angle):
         return
     body.hide() # should be faster than pick-up animation
     actor = self.actor
     anim = actor.getAnimControl('anim')
     interval = actor.actorInterval(
         'anim',
         playRate=S.ch_anim['pick_up_speed'],
         startFrame=S.ch_anim['pick_up_range'][0],
         endFrame=S.ch_anim['pick_up_range'][1]
     )
     yield interval
     body.bind(self)
     while not self.must_die and self.captured_body:
         val = yield events(self.must_die_event, self.release_body_event,
                                             self.continue_move_body_event)
         if val != self.continue_move_body_event:
             break
         yield wait(.05)
         sp = float(S.player['body_moving_speed'])
         anim.setPlayRate(sp / 2)
         wr = S.pl_anim['body_moving_range']
         anim.loop(True, wr[0], wr[1])
         while not self.must_die and self.captured_body:
             ok = yield self._body_moving_step(body)
             if type(ok) is bool and not ok:
                 break
         anim.pose(S.player['body_captured_frame'])
     yield body.hide(False)
     body.unbind()
Beispiel #2
0
 def do_jump(self):
     map = self.manager.map
     pred = lambda pos: 'jump' in map[pos]['actions']
     field = deque(map.get_jump_field(self.pos))
     if not field:
         return
     pointer = loader.loadModel(S.model('plane'))
     texture = loader.loadTexture(
                 S.texture(S.player['pointer_texture']))
     pointer.setTexture(texture)
     pointer.setTransparency(True)
     pointer.setHpr(0, -90, 0)
     pointer.reparentTo(self.manager.main_node)
     while True:
         pos = field[0]
         pointer.setPos(pos[0], pos[1], 0.1)
         finish_event = S.control_keys['jump'] + '-up'
         left_key = S.control_keys['move_left']
         right_key = S.control_keys['move_right']
         val = yield events(left_key, left_key + '-repeat',
                            right_key, right_key + '-repeat',
                            finish_event, self.must_die_event)
         if val in (self.must_die_event, finish_event):
             break
         elif val in (left_key, left_key + '-repeat'):
             field.rotate(1)
         elif val in (right_key, right_key + '-repeat'):
             field.rotate(-1)
         else:
             raise Exception('Unknown event "{}"'.format(val))
     self.set_move_handlers()
     pointer.removeNode()
     if self.must_die:
         return
     actor = self.actor
     sp = float(self.speed)
     v = pos[0] - self.pos[0], pos[1] - self.pos[1]
     dist = float(hypot(v[0], v[1]))
     angle = (degrees(atan2(v[1], v[0])) + 90) % 360
     anim = actor.getAnimControl('anim')
     anim.setPlayRate(sp / 2)
     wr = S.ch_anim['walk_range']
     anim.loop(True, wr[0], wr[1])
     yield self._rotate_to(angle=angle)
     if not self.walk_pred(pos):
         actor.pose('anim', self.idle_frame)
         return
     map.block(pos)
     wr = S.pl_anim['pre_jump_range']
     interval = actor.actorInterval(
         'anim',
         playRate=S.pl_anim['pre_jump_speed'],
         startFrame=wr[0], endFrame=wr[1]
     )
     yield interval
     interval = ProjectileInterval(actor, (0, 0, 0),
                 (0, 0, 0), 1, gravityMult=S.player['jump_height'])
     interval.start()
     mid_pos = (float(self.pos[0] + pos[0]) / 2,
                float(self.pos[1] + pos[1]) / 2)
     interval = LerpPosInterval(self.node, 0.5, mid_pos + (0,))
     yield interval
     self.pos = pos
     map.unblock(self.pos)
     interval = LerpPosInterval(self.node, 0.5, pos + (0,))
     yield interval
     wr = S.pl_anim['post_jump_range']
     interval = actor.actorInterval(
         'anim',
         playRate=S.pl_anim['post_jump_speed'],
         startFrame=wr[0], endFrame=wr[1]
     )
     yield interval
     yield wait(0.1)
     actor.pose('anim', self.idle_frame)