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


Python pymunk.Vec2d方法代码示例

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


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

示例1: __init__

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def __init__(self, pos, length, height, space, mass=5.0):
        moment = 1000
        body = pm.Body(mass, moment)
        body.position = Vec2d(pos)
        shape = pm.Poly.create_box(body, (length, height))
        shape.color = (0, 0, 255)
        shape.friction = 0.5
        shape.collision_type = 2
        space.add(body, shape)
        self.body = body
        self.shape = shape
        wood = pygame.image.load("../resources/images/wood.png").convert_alpha()
        wood2 = pygame.image.load("../resources/images/wood2.png").convert_alpha()
        rect = pygame.Rect(251, 357, 86, 22)
        self.beam_image = wood.subsurface(rect).copy()
        rect = pygame.Rect(16, 252, 22, 84)
        self.column_image = wood2.subsurface(rect).copy() 
开发者ID:estevaofon,项目名称:angry-birds-python,代码行数:19,代码来源:polygon.py

示例2: __init__

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def __init__(self, distance, angle, x, y, space):
        self.life = 20
        mass = 5
        radius = 12
        inertia = pm.moment_for_circle(mass, 0, radius, (0, 0))
        body = pm.Body(mass, inertia)
        body.position = x, y
        power = distance * 53
        impulse = power * Vec2d(1, 0)
        angle = -angle
        body.apply_impulse_at_local_point(impulse.rotated(angle))
        shape = pm.Circle(body, radius, (0, 0))
        shape.elasticity = 0.95
        shape.friction = 1
        shape.collision_type = 0
        space.add(body, shape)
        self.body = body
        self.shape = shape 
开发者ID:estevaofon,项目名称:angry-birds-python,代码行数:20,代码来源:characters.py

示例3: __init__

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def __init__(self, position, length, height, space, mass=5.0):
        value_moment = 1000
        body_obj = pym.Body(mass, value_moment)
        body_obj.position = Vec2d(position)
        shape_obj = pym.Poly.create_box(body_obj, (length, height))
        shape_obj.color = (0, 0, 255)
        shape_obj.friction = 0.5
        shape_obj.collision_type = 2 #adding to check collision later
        space.add(body_obj, shape_obj)
        self.body = body_obj
        self.shape = shape_obj
        wood_photo = pg.image.load("../res/photos/wood.png").convert_alpha()
        wood2_photo = pg.image.load("../res/photos/wood2.png").convert_alpha()
        rect_wood = pg.Rect(251, 357, 86, 22)
        self.beam_image = wood_photo.subsurface(rect_wood).copy()
        rect_wood2 = pg.Rect(16, 252, 22, 84)
        self.column_image = wood2_photo.subsurface(rect_wood2).copy() 
开发者ID:PacktPublishing,项目名称:Learning-Python-by-building-games,代码行数:19,代码来源:polygon.py

示例4: draw_poly

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def draw_poly(self, element, screen):
        """Draw beams and columns"""
        polygon = self.shape

        if element == 'beams':
            pos = polygon.body.position
            pos = Vec2d(self.convert_to_pygame(pos))
            angle_degrees = math.degrees(polygon.body.angle)
            rotated_beam = pg.transform.rotate(self.beam_image,
                                                       angle_degrees)
            offset = Vec2d(rotated_beam.get_size()) / 2.
            pos = pos - offset
            final_pos = pos
            screen.blit(rotated_beam, (final_pos.x, final_pos.y))
        if element == 'columns':
            pos = polygon.body.position
            pos = Vec2d(self.convert_to_pygame(pos))
            angle_degrees = math.degrees(polygon.body.angle) + 180
            rotated_column = pg.transform.rotate(self.column_image,
                                                       angle_degrees)
            offset = Vec2d(rotated_column.get_size()) / 2.
            pos = pos - offset
            final_pos = pos
            screen.blit(rotated_column, (final_pos.x, final_pos.y)) 
开发者ID:PacktPublishing,项目名称:Learning-Python-by-building-games,代码行数:26,代码来源:polygon.py

示例5: __init__

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def __init__(self, distance, angle, x_pos, y_pos, space):
        weight = 5
        r = 12 #radius
        value_of_inertia = p.moment_for_circle(weight, 0, r, (0, 0))
        obj_body = p.Body(weight, value_of_inertia)
        obj_body.position = x_pos, y_pos
        power_value = distance * 53
        impulse = power_value * Vec2d(1, 0)
        angle = -angle
        obj_body.apply_impulse_at_local_point(impulse.rotated(angle))
        obj_shape = p.Circle(obj_body, r, (0, 0))
        obj_shape.elasticity = 0.95 #bouncing angry bird
        obj_shape.friction = 1 #for roughness
        obj_shape.collision_type = 0 #for checking collisions later
        space.add(obj_body, obj_shape)
        #class RoundBird attribute ----
        self.body = obj_body
        self.shape = obj_shape 
开发者ID:PacktPublishing,项目名称:Learning-Python-by-building-games,代码行数:20,代码来源:characters.py

示例6: _draw

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def _draw(self, screen):
        if self._cosmetic:
            p = (self._x, self._y)
        else:
            p = to_pygame(self.body.position)

        pygame.draw.circle(screen, self.color, p, int(self._radius), 0)

        if self.draw_radius_line:
            if self._cosmetic:
                p2 = (self._x+self._radius, self._y)
            else:
                circle_edge = self.body.position + pymunk.Vec2d(self.shape.radius, 0).rotated(self.body.angle)
                p2 = to_pygame(circle_edge)

            pygame.draw.lines(screen, pygame.Color('black'), False, [p, p2], 1) 
开发者ID:jshaffstall,项目名称:PyPhysicsSandbox,代码行数:18,代码来源:ball_shape.py

示例7: create_cat

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def create_cat(self):
        inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0))
        self.cat_body = pymunk.Body(1, inertia)
        self.cat_body.position = 50, height - 100
        self.cat_shape = pymunk.Circle(self.cat_body, 30)
        self.cat_shape.color = THECOLORS["orange"]
        self.cat_shape.elasticity = 1.0
        self.cat_shape.angle = 0.5
        direction = Vec2d(1, 0).rotated(self.cat_body.angle)
        self.space.add(self.cat_body, self.cat_shape) 
开发者ID:llSourcell,项目名称:Self-Driving-Car-Demo,代码行数:12,代码来源:carmunk.py

示例8: create_car

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def create_car(self, x, y, r):
        inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0))
        self.car_body = pymunk.Body(1, inertia)
        self.car_body.position = x, y
        self.car_shape = pymunk.Circle(self.car_body, 25)
        self.car_shape.color = THECOLORS["green"]
        self.car_shape.elasticity = 1.0
        self.car_body.angle = r
        driving_direction = Vec2d(1, 0).rotated(self.car_body.angle)
        self.car_body.apply_impulse(driving_direction)
        self.space.add(self.car_body, self.car_shape) 
开发者ID:llSourcell,项目名称:Self-Driving-Car-Demo,代码行数:13,代码来源:carmunk.py

示例9: move_obstacles

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def move_obstacles(self):
        # Randomly move obstacles around.
        for obstacle in self.obstacles:
            speed = random.randint(1, 5)
            direction = Vec2d(1, 0).rotated(self.car_body.angle + random.randint(-2, 2))
            obstacle.velocity = speed * direction 
开发者ID:llSourcell,项目名称:Self-Driving-Car-Demo,代码行数:8,代码来源:carmunk.py

示例10: draw_poly

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def draw_poly(self, element, screen):
        """Draw beams and columns"""
        poly = self.shape
        ps = poly.get_vertices()
        ps.append(ps[0])
        ps = map(self.to_pygame, ps)
        ps = list(ps)
        color = (255, 0, 0)
        pygame.draw.lines(screen, color, False, ps)
        if element == 'beams':
            p = poly.body.position
            p = Vec2d(self.to_pygame(p))
            angle_degrees = math.degrees(poly.body.angle) + 180
            rotated_logo_img = pygame.transform.rotate(self.beam_image,
                                                       angle_degrees)
            offset = Vec2d(rotated_logo_img.get_size()) / 2.
            p = p - offset
            np = p
            screen.blit(rotated_logo_img, (np.x, np.y))
        if element == 'columns':
            p = poly.body.position
            p = Vec2d(self.to_pygame(p))
            angle_degrees = math.degrees(poly.body.angle) + 180
            rotated_logo_img = pygame.transform.rotate(self.column_image,
                                                       angle_degrees)
            offset = Vec2d(rotated_logo_img.get_size()) / 2.
            p = p - offset
            np = p
            screen.blit(rotated_logo_img, (np.x, np.y)) 
开发者ID:estevaofon,项目名称:angry-birds-python,代码行数:31,代码来源:polygon.py

示例11: create_car

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def create_car(self, x, y, r):
        inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0))
        self.car_body = pymunk.Body(1, inertia)
        self.car_body.position = x, y
        self.car_shape = pymunk.Circle(self.car_body, 15)
        self.car_shape.color = THECOLORS["green"]
        self.car_shape.elasticity = 1.0
        self.car_body.angle = r
        self.driving_direction = Vec2d(1, 0).rotated(self.car_body.angle)
        self.car_body.apply_impulse(self.driving_direction)
        self.space.add(self.car_body, self.car_shape) 
开发者ID:harvitronix,项目名称:rl-rc-car,代码行数:13,代码来源:carmunk.py

示例12: move_cat

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def move_cat(self):
        speed = random.randint(50, 120)
        self.cat_body.angle -= random.randint(-1, 1)
        direction = Vec2d(1, 0).rotated(self.cat_body.angle)
        self.cat_body.velocity = speed * direction 
开发者ID:harvitronix,项目名称:rl-rc-car,代码行数:7,代码来源:carmunk.py

示例13: position

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def position(self, value):
        position = pymunk.Vec2d(*value)
        delta = position - self.main_body.position
        for obj in self.pymunk_objects:
            try:
                obj.position += delta
            except AttributeError:
                continue 
开发者ID:pygame,项目名称:stuntcat,代码行数:10,代码来源:model.py

示例14: create_car

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def create_car(self, x, y, r):
        inertia = pymunk.moment_for_circle(1, 0, 14, (0, 0))
        self.car_body = pymunk.Body(1, inertia)
        self.car_body.position = x, y
        self.car_shape = pymunk.Circle(self.car_body, r)
        self.car_shape.color = THECOLORS["green"]
        self.car_shape.elasticity = 1.0
        self.car_body.angle = 1.4
        driving_direction = Vec2d(1, 0).rotated(self.car_body.angle)
        self.car_body.apply_impulse(driving_direction)
        self.space.add(self.car_body, self.car_shape) 
开发者ID:jangirrishabh,项目名称:toyCarIRL,代码行数:13,代码来源:carmunk.py

示例15: move_cat

# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Vec2d [as 别名]
def move_cat(self):
        speed = random.randint(20, 200)
        self.cat_body.angle -= random.randint(-1, 1)
        direction = Vec2d(1, 0).rotated(self.cat_body.angle)
        self.cat_body.velocity = speed * direction 
开发者ID:jangirrishabh,项目名称:toyCarIRL,代码行数:7,代码来源:carmunk.py


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