def __createCircleShape(info: 'Dict[str, Any]') -> 'Circle': shape = Circle(None, info['radius'], (info.get('x', 0), info.get('y', 0))) shape.mass = info['mass'] shape.elasticity = info.get('elasticity', 0.5) shape.friction = info.get('friction', 0.5) return shape
def init_space(): sp = Space() sp.gravity = (0, 50) chain = make_pivot_chain(sp, (0, 0), (240, 30), 30) sp.add(constraint.PivotJoint(chain[0], sp.static_body, chain[0].position)) # Cria quadrado L = 25 player = Body(mass=1, moment=100) shape = Poly(player, [(-L, -L), (L, -L), (L, L), (-L, L)]) player.position = (90, 60) player.velocity = (-25, 25) shape.elasticity = 1.0 shape.color = pyxel.COLOR_RED shape.collision_type = 42 ball = Body(mass=1, moment=200) ball_shape = Circle(ball, 20) ball.position = (player.position.x, 130) ball_shape.elasticity = 1.0 shape.color = pyxel.COLOR_NAVY ball_shape.collision_type = 42 joint1 = constraint.DampedSpring(player, ball, (0, 0), (20, 0), 20, 3, 0.5) joint2 = constraint.PivotJoint(sp.static_body, player, (65, 35)) joint1.collide_bodies = False sp.add(joint1, joint2) body2 = Body(1, 100) sp.add(body2) sp.add(Poly(body2, [(-3, 3), (3, 3), (3, -3), (-3, -3)])) body2.position = 220, 50 sp.add(constraint.DampedRotarySpring(body2, ball, 0, 2, 1)) sp.body2 = body2 # Cria margens line = Body(body_type=Body.STATIC) e = 0 lines = [ Segment(line, (-e, -e), (240 + e, -e), 2), Segment(line, (-e, 180 + e), (240 + e, 180 + e), 2), Segment(line, (-e, -e), (-e, 180 + e), 2), Segment(line, (240 + e, -e), (240 + e, 180 + e), 2), ] for line in lines: line.elasticity = 1.0 lines = [] # Adiciona elementos ao espaço sp.add(player, shape, ball, ball_shape, *lines) sp.player = player #handler = sp.add_collision_handler(42, 42) #handler.begin = lambda *args: False return sp
def handle_object_type_pin(data, body): pin = Circle(body, 2, get_rect(data).center) pin.elasticity = 1.0 yield pin