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


Python Vector.normalise方法代码示例

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


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

示例1: GameEntity

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

#.........这里部分代码省略.........
            
            antialias = 1
            red = 255,0,0

            for line in lines:
                  text = font.render(line.strip(), antialias, red)
                  
                  text_pos = text.get_rect()

                  center_image_x = text_pos.width/2
                  center_image_y = text_pos.height/2
                  w, h = center
                  center = ((w - center_image_x),(h - center_image_y))
                  
                  text_pos = center 

                  height = font.get_linesize()
                  surface.blit(text, text_pos)
                  
                  new_y = self.location.get_y() + height
                  center = (self.location.get_x(), new_y)
                  

            pygame.display.flip()

      def process(self, time_passed):
            """Function that plots a new course.

            Function that determines whether or not the entity can move,
            if the enity can move then a new course is plotted based
            on its current location, and its destination

            vec_to_destination: holds a vector object that determines how to get
            from the current location to a destination location e.g. A (1,1) B(10,10)
            vec_to_des(9,9)

            distance_to_destination: holds the distance between two points. Should
            be a numeric value

            heading: holds the heading/direction that leads to the destination, Created
            by normalising the vec_to_destination. vect_to_destination / magnitude, giving it
            a magnitude of 1, which provides a heading

            travel_speed: holds the speed the entity should travel based on its given speed and
            the amount of time that has passed

            position: holds the current position of the entity based on its heading
            and its travel speed.
            """
            
            
            self.brain.think()

            if self.speed > 0 and self.location != self.destination:

                vec_to_destination = self.destination - self.location
                distance_to_destination = vec_to_destination.get_magnitude()
                self.heading = vec_to_destination
                self.heading.normalise()
                travel_speed = min(distance_to_destination, time_passed * self.speed)
                position = self.heading * travel_speed 
                self.location += position

      def rotate_image(self):
            """This function is used to rotate the entity image depending on its heading.
            """

            if self.heading.get_x() == 0 and self.heading.get_y() == 0: #or self.heading.compare_to(self.last_heading) == True:
                  self.heading = self.last_heading

            if self.heading.get_x() >=0 and self.heading.get_y() <=0:
                  value = math.degrees(math.acos(self.heading.get_x()))
                  self.image = self.start_image
                  self.image = pygame.transform.rotate(self.image, value)
                  self.last_heading = self.heading
                  return

            elif self.heading.get_x() <=0 and self.heading.get_y() <=0:
                  value = math.degrees(math.acos(self.heading.get_x()))
                  self.image = self.start_image
                  self.image = pygame.transform.rotate(self.image, value)
                  self.last_heading = self.heading
                  return

            elif self.heading.get_x() <=0 and self.heading.get_y() >=0 :
                  value = 180 + math.degrees(math.asin(self.heading.get_y()))
                  self.image = self.start_image
                  self.image = pygame.transform.rotate(self.image, value)
                  self.last_heading = self.heading
                  return

            elif self.heading.get_x() >=0 and self.heading.get_y() >=0:
                  value = 360 - math.degrees(math.asin(self.heading.get_y()))
                  self.image = self.start_image
                  self.image = pygame.transform.rotate(self.image, value)
                  self.last_heading = self.heading
                  return

      def handle_click(self, event):
            return
开发者ID:Mecharyry,项目名称:PythonGame,代码行数:104,代码来源:Entities.py


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