• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pymunk.moment_for_circle函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: car

    def car(self, space):
        pos = Vec2d(100,100)

        wheel_color = .2,.86,.47
        shovel_color = .86,.47,.2
        mass = 100
        radius = 25
        moment = pymunk.moment_for_circle(mass, 20, radius)
        wheel1_b = pymunk.Body(mass, moment)
        wheel1_s = pymunk.Circle(wheel1_b, radius)
        wheel1_s.friction = 1.5
        wheel1_s.color = wheel_color
        space.add(wheel1_b, wheel1_s)

        mass = 100
        radius = 25
        moment = pymunk.moment_for_circle(mass, 20, radius)
        wheel2_b = pymunk.Body(mass, moment)
        wheel2_s = pymunk.Circle(wheel2_b, radius)
        wheel2_s.friction = 1.5
        wheel2_s.color = wheel_color
        space.add(wheel2_b, wheel2_s)

        mass = 100
        size = (50,30)
        moment = pymunk.moment_for_box(mass, size)
        chassi_b = pymunk.Body(mass, moment)
        chassi_s = pymunk.Poly.create_box(chassi_b, size)
        space.add(chassi_b, chassi_s)

        vs = [(0,0),(0,-45),(25,-45)]
        shovel_s = pymunk.Poly(chassi_b, vs, transform = pymunk.Transform(tx=85))
        shovel_s.friction = 0.5
        shovel_s.color = shovel_color
        space.add(shovel_s)

        wheel1_b.position = pos - (55,0)
        wheel2_b.position = pos + (55,0)
        chassi_b.position = pos + (0,25)

        space.add(
            pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25,-15)),
            pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25, 15)),
            pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25,-15)),
            pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25, 15))
            )
        
        speed = -4
        space.add(
            pymunk.SimpleMotor(wheel1_b, chassi_b, speed),
            pymunk.SimpleMotor(wheel2_b, chassi_b, speed)
        )
        with self.canvas:
            Color(*wheel_color)
            wheel1_s.ky = self.ellipse_from_circle(wheel1_s)
            Color(*wheel_color)
            wheel2_s.ky = self.ellipse_from_circle(wheel2_s)
            Color(*shovel_color)
            chassi_s.ky = Quad(points=self.points_from_poly(chassi_s))
            shovel_s.ky = Triangle(points=self.points_from_poly(shovel_s))
开发者ID:viblo,项目名称:pymunk,代码行数:60,代码来源:main.py


示例2: __init__

    def __init__(self, body_mass, body_position, body_size, wheel_base):
        self.body_mass = body_mass
        self.body_position = body_position
        self.body_size = body_size
        self.body_body = pymunk.Body(self.body_mass, 1000)
        self.body_body.position = self.body_position
        self.body_poly = pymunk.Poly.create_box(self.body_body, self.body_size)
        
        self.body_poly.friction = 0.5

        body_space.add(self.body_body, self.body_poly)

        self.wheel_base = wheel_base

        self.wheelL_mass = 1
        self.wheelL_radius = (self.body_size[1]//1.5)
        self.wheelL_position_x = self.body_position[0]-(self.body_size[0]//2)+self.wheelL_radius - self.wheel_base
        self.wheelL_position_y = self.body_position[1] + self.body_size[1]*1.5
        self.wheelL_position = self.wheelL_position_x, self.wheelL_position_y
        
        self.inertiaL = pymunk.moment_for_circle(self.wheelL_mass, 0, self.wheelL_radius)
        self.wheelL_b = pymunk.Body(self.wheelL_mass, self.inertiaL)
        self.wheelL_b.position = self.wheelL_position
        self.wheelL_shape = pymunk.Circle(self.wheelL_b, self.wheelL_radius)
        
        self.wheelL_shape.friction = 0.5
        
        space.add(self.wheelL_b, self.wheelL_shape)

        self.wheelR_mass = 1
        self.wheelR_radius = (self.body_size[1]//1.5)
        self.wheelR_position_x = self.body_position[0]+(self.body_size[0]//2)-self.wheelL_radius + self.wheel_base
        self.wheelR_position_y = self.body_position[1] + self.body_size[1]*1.5
        self.wheelR_position = self.wheelR_position_x, self.wheelR_position_y
        
        self.inertiaR = pymunk.moment_for_circle(self.wheelR_mass, 0, self.wheelR_radius)
        self.wheelR_b = pymunk.Body(self.wheelR_mass, self.inertiaR)
        self.wheelR_b.position = self.wheelR_position
        self.wheelR_shape = pymunk.Circle(self.wheelR_b, self.wheelR_radius)

        self.wheelR_shape.friction = 0.5
        
        space.add(self.wheelR_b, self.wheelR_shape)

        self.left_spring = pymunk.constraint.DampedSpring(self.body_body, self.wheelL_b, (0, self.body_size[1]//2), (0,0), 200, 80.0, 50)
        self.right_spring = pymunk.constraint.DampedSpring(self.body_body, self.wheelR_b, (0, self.body_size[1]//2), (0,0), 200, 80.0, 50)
    
        self.left_groove_start = (-self.body_size[0]//2 + self.wheelL_radius, 0)
        self.left_groove_end = (-self.body_size[0]//2 + self.wheelL_radius - self.wheel_base, self.wheelL_radius + 20)
        
        self.left_groove_joint = pymunk.constraint.GrooveJoint(self.body_body, self.wheelL_b, self.left_groove_start, self.left_groove_end, (0,0))
        
        self.right_groove_start = (self.body_size[0]//2 - self.wheelL_radius, 0)
        self.right_groove_end = (self.body_size[0]//2 - self.wheelR_radius + self.wheel_base, self.wheelR_radius + 20)
        
        self.right_groove_joint = pymunk.constraint.GrooveJoint(self.body_body, self.wheelR_b, self.right_groove_start, self.right_groove_end, (0,0))
        
        space.add(self.left_spring, self.right_spring, self.left_groove_joint, self.right_groove_joint)
开发者ID:nuds7,项目名称:FragileTruck---pygame,代码行数:58,代码来源:pymunk2.py


示例3: __init__

    def __init__(self, body_mass, body_position, body_size, wheel_base):
        self.body_mass = body_mass
        self.body_position = body_position
        self.body_size = body_size
        self.body_body = pymunk.Body(self.body_mass, 1000)
        self.body_body.position = self.body_position
        self.body_poly = pymunk.Poly.create_box(self.body_body, self.body_size)
        
        self.body_poly.friction = 0.5

        body_space.add(self.body_body, self.body_poly)

        self.wheel_base = wheel_base

        self.wheelL_mass = 1
        self.wheelL_radius = (self.body_size[1]//1.5)
        self.wheelL_position_x = self.body_position[0]-(self.body_size[0]//2)+self.wheelL_radius - self.wheel_base
        self.wheelL_position_y = self.body_position[1] + self.body_size[1] + 20
        self.wheelL_position = self.wheelL_position_x, self.wheelL_position_y
        
        self.inertiaL = pymunk.moment_for_circle(self.wheelL_mass, 0, self.wheelL_radius)
        self.wheelL_b = pymunk.Body(self.wheelL_mass, self.inertiaL)
        self.wheelL_b.position = self.wheelL_position
        self.wheelL_shape = pymunk.Circle(self.wheelL_b, self.wheelL_radius)
        
        self.wheelL_shape.friction = 0.5
        
        space.add(self.wheelL_b, self.wheelL_shape)

        self.wheelR_mass = 1
        self.wheelR_radius = (self.body_size[1]//1.5)
        self.wheelR_position_x = self.body_position[0]+(self.body_size[0]//2)-self.wheelL_radius + self.wheel_base
        self.wheelR_position_y = self.body_position[1] + self.body_size[1] + 20
        self.wheelR_position = self.wheelR_position_x, self.wheelR_position_y
        
        self.inertiaR = pymunk.moment_for_circle(self.wheelR_mass, 0, self.wheelR_radius)
        self.wheelR_b = pymunk.Body(self.wheelR_mass, self.inertiaR)
        self.wheelR_b.position = self.wheelR_position
        self.wheelR_shape = pymunk.Circle(self.wheelR_b, self.wheelR_radius)

        self.wheelR_shape.friction = 0.5
        
        space.add(self.wheelR_b, self.wheelR_shape)

        self.left_spring = pymunk.constraint.DampedSpring(self.body_body, self.wheelL_b, (-self.body_size[0]//2, 0), (0,0), self.wheelL_position_y, 7.0, 7)
        self.right_spring = pymunk.constraint.DampedSpring(self.body_body, self.wheelR_b, (self.body_size[0]//2, 0), (0,0), self.wheelR_position_y, 7.0, 7)
        self.middle_spring = pymunk.constraint.DampedSpring(self.wheelL_b, self.wheelR_b, (0,0), (0,0), self.body_size[0], 100.0, 5)

        self.left_pinjoint = pymunk.constraint.PinJoint(self.body_body, self.wheelL_b, (0,0), (0,0))
        self.right_pinjoint = pymunk.constraint.PinJoint(self.body_body, self.wheelR_b, (0,0), (0,0))

        
        
        space.add(self.left_spring, self.right_spring, self.left_pinjoint, self.right_pinjoint, self.middle_spring)
开发者ID:nuds7,项目名称:FragileTruck---pygame,代码行数:54,代码来源:truckphysics1.py


示例4: car

def car(space):
    pos = Vec2d(100,200)

    wheel_color = 52,219,119
    shovel_color = 219,119,52
    mass = 100
    radius = 25
    moment = pymunk.moment_for_circle(mass, 20, radius)
    wheel1_b = pymunk.Body(mass, moment)
    wheel1_s = pymunk.Circle(wheel1_b, radius)
    wheel1_s.friction = 1.5
    wheel1_s.color = wheel_color
    space.add(wheel1_b, wheel1_s)

    mass = 100
    radius = 25
    moment = pymunk.moment_for_circle(mass, 20, radius)
    wheel2_b = pymunk.Body(mass, moment)
    wheel2_s = pymunk.Circle(wheel2_b, radius)
    wheel2_s.friction = 1.5
    wheel2_s.color = wheel_color
    space.add(wheel2_b, wheel2_s)

    mass = 100
    size = (50,30)
    moment = pymunk.moment_for_box(mass, size)
    chassi_b = pymunk.Body(mass, moment)
    chassi_s = pymunk.Poly.create_box(chassi_b, size)
    space.add(chassi_b, chassi_s)

    vs = [(0,0),(25,45),(0,45)]
    shovel_s = pymunk.Poly(chassi_b, vs, transform = pymunk.Transform(tx=85))
    shovel_s.friction = 0.5
    shovel_s.color = shovel_color
    space.add(shovel_s)

    wheel1_b.position = pos - (55,0)
    wheel2_b.position = pos + (55,0)
    chassi_b.position = pos + (0,-25)

    space.add(
        pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25,-15)),
        pymunk.PinJoint(wheel1_b, chassi_b, (0,0), (-25, 15)),
        pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25,-15)),
        pymunk.PinJoint(wheel2_b, chassi_b, (0,0), (25, 15))
        )
    
    speed = 4
    space.add(
        pymunk.SimpleMotor(wheel1_b, chassi_b, speed),
        pymunk.SimpleMotor(wheel2_b, chassi_b, speed)
    )
开发者ID:viblo,项目名称:pymunk,代码行数:52,代码来源:index_video.py


示例5: __init__

 def __init__(self, pos, rot, child_unit):
     self.unit = child_unit
     self.obj_id = child_unit.obj_id
     inertia = pymunk.moment_for_circle(
         self.unit.mass, 0, self.unit.radius,(0,0)
     )
     
     self.body = pymunk.Body(self.unit.mass, inertia)
     self.unit.set_offset(0,0)
     self.unit.local_angle = 0
     self.unit.local_angle_target = 0
     self.unit.rotation = 0
     self.unit.initialize(self,collision_type=physics.FREE)
     
     self.body.angle = math.radians(rot)
     self.body.position = pos
     self.angle_degrees = rot
     
     self.attachable = True
     self.visible = True
     
     physics.body_update_list.append(self)
     physics.unit_update_list.append(self.unit)
     physics.space.add(self.body)
     self.unit.add_shapes()
开发者ID:irskep,项目名称:Gluball,代码行数:25,代码来源:body.py


示例6: update_center_of_mass_old

 def update_center_of_mass_old(self):
     if len(self.units) == 0: return
     avg_x = 0.0
     avg_y = 0.0
     mass_total = 0.0
     inertia_total = 0.0
     
     for u in self.units:
         mass_total += u.mass
         inertia_total += pymunk.moment_for_circle(
                         u.mass, 0, u.radius, u.offset)
         avg_x += u.mass * u.offset[0]
         avg_y += u.mass * u.offset[1]
         u.remove_shapes()
     avg_x /= mass_total
     avg_y /= mass_total
     new_body_position = self.body.local_to_world((avg_x,avg_y))
     
     old_body = self.body
     physics.space.remove(old_body)
     
     self.body = pymunk.Body(mass_total, inertia_total)
     self.body.position = new_body_position
     self.body.velocity = old_body.velocity
     self.body.angular_velocity = old_body.angular_velocity
     self.body.angle = old_body.angle
     old_body = None
     
     physics.space.add(self.body)
     
     for u in self.units:
         x, y = u.offset[0]-avg_x, u.offset[1]-avg_y
         u.set_offset(x,y)
         u.initialize(self,collision_type=physics.PLAYER)
         u.add_shapes()
开发者ID:irskep,项目名称:Gluball,代码行数:35,代码来源:body.py


示例7: update_center_of_mass

 def update_center_of_mass(self):
     if len(self.units) == 0: return
     avg_x = 0.0
     avg_y = 0.0
     mass_total = 0.0
     inertia_total = 0.0
     
     for u in self.units:
         mass_total += u.mass
         inertia_total += pymunk.moment_for_circle(
                         u.mass, 0, u.radius, u.offset)
         avg_x += u.mass * u.offset[0]
         avg_y += u.mass * u.offset[1]
         #u.remove_shapes()
     avg_x /= mass_total
     avg_y /= mass_total
     new_body_position = self.body.local_to_world((avg_x,avg_y))
     
     self.body.position = new_body_position
     self.body.mass = mass_total
     self.body.moment = inertia_total
     
     for u in self.units:
         x, y = u.offset[0]-avg_x, u.offset[1]-avg_y
         u.set_offset(x,y)
         u.update_shapes()
开发者ID:irskep,项目名称:Gluball,代码行数:26,代码来源:body.py


示例8: __init__

	def __init__(self, scene, tex = 'blinky', position=(0,0)):
		self.start_pos = position
		
		radius, mass = 7, .001

		p_man_moment = pymunk.moment_for_circle(mass, 0, radius)

		self.ghost_b 					= pymunk.Body(mass, p_man_moment)
		self.ghost_b.position 			= position
		self.ghost_shape 				= pymunk.Circle(self.ghost_b, radius)
		self.ghost_shape.friction 		= .5
		self.ghost_shape.elasticity 	= .2
		self.ghost_shape.collision_type = 4

		self.ghost_shape.fill_color = (0,0,0,0)

		scene.space.add(self.ghost_b, self.ghost_shape)

		ghost_img = pyglet.image.load('resources/textures/'+tex+'.png')
		ghost_img.anchor_x, ghost_img.anchor_y = ghost_img.width/2, ghost_img.height/2
		tex = ghost_img.get_texture()
		
		glTexParameteri(tex.target, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
		glTexParameteri(tex.target, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
		
		self.ghost_s = pyglet.sprite.Sprite(
			ghost_img, batch=scene.normal_batch, group=scene.ordered_group3)

		self.ghost_s.scale = 1

		self.ghost_b.on_tween_complete = self.on_tween_complete
		self.ghost_b.update_tween = self.update_tween

		self.ghost_b.posx = position[0]
		self.ghost_b.posy = position[1]
开发者ID:Elizabwth,项目名称:pyman,代码行数:35,代码来源:entities.py


示例9: __init__

    def __init__(self, world, position, width=1.6, length=4.0, tire_width=.25, tire_length=.8, skidmarks=None, body_density=1.0):
        mass = width * length * body_density
        inertia = moment_for_box(mass, width, length)
        self.world = world
        body = Body(mass, inertia, )
        body.position = position
        shape = Poly.create_box(body, size=(width, length))
        super(Car, self).__init__(world, body, shape)

        slot_density = .01
        slot_radius = .1
        slot_mass = slot_density * (slot_radius ** 2) * pi
        slot_inertia = moment_for_circle(slot_mass, 0.0, slot_radius)
        #self.slot = Body(slot_mass, slot_inertia)


        flpos = position[0] - width / 2.0 - tire_width * 2, position[1] + length / 2.0
        self.front_left = Tire(self, flpos, tire_width, tire_length, skidmarks=skidmarks, powered=False, density=body_density)


        frpos = position[0] + width / 2.0 + tire_width * 2, position[1] + length / 2.0
        self.front_right = Tire(self, frpos, tire_width, tire_length, skidmarks=skidmarks, powered=False, density=body_density)
        
        rlpos = position[0] - width / 2.0 - tire_width * 2, position[1] - length / 2.0
        self.rear_left = Tire(self, rlpos, tire_width * 1.5, tire_length, steerable=False, skidmarks=skidmarks, density=body_density)

        rrpos = position[0] + width / 2.0 + tire_width * 2, position[1] - length / 2.0
        self.rear_right = Tire(self, rrpos, tire_width * 1.5, tire_length, steerable=False, skidmarks=skidmarks, density=body_density)
        self.tires = [self.front_left, self.front_right, self.rear_left, self.rear_right]
开发者ID:deets,项目名称:raspberry-racer,代码行数:29,代码来源:car.py


示例10: __init__

 def __init__(self, space, x, y):
     inertia = pymunk.moment_for_circle(Raindrop.MASS, 0, Raindrop.RADIUS)
     self.body = pymunk.Body(Raindrop.MASS, inertia)
     self.body.position = x, y
     shape = pymunk.Circle(self.body, Raindrop.RADIUS)
     shape.friction = 0.5
     space.add(self.body, shape)
开发者ID:mickhalsband,项目名称:BunnyGame,代码行数:7,代码来源:rain.py


示例11: create_ball

 def create_ball(self, x, y, mass=40, radius=7):
     inertia = pymunk.moment_for_circle(mass, 0, radius, (0, 0))
     body = pymunk.Body(mass, inertia)
     body.position = x, y
     shape = pymunk.Circle(body, radius, (0, 0))
     shape.elasticity = 0.95
     return body, shape
开发者ID:d42,项目名称:pongjector,代码行数:7,代码来源:main.py


示例12: __init__

 def __init__(self, x, y):
     self.mass = 1
     self.radius = 14
     self.inertia = pk.moment_for_circle(self.mass, 0, self.radius)
     self.body = pk.Body(self.mass, self.inertia)
     self.body.position = x, y
     self.shape = pk.Circle(self.body, self.radius)
开发者ID:justinmeister,项目名称:Pymunk-Projects,代码行数:7,代码来源:ball_ramps.py


示例13: __init__

 def __init__(
             self, col_type, img, damage, 
             x, y, vx, vy, rotate=False, batch=None, group=None
         ):
     super(Bullet, self).__init__(img, x, y, batch=batch, group=group)
     self.damage = damage
     
     if rotate:
         self.rotation = math.degrees(-math.atan2(vy, vx))
     
     radius = 4
     mass = physics.default_density*(radius*radius*2*math.pi)
     inertia = pymunk.moment_for_circle(mass, 0, radius, (0,0))
     self.body = pymunk.Body(mass, inertia)
     self.body.position = (x,y)
     self.body.velocity = (vx, vy)
     
     self.shape = pymunk.Circle(self.body, radius, (0,0))
     self.shape.friction = 1.0
     self.shape.elasticity = 0.0
     self.shape.parent = self
     self.shape.collision_type = col_type
     self.shape.layers = 1
     
     physics.space.add(self.body)
     physics.space.add(self.shape)
     
     physics.body_update_list.append(self)
开发者ID:irskep,项目名称:Gluball,代码行数:28,代码来源:bullet.py


示例14: addBall

 def addBall(self, mass, radius, pos):
     inertia = pymunk.moment_for_circle(mass, 0, radius, (0, 0))
     body = pymunk.Body(mass, inertia)
     body.position = pos
     shape = pymunk.Circle(body, radius, (0, 0))
     shape.elasticity = 0.75
     return shape
开发者ID:0,项目名称:SpaceFight,代码行数:7,代码来源:gameobject.py


示例15: __init__

  def __init__(self, level, radius=100, position=(0,0), density=1.0, verticies=None, orbit=None, mass=None, static=False, **kwargs):
    # physics
    if not mass:
      mass = math.pi * radius**2 * density  #4/3 * math.pi * radius**3 * density * 0.1
    inertia = pymunk.moment_for_circle(mass, 0, radius, (0,0))
    body = pymunk.Body(mass, inertia)
    body.position = Vec2d(position)
    body.radius = radius
    shape = pymunk.Circle(body, radius, (0,0))
    shape.friction = 2

    if static:
      level.space.add_static(body,shape)
    else:
      level.space.add(body,shape)

    # visuals
    if not verticies:
      verticies = int(radius / 5.) + 10
    vert_list = generate_circle(radius=radius, steps=verticies)
    display = level.batch.add(verticies, GL_LINE_LOOP, PositionedList(self), ('v2f', vert_list))

    if orbit:
      gravitation = level.gravity * (body.mass + orbit.body.mass)
      distance = body.position.get_distance(orbit.body.position)
      speed = (gravitation/distance)**(0.5)
      body.velocity = (body.position - orbit.body.position).rotated(90).normalized() * speed


    self.body = body
    self.shape = shape
    self.display = display
    self.level = level
开发者ID:nickretallack,项目名称:physics,代码行数:33,代码来源:things.py


示例16: __init__

    def __init__(self, bod_x, bod_y, space):
        
        linelength = 50 #can make this a parameter 
        self.rotation_center_body = pm.Body(pm.inf, pm.inf) # rigid center of rotation
        self.rotation_center_body.position = (bod_x,bod_y)
            
        self.body = pm.Body(60, 5000) # this will be the body for the line
        self.body.position = (bod_x,bod_y)    
            
        self.l1 = pm.Segment(self.body, (0, 0), (0.0, -linelength), 5.0)
        
        #create the ball
        mass = 10
        radius = 20 
        inertia = pm.moment_for_circle(mass, 0, radius, (0,0))
        self.ballBody = pm.Body(mass, inertia)
        self.ballBody.position = (bod_x, bod_y - (linelength + radius) )
        
        self.circle = pm.Circle(self.ballBody, radius, (0,0))
        self.circle.elasticity = 1
   
        #connect the line to the center of rotation and then the ball to the line
        self.rotation_center_joint = pm.PinJoint(self.body, self.rotation_center_body, (0,0), (0,0))
        self.rotation_center_joint2 = pm.PinJoint(self.body, self.ballBody, (0,-linelength), (0,0))    


        space.add(self.l1, self.circle, self.ballBody, self.body, self.rotation_center_joint, self.rotation_center_joint2)
     
            
开发者ID:nchokas,项目名称:PysProblem,代码行数:27,代码来源:lineswing_old.py


示例17: _build_physics_elements

    def _build_physics_elements(self):
        self.dynamic_object = []
        for element in self.collect_object_list:
            width, height = element.size
            mass = width * height
            if element.is_circle:
                moment = pymunk.moment_for_circle(mass, 0, 100)
                body = pymunk.Body(mass, moment)
                shape = pymunk.Circle(body, width/2)
                body.elasticity = 0.9
            else:
                vs = [(-width/2, height/2), (width/2, height/2), (width/2, -height/2), (-width/2, -height/2)]
                moment = pymunk.moment_for_poly(mass, vs)
                body = pymunk.Body(mass, moment)
                shape = pymunk.Poly(body, vs)
            shape.friction = 0.6
            body.position = element.position[0]+width/2, self.flipy(element.position[1]+height/2)
            body.angle = math.pi
            self.space.add(body, shape)
            self.dynamic_object.append((element, shape))

        static_body = pymunk.Body()
        for element in self.collide_object_list:
            x, y = element.position[0], self.flipy(element.position[1])
            width, height = element.size[0], element.size[1]
            static_lines = [pymunk.Segment(static_body, (x, y), (x+width, y), 0.0),
                            pymunk.Segment(static_body, (x+width, y), (x+width, y-height), 0.0),
                            pymunk.Segment(static_body, (x+width, y-height), (x, y-height), 0.0),
                            pymunk.Segment(static_body, (x, y-height), (x, y), 0.0),
                            ]
            for l in static_lines:
                l.friction = 0.5
            self.space.add(static_lines)
开发者ID:joaompinto,项目名称:DragonWalk,代码行数:33,代码来源:level.py


示例18: __init__

 def __init__(self, game, pos, bonus_type=0):
     self._game = game
     self.is_alive = True
     self._life = constants.ENEMY_ARMOR
     self.bonus_type = bonus_type
     # Mouse pointer 'body'
     self.aim = pymunk.Body(1, 1)
     self.aim_shape = pymunk.Circle(self.aim, 1, (0, 0))
     self.aim_shape.layers = 0b000  # The 'aim' should not collide with any objects
     self.aim.position = pos
     # Enemy body
     mass = 3
     radius = 15
     inertia = pymunk.moment_for_circle(mass, 0, radius, (0, 0))
     self.body = pymunk.Body(mass, inertia)
     shape = pymunk.Circle(self.body, radius, (0, 0))
     shape.elasticity = 0.9
     shape.friction = 0.8
     shape.collision_type = 3
     self.shape = shape
     if not bonus_type:
         self.sprite = Sprite("enemy.png")
     elif bonus_type == constants.HEALTH_BONUS_TYPE:
         animation = pyglet.resource.animation("bonus_enemy_green.gif")
         self.sprite = Sprite(animation)
     elif bonus_type == constants.KILLALL_BONUS_TYPE:
         animation = pyglet.resource.animation("bonus_enemy_yellow.gif")
         self.sprite = Sprite(animation)
     self.sprite.do(Repeat(RotateBy(360, 2)))
     self.body.position = self.sprite.position = pos
     self.body.apply_force(-(self.body.mass + self.aim.mass) * game.space.gravity)
     # Connect aim and body with a DampedSpring - this should create the effect of flying through the air to the
     # player
     self.move = pymunk.constraint.DampedSpring(self.aim, self.body, (0, 0), (0, 0), 1, 600.0, 100)
     game.space.add(self.body, self.shape, self.aim, self.move)
开发者ID:aikikode,项目名称:pyhammerfight,代码行数:35,代码来源:models.py


示例19: _constructPhysics

 def _constructPhysics(self, mass, pos):
     """Called by parent constructor.
     """
     self.mass = mass
     self.inertia = pymunk.moment_for_circle(mass, 0, self.radius, (0, 0))
     self.body = pymunk.Body(mass, self.inertia)
     self.shape = pymunk.Circle(self.body, self.radius, (0, 0))
开发者ID:oshoukry,项目名称:SpaceBattleArena,代码行数:7,代码来源:Entities.py


示例20: _createPhysicsObject

 def _createPhysicsObject(self):
     """Return a new physics object"""
     if self.geometry_type == 'circle':
         inertia = pymunk.moment_for_circle(self.mass, 0, self.radius, (0,0))
     else:
         inertia = pymunk.moment_for_box(self.mass, self.width, self.height)
     #
     body = pymunk.Body(self.mass, inertia)
     body.velocity = self.velocity
     body.force = self.force
     #
     if self.geometry_type == 'circle':
         shape = pymunk.Circle(body, self.radius, (0,0))
     else:
         #shape = pymunk.Poly(body, [(0, 0), (self.width, 0), 
         #                           (self.width, self.height), (0, self.height)])
         w2, h2 = self.width/2, self.height/2
         shape = pymunk.Poly(body, [(-w2,-h2), (+w2, -h2), (+w2, +h2), (-w2, +h2)])
     #
     shape.elasticity = self.elasticity
     shape.collision_type = 2
     shape.group = self.group
     shape.layers = self.layers
     shape.friction = self.friction
     self.shape = shape
     self.body = body
开发者ID:gregpuzzles1,项目名称:Sandbox,代码行数:26,代码来源:physical.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pymunk.moment_for_poly函数代码示例发布时间:2022-05-27
下一篇:
Python pymunk.moment_for_box函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap