当前位置: 首页>>代码示例>>Python>>正文


Python Vector.truncate方法代码示例

本文整理汇总了Python中Vector.Vector.truncate方法的典型用法代码示例。如果您正苦于以下问题:Python Vector.truncate方法的具体用法?Python Vector.truncate怎么用?Python Vector.truncate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Vector.Vector的用法示例。


在下文中一共展示了Vector.truncate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: resolve

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import truncate [as 别名]
 def resolve(self):
     """
     Return combined result of all steering behaviours.
     """
     acc=Vector(0,0)
     #if type(self.player.state) == Player.RxAttack:
     #    pdb.set_trace()
     if self._avoid_defenders_on:
         acc += self.avoid_defenders() * self.w_avoid_defenders
     if self._seek_on:
         acc += self.seek() * self.w_seek
     if self._seek_end_zone_on:
         acc += self.seek_end_zone() * self.w_seek_end_zone
     if self._avoid_walls_on:
         acc += self.avoid_walls() * self.w_avoid_walls
     if self._pursue_on:
         acc += self.pursue() * self.w_pursue
     if self._block_on:
         acc += self.block() * self.w_block
     if self._avoid_friends_on:
         acc += self.avoid_friends() * self.w_avoid_friends
     if self._zone_defend_on:
         acc += self.zone_defend() * self.w_zone_defend
     if self._guard_on:
         acc += self.guard() * self.w_guard
     if self._stay_in_range_on:
         acc += self.stay_in_range() * self.w_stay_in_range
     if self._avoid_end_zone_on:
         acc += self.avoid_end_zone() * self.w_avoid_end_zone
     if self._arrive_at_speed_on:
         acc += self.arrive_at_speed() * self.w_arrive_at_speed
     return acc.truncate(self.player.top_acc)
开发者ID:Bogdanovist,项目名称:smash2,代码行数:34,代码来源:Steering.py

示例2: Player

# 需要导入模块: from Vector import Vector [as 别名]
# 或者: from Vector.Vector import truncate [as 别名]

#.........这里部分代码省略.........
        return (self.x - self.defend_end_zone_x)*self.team.direction

    @property
    def opposite_team(self):
        return self.team.opposite_team

    @property
    def direction(self):
        return self.team.direction    

    @property
    def has_ball(self):
        return self.pitch.ball.carrier == self

    @property
    def in_contact(self):
        return self in self.pitch.contacts.keys()

    @property
    def team_name(self):
        if self.team.direction > 0:
            return('home')
        else:
            return('away')

    @property
    def team_in_possession(self):
        return self.team.in_possession

    def x_from_defend_end_zone(self,x):
        if self.team.direction > 0:
            return x
        else:
            return self.pitch.xsize-x  

    def move(self):

        # NOTE: Ignores mass! (assumes m=1 I guess)
        # Don't move if we are prone
        if not self.standing:
            # Prone players might still be moving, but they rapidly deccelerate!
            # Magic numbers
            prone_acc = 20.
            prone_top_speed = 5.
            desired_acc = self.vel.norm() * prone_acc * self.pitch.dt * -1.
            if self.vel.mag() < desired_acc.mag():
                self.vel=Vector(0,0)
            else:
                self.vel += desired_acc
                self.vel = self.vel.truncate(prone_top_speed)
                self.pos += self.vel * self.pitch.dt
            return
        elif self.in_contact:
            # Push resolved seperately
            return
        acc = self.current_acc()
        # Check current puff reduced acc
        # NOTE HACK: Current states consider current vel in providing desired acc
        # We undo this so that they return the actual desired velocity
        state_vel = self.move_state.execute()
        desired_vel = state_vel + self.vel 
        drag_limited_acc = acc * (1. - desired_vel.angle_factor(self.vel) * self.vel.mag() / self.top_speed)
        desired_acc = (desired_vel - self.vel).truncate(drag_limited_acc)
        self.vel += desired_acc * self.pitch.dt
        self.vel = self.vel.truncate(self.top_speed)
        self.pos += self.vel * self.pitch.dt
        # It costs puff to move
        self.puff -= desired_acc.mag() * self.pitch.dt * self.pitch.puff_fac

    def push(self):
        if not self.in_contact: return
        # NOTE: Pushing forwards always, but we don't always want to do that. Need to have hook
        # into state and define in states the push directions ( a parrallel steering behaviours).
        
    def current_acc(self):
        " Current puff reduced max accel."
        cut_in=0.5
        ability_floor=0.5
        #NOTE: Turned off for now to allow easier state debugging
        return self.top_acc
        # Reduce ability linearily after cut in, down to floor
        ratio = self.puff/self.stamina
        if ratio < cut_in:
            fac = ratio*(1.-ability_floor)/cut_in + ability_floor
        else:
            fac = 1.
        return fac*self.top_acc

    def standup(self):
        """
        Check if player is prone and if so whether they can stand yet.
        """
        # Done via property now (but is it working?)
        #if self.prone > 0.:
        self.prone -= self.pitch.dt
        #    if self.prone <= 0.:
        #        self.standing=True
    
    def drop_ball(self):
        self.send(self.pitch.ball,'ball_loose')
开发者ID:Bogdanovist,项目名称:smash2,代码行数:104,代码来源:Player.py


注:本文中的Vector.Vector.truncate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。