本文整理汇总了Python中pymunk.Body方法的典型用法代码示例。如果您正苦于以下问题:Python pymunk.Body方法的具体用法?Python pymunk.Body怎么用?Python pymunk.Body使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymunk
的用法示例。
在下文中一共展示了pymunk.Body方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [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()
示例2: __init__
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [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
示例3: add_ball
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [as 别名]
def add_ball(space):
mass = 0.01
radius = 3
inertia = pymunk.moment_for_circle(mass, 0, radius, (0,0))
x = random.randint(181,182)
body = pymunk.Body(mass, inertia)
body._bodycontents.v_limit = 120
body._bodycontents.h_limit = 1
body.position = x, 410
shape = pymunk.Circle(body, radius, (0,0))
shape.collision_type = 0x6 #liquid
space.add(body, shape)
return shape
示例4: add_bottle
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [as 别名]
def add_bottle(space):
mass = 10
inertia = 0xFFFFFFFFF
body = pymunk.Body(mass, inertia)
body.position = (130,300)
l1 = pymunk.Segment(body, (-150, 0), (-100, 0), 2.0)
l2 = pymunk.Segment(body, (-150, 0), (-150, 100), 2.0)
l3 = pymunk.Segment(body, (-100, 0), (-100, 100), 2.0)
# Glass friction
l1.friction = 0.94
l2.friction = 0.94
l3.friction = 0.94
# Set collision types for sensors
l1.collision_type = 0x2 # bottle_bottom
l2.collision_type = 0x3 # bottle_right_side
l3.collision_type = 0x4 # bottle_left_side
space.add(l1, l2, l3, body)
return l1,l2,l3
示例5: __init__
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [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()
示例6: __init__
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [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
示例7: __init__
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [as 别名]
def __init__(self, space, x, y, width, height, radius, mass, static, cosmetic=False):
if not cosmetic:
moment = pymunk.moment_for_box(mass, (width, height))
if static:
self.body = pymunk.Body(mass, moment, pymunk.Body.STATIC)
else:
self.body = pymunk.Body(mass, moment)
self.body.position = x, y
self.shape = pymunk.Poly.create_box(self.body, (width, height), radius)
space.add(self.body, self.shape)
self.width = width
self.height = height
self.radius = radius
self.static = static
self._x = x
self._y = y
super().__init__(cosmetic)
示例8: __init__
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [as 别名]
def __init__(self, space, p1, p2, thickness, mass, static, cosmetic=False):
x = (p1[0] + p2[0]) / 2
y = (p1[1] + p2[1]) / 2
if not cosmetic:
moment = pymunk.moment_for_segment(mass, (p1[0]-x, p1[1]-y), (p2[0]-x, p2[1]-y), thickness)
if static:
self.body = pymunk.Body(mass, moment, pymunk.Body.STATIC)
else:
self.body = pymunk.Body(mass, moment)
self.body.position = x, y
self.shape = pymunk.Segment(self.body, (p1[0]-x, p1[1]-y), (p2[0]-x, p2[1]-y), thickness)
space.add(self.body, self.shape)
self.radius = thickness
self.static = static
self._p1 = p1
self._p2 = p2
self._x = x;
self._y = y
super().__init__(cosmetic)
示例9: __init__
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [as 别名]
def __init__(self, space, x, y, radius, mass, static, cosmetic=False):
if not cosmetic:
moment = pymunk.moment_for_circle(mass, 0, radius)
if static:
self.body = pymunk.Body(mass, moment, pymunk.Body.STATIC)
else:
self.body = pymunk.Body(mass, moment)
self.body.position = x, y
self.shape = pymunk.Circle(self.body, radius)
space.add(self.body, self.shape)
self.static = static
self._draw_radius_line = False
self._x = x
self._y = y
self._radius = radius
super().__init__(cosmetic)
示例10: init_pockets
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [as 别名]
def init_pockets(space):
pockets = []
for i in [(44.1, 44.1), (755.9, 44.1), (755.9, 755.9), (44.1, 755.9)]:
inertia = pymunk.moment_for_circle(0.1, 0, POCKET_RADIUS, (0, 0))
body = pymunk.Body(0.1, inertia)
body.position = i
shape = pymunk.Circle(body, POCKET_RADIUS, (0, 0))
shape.color = POCKET_COLOR
shape.collision_type = 2
shape.filter = pymunk.ShapeFilter(categories=0b1000)
space.add(body, shape)
pockets.append(shape)
del body
del shape
return pockets
# Initialize striker with force
示例11: init_striker
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [as 别名]
def init_striker(space, x, passthrough, action, player):
inertia = pymunk.moment_for_circle(STRIKER_MASS, 0, STRIKER_RADIUS, (0, 0))
body = pymunk.Body(STRIKER_MASS, inertia)
if player == 1:
body.position = (action[0], 140)
if player == 2:
body.position = (action[0], BOARD_SIZE - 140)
body.apply_force_at_world_point((cos(action[1]) * action[2], sin(
action[1]) * action[2]), body.position + (STRIKER_RADIUS * 0, STRIKER_RADIUS * 0))
shape = pymunk.Circle(body, STRIKER_RADIUS, (0, 0))
shape.elasticity = STRIKER_ELASTICITY
shape.color = STRIKER_COLOR
mask = pymunk.ShapeFilter.ALL_MASKS ^ passthrough.filter.categories
sf = pymunk.ShapeFilter(mask=mask)
shape.filter = sf
shape.collision_type = 2
space.add(body, shape)
return [body, shape]
# Adds coins to the board at the given coordinates
示例12: init_striker
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [as 别名]
def init_striker(space, x, passthrough, action, player):
inertia = pymunk.moment_for_circle(STRIKER_MASS, 0, STRIKER_RADIUS, (0, 0))
body = pymunk.Body(STRIKER_MASS, inertia)
if player == 1:
body.position = (action[0], 145)
if player == 2:
body.position = (action[0], BOARD_SIZE - 136)
body.apply_force_at_world_point((cos(action[1]) * action[2], sin(
action[1]) * action[2]), body.position + (STRIKER_RADIUS * 0, STRIKER_RADIUS * 0))
shape = pymunk.Circle(body, STRIKER_RADIUS, (0, 0))
shape.elasticity = STRIKER_ELASTICITY
shape.color = STRIKER_COLOR
mask = pymunk.ShapeFilter.ALL_MASKS ^ passthrough.filter.categories
sf = pymunk.ShapeFilter(mask=mask)
shape.filter = sf
shape.collision_type = 2
space.add(body, shape)
return [body, shape]
# Adds coins to the board at the given coordinates
示例13: init_pockets
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [as 别名]
def init_pockets(space):
pockets = []
for i in [(44.1, 43.1), (756.5, 43), (756.5, 756.5), (44, 756.5)]:
inertia = pymunk.moment_for_circle(0.1, 0, POCKET_RADIUS, (0, 0))
body = pymunk.Body(0.1, inertia)
body.position = i
shape = pymunk.Circle(body, POCKET_RADIUS, (0, 0))
shape.color = POCKET_COLOR
shape.collision_type = 2
shape.filter = pymunk.ShapeFilter(categories=0b1000)
space.add(body, shape)
pockets.append(shape)
del body
del shape
return pockets
# Initialize striker with force
示例14: create_obstacle
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [as 别名]
def create_obstacle(self, x, y, r):
c_body = pymunk.Body(pymunk.inf, pymunk.inf)
c_shape = pymunk.Circle(c_body, r)
c_shape.elasticity = 1.0
c_body.position = x, y
c_shape.color = THECOLORS["blue"]
self.space.add(c_body, c_shape)
return c_body
示例15: create_cat
# 需要导入模块: import pymunk [as 别名]
# 或者: from pymunk import Body [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)